How to Deploy an Ubuntu Linux VM in Azure using Terraform
In this story, we will learn how to deploy an Ubuntu Linux VM in Azure using Terraform.
Prerequisites
Before creating our Azure Virtual Machine, we will need an Azure SPN (Service Principal) to execute our Terraform code (check step 1 of this story if you need help creating an SPN).
Creating a Terraform file for Azure Authentication
First, we create a file called provider-variables.tf, used by Azure authentication variables.
We will use a Service Principal with a Client Secret. Check the link below for more info about Azure authentication for Terraform: https://www.terraform.io/docs/providers/azurerm/guides/service_principal_client_secret.html
variable "azure_subscription_id" {
type = string
description = "Azure Subscription ID"
}variable "azure_client_id" {
type = string
description = "Azure Client ID"
}variable "azure_client_secret" {
type = string
description = "Azure Client Secret"
}variable "azure_tenant_id" {
type = string
description = "Azure Tenant ID"
}
After that, we edit the file terraform.tfvars and add the Azure credential information: