Infrastructure as Code (IaC) for Data Platforms with Terraform
Provision warehouses, buckets, IAM, and clusters reproducibly with Terraform.
In plain words
Pinned providers, modules, variables, and policies. Next, OIDC credential, remote state, diff, and policy check. Finally, detect changes, import, key/role lifecycle.
Think of it like…
Terraform is a construction blueprint with a state ledger and change order; the blueprint should never contain the vault key, and demolition needs a separate safety interlock.
Where you’ve seen it
lifecycle { prevent_destroy = true } protects a data bucket, a GCS/S3 backend holds encrypted state with versioning, and GitHub OIDC assumes a narrow Terraform role before terraform plan -out=review.plan gates apply.
Words you’ll hear
- Terraform
- Infrastructure-as-code tool using HCL configuration, providers, state, and plan/apply workflows.
- IaC
- Declarative infrastructure treated as reviewable/versioned source rather than manually configured consoles.
- IAM
- Identity and policy determining whether Terraform or data workloads may create buckets, warehouses, roles, and keys.
- Operational boundary
- Storing secrets or unencrypted state can leak credentials, a broad
destroyin the same plan can erase data buckets, and provider authentication that is too powerful defeats least privilege in every apply. Use remote encrypted/locked state, plan/apply through reviewed environments, prevent deletion on stateful resources, pin providers/modules, use separate narrow deployment roles, and import/drift-detect existing data infrastructure.
Visual diagram
Theory & deep dive
Terraform: the working mechanism
Terraform declares cloud data resources-buckets, warehouses, IAM, KMS, networks, clusters-and records state so CI can review plans, apply controlled diffs, and recreate infrastructure consistently.
Pinned providers, modules, variables, and policies. OIDC credential, remote state, diff, and policy check, then approval, locking, stateful resource guard, and evidence; this exposes the state governed by IAM.
lifecycle { prevent_destroy = true } protects a data bucket, a GCS/S3 backend holds encrypted state with versioning, and GitHub OIDC assumes a narrow Terraform role before terraform plan -out=review.plan gates apply.
Infrastructure as Code for Data Platforms with Terraform: failure mode and production response
Storing secrets or unencrypted state can leak credentials, a broad destroy in the same plan can erase data buckets, and provider authentication that is too powerful defeats least privilege in every apply.
Use remote encrypted/locked state, plan/apply through reviewed environments, prevent deletion on stateful resources, pin providers/modules, use separate narrow deployment roles, and import/drift-detect existing data infrastructure. Track State lock as "one apply for an environment at a time", and make Provider pin visible to the dataset owner.
How it works, step by step
Step 1 of 41. Declare
Pinned providers, modules, variables, and policies. Terraform declares cloud data resources-buckets, warehouses, IAM, KMS, networks, clusters-and records state so CI can review plans, apply controlled diffs, and recreate infrastructure consistently.
- State lock
- one apply for an environment at a time
- IaC
- Declarative infrastructure treated as reviewable/versioned source rather than manually configured consoles.
When to use it & trade-offs
What it is
Terraform declares cloud data resources-buckets, warehouses, IAM, KMS, networks, clusters-and records state so CI can review plans, apply controlled diffs, and recreate infrastructure consistently. lifecycle { prevent_destroy = true } protects a data bucket, a GCS/S3 backend holds encrypted state with versioning, and GitHub OIDC assumes a narrow Terraform role before terraform plan -out=review.plan gates apply.
Why it matters: Storing secrets or unencrypted state can leak credentials, a broad destroy in the same plan can erase data buckets, and provider authentication that is too powerful defeats least privilege in every apply. Use remote encrypted/locked state, plan/apply through reviewed environments, prevent deletion on stateful resources, pin providers/modules, use separate narrow deployment roles, and import/drift-detect existing data infrastructure.
When to reach for it
- Provision warehouses, buckets, IAM, and clusters reproducibly with Terraform.
- Choose Terraform because it provides this capability: Infrastructure-as-code tool using HCL configuration, providers, state, and plan/apply workflows.
- Keep evidence for State lock at "one apply for an environment at a time" so the last production stage-Drift/rotate - detect changes, import, key/role lifecycle-remains testable.
When to avoid or be careful
- Storing secrets or unencrypted state can leak credentials, a broad
destroyin the same plan can erase data buckets, and provider authentication that is too powerful defeats least privilege in every apply. - Do not conflate IaC with Terraform. The second concept contributes different behavior: Declarative infrastructure treated as reviewable/versioned source rather than manually configured consoles.
- Release only after this guardrail is in place: Use remote encrypted/locked state, plan/apply through reviewed environments, prevent deletion on stateful resources, pin providers/modules, use separate narrow deployment roles, and import/drift-detect existing data infrastructure.
Terraform / IaC / IAM - roles, limits, and operating cost
Strengths: Infrastructure-as-code tool using HCL configuration, providers, state, and plan/apply workflows. Terraform declares cloud data resources-buckets, warehouses, IAM, KMS, networks, clusters-and records state so CI can review plans, apply controlled diffs, and recreate infrastructure consistently.
Watch out: Storing secrets or unencrypted state can leak credentials, a broad destroy in the same plan can erase data buckets, and provider authentication that is too powerful defeats least privilege in every apply.
Strengths: Declarative infrastructure treated as reviewable/versioned source rather than manually configured consoles. In this workflow it supports: Apply - approval, locking, stateful resource guard, and evidence.
Watch out: The operating cost is real: versions and checksums committed in lock file.
Strengths: Identity and policy determining whether Terraform or data workloads may create buckets, warehouses, roles, and keys. Its output can be checked with Destructive plan.
Watch out: Operating guardrail: Use remote encrypted/locked state, plan/apply through reviewed environments, prevent deletion on stateful resources, pin providers/modules, use separate narrow deployment roles, and import/drift-detect existing data infrastructure.
Interview signals & numbers to know
When this topic comes up
- “Where is the failure boundary for Terraform, and how would State lock reveal it?”
- “Why is IaC distinct from this behavior: identity and policy determining whether Terraform or data workloads may create buckets, warehouses, roles, and keys?”
- Production clue: Storing secrets or unencrypted state can leak credentials, a broad destroy in the same plan can erase data buckets, and provider authentication that is too powerful defeats least privilege in every apply.
- Design probe: Use remote encrypted/locked state, plan/apply through reviewed environments, prevent deletion on stateful resources, pin providers/modules, use separate narrow deployment roles, and import/drift-detect existing data infrastructure.
Benchmarks & rules of thumb
- State lock
- one apply for an environment at a time
- Provider pin
- versions and checksums committed in lock file
- Destructive plan
- zero unreviewed delete/replace on stateful data resources
Common mistakes & follow-ups
Common interview mistakes
- Storing secrets or unencrypted state can leak credentials, a broad
destroyin the same plan can erase data buckets, and provider authentication that is too powerful defeats least privilege in every apply. - Reporting success from a job exit code without checking State lock and Provider pin.
- Treating this example as complete without replay, rollback, or access boundaries:
lifecycle { prevent_destroy = true }protects a data bucket, a GCS/S3 backend holds encrypted state with versioning, and GitHub OIDC assumes a narrow Terraform role beforeterraform plan -out=review.plangates apply.
Likely interviewer follow-ups
- How would you prove this contract instead of only checking that the command ran: Infrastructure-as-code tool using HCL configuration, providers, state, and plan/apply workflows.
- What does the recovery plan do when this occurs? Storing secrets or unencrypted state can leak credentials, a broad
destroyin the same plan can erase data buckets, and provider authentication that is too powerful defeats least privilege in every apply. - When is Terraform insufficient for Provider pin, and what does adding IaC cost in State lock?
Knowledge check
Put it into practice
Practice related interview Q&A
Apply Infrastructure as Code (IaC) for Data Platforms with Terraform with data engineer interview Q&A and hands-on practice.