Track
Terraform & IaC lessons
43 short lessons on Terraform & IaC. Each one starts from a real situation, shows how it works, and ends with a quiz. Free to read.
All 43 lessons
- Infrastructure as code: why and what declarative meansBeginner · 5 min
Why a security group nobody can explain is a bigger risk than one that is misconfigured, and how describing the end state in a file lets a tool find the gap for you.
- The Terraform workflow: init, plan, apply, destroyBeginner · 5 min
Four commands, one rule: read the output of the second before you run the third. Create a bucket, prove nothing is left to change, then delete it again.
- Variables, outputs and localsBeginner · 5 min
One set of files, two environments: how variables, locals and outputs let the same code build staging and prod, and which source of values wins when two disagree.
- Terraform state: what it maps and why it mattersBeginner · 5 min
A pull request that only renames a resource label plans to delete a bucket holding 90 GB of logs. State explains why, and one moved block fixes it.
- Remote state and lockingBeginner · 5 min
Two engineers apply within seconds of each other. Without a shared state and a lock, one run overwrites the other's record. Here is how the second one gets stopped…
- Lifecycle ignore_changesBeginner · 4 min
Lifecycle ignore_changes suppresses plans for selected attribute drift.
- create_before_destroyBeginner · 4 min
create_before_destroy requests replacement creation before deletion.
- Providers and version lockingBeginner · 5 min
Why a pipeline that passed for three months can start changing 14 resources on a Monday, and the two files that stop it.
- Modules: reuse without copy-pasteBeginner · 5 min
Fourteen log buckets across five repos, three different encryption settings, and an audit question nobody can answer. A module turns that into one definition.
- Terraform workspaceBeginner · 4 min
Terraform workspace separates multiple state instances.
- Data sourcesBeginner · 5 min
Data sources read existing infrastructure for configuration.
- Reading a plan: create, change, destroy and replaceBeginner · 5 min
The summary line of a plan counts replacements twice. How to read every symbol, find the attribute that forced a replacement, and spot drift.
- terraform importBeginner · 4 min
terraform import associates existing infrastructure with state.
- Terraform refreshBeginner · 4 min
Terraform refresh reads current provider objects into planning.
- Moved blocksBeginner · 4 min
Moved blocks record resource address refactors.
- IAM policy for automationBeginner · 4 min
IAM policy for automation bounds Terraform permissions.
- S3 remote backendBeginner · 4 min
S3 remote backend persists Terraform state in an S3 object.
- Plan approvalsBeginner · 4 min
Plan approvals gate changes before production apply.
- Terraform init and providersBeginner · 4 min
terraform init installs the providers and modules a configuration needs and sets up its backend, and the committed lock file keeps every run on the same provider…
- Dependency graphIntermediate · 4 min
Terraform builds a dependency graph from references and explicit depends_on lines, and the graph sets the order of work and decides which resources can run in parallel.
- State lockingIntermediate · 4 min
A supported backend locks Terraform state to coordinate operations that could write it.
- Remote backendsIntermediate · 5 min
A backend stores Terraform state in shared storage and can lock it so two runs cannot write the same state, and that state holds secrets that need the same protection…
- Drift detectionIntermediate · 4 min
Drift is a difference between Terraform's state and the real infrastructure, and a refresh-only plan shows it without changing anything, though a plan with refresh…
- Plan versus applyIntermediate · 4 min
A plan is a proposal, and a saved plan file holds the reviewed actions that apply performs without a new prompt, which keeps the approval and the change tied together.
- Resource lifecycleIntermediate · 4 min
Lifecycle settings control replacement order, destruction guards and ignored attributes, so each setting decides whether a change replaces a live resource safely or is…
- for_each identityIntermediate · 4 min
for_each identifies each instance by its map key or set element, so renaming a key looks like destroying one object and creating another unless the move is recorded.
- count indexingIntermediate · 4 min
count identifies instances by index, so reordering or removing a list item can change which live object each index points to, and the plan can replace them.
- Import existing resourcesAdvanced · 4 min
Import records an existing object in state without changing it, and a clean plan afterwards shows the configuration matches the real object so the team can manage it.
- Module contractsAdvanced · 4 min
A module's input variables and output values form its contract with callers, so renaming an output or removing an input breaks callers even when the module code is…
- Output sensitivityAdvanced · 4 min
A sensitive output is hidden on screen and in logs, but Terraform still stores the value in state, so the state store and the CI logs need the real protection.
- Secret handlingAdvanced · 5 min
Secrets in Terraform reach state and plan files even when they are marked sensitive, so a handling plan must cover where values are stored, who can read them and how…
- Provider aliasesAdvanced · 4 min
Provider aliases give one provider several configurations, and resources and modules must pick one explicitly because the default is used without warning when they do…
- Multi account providersAdvanced · 4 min
Multi-account Terraform works when each provider configuration assumes a role in its own account, because an assumed session carries that role's permissions and then…
- Workspaces limitationsAdvanced · 4 min
Workspaces hold separate states inside one backend and one configuration, which makes them a weak barrier between environments that need separate credentials, so use…
- Policy as codeAdvanced · 4 min
Policy as code checks Terraform plan data against written rules before changes are applied, and it protects a team only when the rules are tested and fail on a known…
- OPA and SentinelAdvanced · 4 min
OPA and Sentinel are policy frameworks that evaluate rules against plan data, and the right choice depends on whether the checks run inside HCP Terraform or in your own…
- Terraform testingAdvanced · 4 min
Explain how Terraform's built-in test files check a module's behaviour. Plan-mode runs read planned values cheaply, while apply-mode runs create real infrastructure and…
- State recoveryAdvanced · 5 min
Explain how to recover Terraform state when a real object and its state entry disagree. Back up state first, then edit the state map and plan again before any apply.
- Destroy planningAdvanced · 4 min
Explain how to build, save and read a Terraform destroy plan before anything is deleted. The saved plan shows exactly what the destroy will remove, and only that file…
- Terragrunt orchestrationAdvanced · 4 min
Explain how Terragrunt runs many Terraform units in dependency order and passes outputs between them. Mock outputs and wide run scopes are the two places where a run…
- IaC code reviewAdvanced · 4 min
Explain how to review a Terraform change by its plan, not just its diff. Formatting and validate checks are cheap, but access and network changes need a reader who…
- Output sensitivity: failure analysisAdvanced · 4 min
Explain what the sensitive flag on a Terraform output does and does not protect. The value is hidden in display output but still written to state, plan files and…
- Secret handling: operational verificationAdvanced · 4 min
Explain how to verify that a secret stays out of the places it should not reach. A repeatable test with a dummy value searches state, plans and logs before merge.