Skip to content
Free since 2015. Built for the engineers who keep things running.

cat /articles/terraform-best-practices-using-variables.md

Infrastructure as Code

Terraform Best Practices — Using variables

When starting out with Terraform it’s hard to know what is considered ‘best practice’ in a number of areas. This post is the sixth in the series which focuses on point 6 in the list, ‘Avoid hardcoding variables’, and also shows best practice for general variable use in Terraform.

medium.com15 Apr 2021 · summary

article --summary

The summary

When starting out with Terraform it’s hard to know what is considered ‘best practice’ in a number of areas. This post is the sixth in the series which focuses on point 6 in the list, ‘Avoid hardcoding variables’, and also shows best practice for general variable use in Terraform. Here's an example of a variables.tf file in the root module (root directory) of a project that is used to create a Windows desktop VM in Azure: Note that every variable has a description. Lastly the files in the vm module itself, firstly the variables.tf file: Again note that defaults can be set for variables, these are taken if no value is passed in. In this case, I always want the following to apply as default unless a value is specified: These variables are also missing their descriptions! You’ll see that the SKU description under source image reference is described as the following: These variables are then used by the module code in main.tf

Editorial note: This is a summary of an article first published by medium.com. The full piece is on their site.

articles --latest

Latest articles

New from the blogs we follow and the community.

All articles

newsletter --weekly

DevOps Weekly, minus the noise.

The best reads, new jobs and upcoming events, in one email a week.