Intro (and little bit more) Hashicorp’s Terraform

I remember thinking a few months ago what is terraform?

Initially I was hesitant due to the thought of learning a new programming language(while still in process of learning others)

Fortunately, my fears where built on false assumptions.

Terraform is a open source software by Hashicorp Terraform it builds/stands-up “virtualised” infrastructure in form of a code. The key word is “virtualised” because wether your building on-prem(e.g VMware)or cloud(e.g Azure) it’s still “virtualised” infrastructure you are essentially building.

Terraform has three fundamental components to build infrastructure and within those components are arguments.

Provider: this is the actual host/cloud services provider. You can deploy to many providers at the same time by using aliases.

Data: This is referring to the actual infrastructure that your resources will be provisioned on so for example datastore etc.

Resources: the actual infrastructure it self. For example on-prem this could be a vSwitch or a VM. On cloud(e.g azure) can be a VNET( and on that VNET you can create a Subnet(, then you may decided to attach and provision a VM instance to that subnet. Subsequently these will all be resources.

Code Example: This code builds a vSwitch on Vmware ESXI host

Now the key thing is in order to use multiple providers and associate each provider to its specific Data and Resources you will need to create aliases.

Now I’m sure you aware there there three states (plan/apply/destroy)

Plan can be useless simply because of a code “plans” it doesn’t necessarily mean it will “apply” the reason for this is because terraform stores all your infrastructure

Wait for it…..yes on a state file.

It will first store the state of your code in a file before it’s pushed to the actual provider.

Subsequently the state file doesn’t necessarily reflect the actual infrastructure. So for example let’s you built a VM named “Test1”. if you delete the state file and attempt to use terraform “plan” it will actually authorise the plan to create”Test1” again.

However if you try terraform “apply” it will fail because the resource already exist on the provider.

This is the biggest issue with a declarative nature of terraform(I made a YouTube on this issue)

Now the developers did this with good intentions. So that you can use terraform state import. This will allow you to import pre-built infrastructure to your new state file. However this is not always necessarily the case.

To summarise terraform is all declarative. Once you understand the fundamentals:

States: apply, destroy, plan(can be useless)

Infrastructure provisioning: Provider, Data, Resources(the main one)

The language it self is almost plain english the syntax can be tricky, but can be easily learned. The rest is easy!

All of the specific provider codes for each on-prem or cloud provider(AWS/azure etc) can be found on harshicorp website.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s