/terraform-azure-vm

A basic Terraform example.

Primary LanguageHCL

terraform logo

Terraform Azure Virtual Machine

Terraform code to spin up an Azure vm with:

  • an open security group (all TCP traffic allowed on port 22).
  • One user.

N.B.

This is purely a test to gain knowledge of Azure services. Close security group for alternative use.

Requirements

Authenticate Azure via the CLI as documented here.

Usage

$ terraform init
$ terraform plan
$ terraform apply

Notes on Process

As I haven't used Azure before, I have highlighted parts of the process to spin up the Azure Virtual Machine that are interesting or differ from AWS.

Powershell

Authenticating Azure

  • Authenticated Azure via CLI instead of using a Service Principal.

  • Azure CLI authentication is smoother than AWS but potentially less easy to configure?

  • Env SUBSCRIPTION_ID doesn't need to be set as using only the default subscription.

Linux Virtual Machine Configuration

  • Assigning os_profile_linux_config ssh_key. In AWS I did this via user data with AWS parameter store and base64 decryption. Perhaps there was a better option.

    Do you have to provision the public key and then go to the console to download the private key for the Virtual Machine?

    Can you assign your own public key? Does it format it correctly to path?

Images

Here are some of the results of running terraform apply in the Azure console.

Azure Resource Group created

Azure Resources

Azure Virtual Network created

Azure Virtual Network

Azure Virtual Machine created

Azure Virtual Machines

Here is the result of ssh to the Azure Virtual Machine.

SSH to Azure Virtual Machine

SSH to Azure Virtual MAchine