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.
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.
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.
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:
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 compositionsand functions or bite-sized repeatable chunks
attributes- These are properties of an object like
mac_address, or something like that. In powershell, these are the properties that would show up when you run
$myvar | get-memberand see the listed properties and methods.
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.
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.