Azure – Terraform #7

Hi there

In this post I’m covering, actually adding one more component to previous article Azure Terraform #5 – TheĀ Variable Definitions (.tfvars) Files.

Those .tfvars files are used when you need to set a lots of variables on and you need to specify their values in a variable definitions file terminated by .tfvars or .tfvars.json and then you specify the file on the command: terraform apply -var=teraform.tfvars or simply terraform apply

It’s common to use this file when you have an environment where you create the automation however you don’t have access to admin users name, passwords, subscription id or any other information that regards to client’s environment that’s a classified information.

  1. you create your with your azure deployment request
    1. azure resource group
    2. vnet
    3. vm
    4. public ip
    5. NSG and so on and so forth
  2. you create your with all variables needed by the file
    1. azure resource group name
    2. azure subscription id
    3. azure vm admin
    4. azure vm admin password
    5. azure prefix
    6. azure vm name
    7. azure vnet name (you can also specify ip addressing if needed) but those requests can differ from environment to environment as well as from client to client (use this as master template and make all changes you might need)
    8. azure public ip
    9. azure NSG name
  3. you create your private.tfvars file (terraform.tfvars) where you have your classified information

Quick review

  1. download Terraform fromĀ
  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

Having the Terraform files’ structure above you’re able to get any request for spin up vms for production, uat or dev environment without any issue and if you need help with the files you just need to share and (public files) and keep your .tfvars file safe (private).

Check my Github repository



Thiago Beier