Skip to content

MicrosoftAZLabs/CreateAzureVMwithTerraform

Repository files navigation

Create a linux VM using Terraform in Azure

IaC (Infrastructure as code)

IaC is a code (human readable) that deploys your infrastructure resources onto various platforms instead of managing them manually through a user interface. Provisioning infrastructure through software to achieve consistent and predictable environment.

How Terraform works?

  • Terraform allows infrastructure to be expressed as code in a simple, human readable language called HCL (HashiCorp Configuration Language). It reads configuration files and provides an execution plan of changes, which can be reviewed for safety and then applied and provisioned.
  • Extensible providers allow Terraform to manage a broad range of resources, including IaaS, PaaS, SaaS, and hardware services.

Terraform Execution Flow

image

Azure provider (azurerm)

What are we building here?

We will try to deploy a standalone Linux VM, below is the pictorial representation of what we will deploy

image

Creating VM on Azure

  • In order to deploy these resources in Azure, clone the repo in Cloud shell(Azure)

image

  • Move to the folder where the repo has been cloned. After that run terraform init command

image

  • After that Validate (terraform validate) --> Plan(terraform plan) --> Apply(terraform apply)

image

  • Once the resources are deployed, you can see the below mentioned message in your cloud shell

image

image

Login into the Linux VM

  • As you would noticed we have create the private-public key using tls

We can save the private key in a file which will be used for login into the VM

image

Change the required permission and login using the below command as mentioned in the screenshot

image

Clean-up resource

  • To clean up the resources created, just run terraform destroy command

image

image

Releases

No releases published

Packages

No packages published

Languages