Hi there

in this post I’m covering Azure & Terraform series today I’m continuing to use the previous vars.tf file which we used to declare all variables for our main.tf file to standardize our Azure through Terraform scripts.

Before we continue check your Terraform version running terraform –version 

Quick review

  1. download Terraform from https://www.terraform.io/downloads.html
  2. edit your Windows PATH variable to point to your terraform main folder (I have a main folder for Azure deployments with a folder on C:\TERRAFORM\ where I extract my Terraform downloaded file into)
  3. quick commands
    1. az login
    2. terraform init
    3. terraform plan -out myplanName
    4. terraform apply myplanName
    5. follow up your console output to check for any warnings, errors and its deployment
    6. terraform destroy

Now you’re ready to continue

download main.tf for this exercise

changes for this exercise

  • removed variable “admin_password” from vars.tf file
  • declared data and output variables to capture:
    • the vm public ip address
    • admin user name (case sensitve)
    • admin password (randomly generated on main.tf)
    • OK SKU

This main.tf will create the following using variables from vars.tf

  1. azure resource group named MyTerraform6
  2. region (location): eastus
  3. azure VNET named myTFVnet
  4. azure subnet #1 named myTFSubnet
  5. azure ubuntu vm 1804 LTS named myTFVM
  6. azure public ip for the ubuntu vm named myTFPublicIP
  7. azure nsg with firewall rule allowing ssh tcp port 22 to the vm through its public ip named myTFNSG
  8. vm admin user named: adminuser
  9. random vm password: ******
  10. prefix for all variables replacing the my*azure resource identifier* , where all azure resources to be created under MyTerraform6 azure resource group.

 

admin_password = i46iE:yr-GqYy_!#
admin_user = Adminuser
os_sku = 18.04-LTS
public_ip_address = 40.87.107.232

Previous Article

Check my Github repository

References
https://learn.hashicorp.com/terraform/azure/variables_az

Thanks,

Thiago Beier
TwitterLinkedInFacebookRSS