teluzia.Cloud Engineer · Day 85
CHAPTER 13 · TERRAFORM FUNDAMENTALS

IaC concepts and Terraform workflow

4–5 hours including independent practice3 topics
LET’S MAKE THIS SIMPLE

What you’re learning today

Terraform is a blueprint reconciler: it compares the blueprint with its tracked building inventory before proposing construction. IaC represents infrastructure intent in reviewable files. Version control records changes and supports collaboration, but files still require safe execution and operational ownership. Declarative configuration describes desired objects rather than a fixed sequence of shell actions. Initialization prepares providers, modules, and backend settings. Validation checks configuration consistency. Planning compares desired configuration with tracked objects and refreshed remote information. These stages answer different questions and should not be treated as interchangeable assurances.

Think of it this way

Terraform is a blueprint reconciler: it compares the blueprint with its tracked building inventory before proposing construction.

TOPIC 01 / 03Step by step

Infrastructure as code

IaC represents infrastructure intent in reviewable files. Version control records changes and supports collaboration, but files still require safe execution and operational ownership. Declarative configuration describes desired objects rather than a fixed sequence of shell actions. For example, a resource block describes one object; the provider performs API calls to converge it.

WORKED EXAMPLE
A resource block describes one object; the provider performs API calls to converge it.

Imagine managing two network resources through a script of create commands. Repeating it may create duplicates unless the script performs its own discovery and comparison. Declarative infrastructure instead describes the intended objects. Terraform combines that configuration with state mappings and provider reads of real objects, then proposes the operations needed to approach the intended result.

Configuration is the desired description. A provider implements interaction with a service. Convergence is movement toward the declared result. Version control makes configuration reviewable but does not enforce safe execution by itself. A file can be correct for one account and destructive in another. IaC reduces undocumented manual work and can improve reproducibility, but introduces state, versioning, access, and change-review responsibilities. Separate temporary experiments from real ownership, and avoid assuming every existing object in an account belongs to the configuration merely because the tool can discover it.

Why this matters

A resource block describes one object; the provider performs API calls to converge it.

A common trap

Do not overlook this operational distinction: Declarative configuration describes desired objects rather than a fixed sequence of shell actions.

MAKE IT VISIBLE

Rehearse a release decision

A RELEASE IS A SERIES OF DECISIONS

Can you ship without losing the old version?

This browser simulation shows why tests, plan review, health validation and rollback belong in a pipeline.

1Tests
2Plan review
3Deploy
4Health check
Currently serving: v1

Ready to run

Read all topics in this lesson

A complete reference to revisit alongside the guided steps above.

Infrastructure as code

IaC represents infrastructure intent in reviewable files. Version control records changes and supports collaboration, but files still require safe execution and operational ownership. Declarative configuration describes desired objects rather than a fixed sequence of shell actions. For example, a resource block describes one object; the provider performs API calls to converge it.

WORKED EXAMPLE
A resource block describes one object; the provider performs API calls to converge it.

Imagine managing two network resources through a script of create commands. Repeating it may create duplicates unless the script performs its own discovery and comparison. Declarative infrastructure instead describes the intended objects. Terraform combines that configuration with state mappings and provider reads of real objects, then proposes the operations needed to approach the intended result.

Configuration is the desired description. A provider implements interaction with a service. Convergence is movement toward the declared result. Version control makes configuration reviewable but does not enforce safe execution by itself. A file can be correct for one account and destructive in another. IaC reduces undocumented manual work and can improve reproducibility, but introduces state, versioning, access, and change-review responsibilities. Separate temporary experiments from real ownership, and avoid assuming every existing object in an account belongs to the configuration merely because the tool can discover it.

Why this matters

A resource block describes one object; the provider performs API calls to converge it.

A common trap

Do not overlook this operational distinction: Declarative configuration describes desired objects rather than a fixed sequence of shell actions.

Init, validate, and plan

Initialization prepares providers, modules, and backend settings. Validation checks configuration consistency. Planning compares desired configuration with tracked objects and refreshed remote information. These stages answer different questions and should not be treated as interchangeable assurances. For example, terraform validate can pass even when AWS credentials later fail during terraform plan.

WORKED EXAMPLE
terraform validate can pass even when AWS credentials later fail during terraform plan.

First, terraform init resolves declared providers, modules, and backend configuration. Next, validate checks internal configuration consistency. Plan then uses inputs, state mappings, and relevant provider reads to propose resource actions. These stages answer different questions: files may validate even when planning cannot authenticate to the cloud or read a required object.

Initialization prepares dependencies. Validation checks configuration semantics within its supported scope. A plan is a proposed change set, not an executed result. Saved plans can support reviewing the exact proposal later applied, while carrying potentially sensitive values. Examine replacements and deletions, not just the final count. Planning can reveal a changed remote object, but it does not automatically decide whether that manual change should be retained. The team must choose the desired configuration and ownership policy. Do not use successful initialization as proof that credentials, quota, or deployment-time behavior will work.

Why this matters

terraform validate can pass even when AWS credentials later fail during terraform plan.

A common trap

Do not overlook this operational distinction: These stages answer different questions and should not be treated as interchangeable assurances.

Apply and state

Apply executes a reviewed proposal, while state maintains resource-address mappings and metadata. It is possible for some changes to succeed before another fails. Recover by inspecting the resulting state and remote resources instead of assuming an error means nothing changed. For example, after one resource succeeds and another fails, rerun a plan to see the remaining intended work.

WORKED EXAMPLE
After one resource succeeds and another fails, rerun a plan to see the remaining intended work.

Suppose configuration declares a bucket, state maps its address to an existing bucket identifier, and the real bucket has a setting changed outside Terraform. During planning, the provider reads the remote value and Terraform compares it with the configured value. The proposed difference depends on both that observed reality and the intended configuration. State is neither the bucket itself nor a backup of its contents.

A resource address identifies Terraform's logical object. State links that address to a remote identity and metadata. Drift is a difference introduced outside the declared workflow. Apply may change some objects before another action fails, leaving a partial result. Inspect state and real resources, then generate a new plan. Deleting state to make an error disappear can make Terraform believe it must create already-existing objects. Keep state protected and use supported recovery or import workflows rather than hand-editing identifiers casually.

Why this matters

After one resource succeeds and another fails, rerun a plan to see the remaining intended work.

A common trap

Do not overlook this operational distinction: Recover by inspecting the resulting state and remote resources instead of assuming an error means nothing changed.

KEEP THESE WITH YOU

Today’s takeaways

Infrastructure as code: IaC represents infrastructure intent in reviewable files. Version control records changes and supports collaboration, but files still require safe execution and operational ownership. Declarative configuration describes desired objects rather than a fixed sequence of shell actions.

Init, validate, and plan: Initialization prepares providers, modules, and backend settings. Validation checks configuration consistency. Planning compares desired configuration with tracked objects and refreshed remote information. These stages answer different questions and should not be treated as interchangeable assurances.

Apply and state: Apply executes a reviewed proposal, while state maintains resource-address mappings and metadata. It is possible for some changes to succeed before another fails. Recover by inspecting the resulting state and remote resources instead of assuming an error means nothing changed.

CLOSE THE LOOP

Ready to complete this day?

Verify the practical steps and pass the knowledge check (at least two thirds correct).

Lab steps verifiedKnowledge check passed