==========================
== Zhuo Hong Wei's Blog ==
==========================
Any and everything

Terraform Mental Model

Having learnt more about terraform, coupled with some hands-on at work, I have expanded my mental model of terraform.

Drawing it out on paper,

Terraform mental model

We can use count = [some number] to create multiple instances of each resource. If we ever need to identify each instance of a resource, we can make use of a contextual variable called count.index for the index of current instance.

In the diagram above, I have also illustrated a module. Terraform modules are used to organize and reuse logical units of terraform code. Each module can then can its own set of inputs (e.g. variables.tf), outputs (e.g. outputs.tf) and body (main.tf). These collectively describe a single resource or set of related resources (e.g., a docker container with a certain image and volume mount). The body (main.tf) of a module can also contain other modules. So we can see that modules provide us a layering and reuse mechanism for structuring a complex infrastructure.

I drew this diagram spontaneously this morning and I missed out provisioners concept.

Looking to revise and expand this drawing as I learn more about terraform.