Create a file named "terraform.tfvars" and save it in the working directory of the Terraform configuration, so side by side to the *.tf files.
subscription_id = "<replace that with your Azure Subscription ID>"
resource_group_name = "rg-virtualmachinelinux-dev-001"
resource_group_location = "West Europe"
vnet_name = "vnet-dev-westeurope-001"
subnet_name = "internal"
public_ip_name = "pip-ubuntudev-westeurope-001"
network_interface_name = "nic-01-ubuntudev-dev-001"
virtual_machine_name = "vm-ubuntudev-westeurope-001"
virtual_machine_size = "Standard_B2s"
storage_image_reference_offer = "0001-com-ubuntu-server-jammy"
storage_image_reference_publisher = "Canonical"
storage_image_reference_sku = "22_04-lts"
storage_image_reference_version = "latest"
virtual_machine_admin_username = "azureuser"
virtual_machine_admin_password = "P@ssw0rd1234!"
virtual_machine_ssh_key_path = "id_rsa.pub"Set the values due to your needs.
az vm image list-skus --location westeurope --publisher Canonical --offer 0001-com-ubuntu-server-jammy --output tableExample result:
Location Name
---------- ---------------
westeurope 22_04-lts
westeurope 22_04-lts-arm64
westeurope 22_04-lts-gen2
In the same directory as your .tf files are located, run
ssh-keygen -f id_rsaSkip the passphrase.
Conduct the initialization with the following command:
terraform initMake sure your Terraform configuration files are in the desired format, by using:
terraform fmtValidate your Terraform configuration
terraform validateCreate a Terraform plan by running:
terraform plan -out tfplanDeploy the Ubuntu VM on Azure executing:
terraform apply tfplanEnsure the proper permission for the private key:
chmod 600 id_rsaEstablish a connection to the virtual machine using:
ssh -i id_rsa azureuser@<public ip address>Destroy the Ubuntu VM on Azure executing:
terraform destroyConfirm the destruction with entering "yes".