Terraform: Introduction

2 minute read


This will be a summary post of getting started with Terraform on Azure from what I have learned the first few months in a position that uses Terraform heavily.

To Resolve:

  1. First, I have bookmarked the following links and reference them daily while searching for things:

    • TF Core Docs - For learning anything about terraform itself like meta-arguments, expressions, and directory structures.
    • Azure RM Docs - For looking up Azure resources and what required/optional arguments they take.
    • Microsof’ts TF on Azure Docs - I don’t find myself referencing this too much, but useful nonetheless.
  2. So as will any language, the best way to start learning is to practice. Here is the progression I have done so far:

    • First, before starting this position, I used Terraform in cloud shell to deploy a VM all in one file, documented in this post.
    • Then after starting, I found a way to have Azure Devops use the Terraform executable to deploy into Azure using Service Connection/Service Principle. I documented that in this post.
    • Now I’m just learning Terraform itself by practicing deploying into a test tenant.
  3. As with any language, the first thing you need to do is read the docs to learn the syntax. In terraform, there isn’t much to learn syntax-wise since it is more like yaml and json than powershell or python. Nonetheless, I have a few post documenting some features I have had to learn:

  4. I have also found a few terms confusing. Here are some thoughts on terminology in regards to Terraform terms:

    • parameter versus argument - I see this one a lot and it generates lots of confusion. I like to link to this MSDN reference where it states a parameter is a ‘P’arking space and an argument is an ‘A’utomobile. Many different automobiles can fit into a single parking space, i.e. different arguments can be passed to a single defined parameter. NOTE: You may see many references where I get this confused as well, I’m not above the law!
    • controller script calling function / stack calling sub-routine / script calling function - I talk about this in a later post but Terraform calls scripts/controllers/stacks module compositions and functions or bite-sized repeatable chunks modules.
    • attributes - These are properties of an object like id, mac_address, or something like that. In powershell, these are the properties that would show up when you run $myvar | get-member and see the listed properties and methods.
  5. I found that by testing locally can be a faster method to testing things than to to push up to Azure Devops and have the build agent run the same commands. Essentially, this gets rid of messing with the pipeline files and focusing exactly what I’m trying to accomplish with Terraform.

  6. I plan to update this blog with more stuff as I learn. For example:

    • Conditionally deploy resources - I already have this post ready, just need to finish a few tweaks. Update: here it is and here is some more fun with optionally deploying infrastructure or settings.
    • Using Terragrunt for managing environments and variables
    • More advanced usage of Terraform since these are basically intro posts so far.