TF Series: Basics
This blog is the sub-part of "Terraform Associate 003 Series". To navigate back to the main Blog Page and know other topics of this series, click here. Here, we will be covering the Basic concepts of Terraform.
What is Terraform?
It is an Infrastructure as a Code (IaaC) and has been divided into Declarative and Cloud Agnostic IaaC. It is a good managing drift when compared to other IaC tools.
What is Terraform Cloud?
It is a SaaS offering for
Remote Stage Storage
Version Control Integrations
Collaborate on Infrastructure Changes in a single unified web portal [www.terraform.io/cloud].
Declarative Vs Imperative IaC tools
Declarative
What you see is what you get (Explicit)
More verbose, zero chance of misconfiguration.
Uses scripting Langs: JSON, YAML, XML
Other tools: AWS CFN, ARM templates (for AZ), Azure Blueprints, Cloud Deployment Manager (for GCP), Terraform
Imperative
You say what you want, and the rest is filled in (Implicit)
Less verbose, can end up with misconfiguration.
Does more than Declarative
Uses programming Langs: Python, Ruby, JavaScript
Other tools: AWS CDK, Pulumi
Declarative+
Terraform is declarative but the Terraform language features imperative-like functionality. Supports: Loops (For Each); Dynamic Blocks; Locals; Complex Data Structures (Map, Collections). Uses HCL (Terraform Language).
Infrastructure Lifecycle
Plan -> Design -> Build -> Test -> Deliver -> Maintain -> Retire.
Day 0: Plan & Design | Day 1: Develop & Iterate | Day 2: Go Live & Maintain.
Advantages of IaC Lifecycle
1) Reliability: IaC makes changes Idempotent, consistent, repeatable & predictable.
Idempotent: No matter how many times you run your IaC, you'll always end up with the same state that is expected.
2) Manageability: Enable mutation via code; Revised with minimal changes.
3) Sensibility: Avoid financial & reputational losses.
Non-Idempotent Vs Idempotent
Non-idempotent: In this case, when we deploy 2 VMs and then do some modifications in the code and re-deploy, it will give us a total of 4 VMs.
This means, that whenever the new configuration is done, it will provide other new deployments - which we don't usually want it to be like this. We expected 2 but, ended up with 4.
Idempotent: In this case, when we deploy 2 VMs and then modify the configuration & re-deploy that, it will modify in the previous state only and in total there will be only 2 VMs with new modifications. This will just delete, re-create or modify the older VMs to newer VMs. We expected 2 and ended up with 2.
Subscribe to my newsletter
Read articles from Krunali Jain directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Krunali Jain
Krunali Jain
Being Curious is better than being Smart.