.terraform/plan -out then apply on the saved plan for reviewed, repeatable applies.
terraform — Backend, required providers/versions, experimentsprovider — Plugin configuration (region, credentials source, features)resource — Managed infrastructure objectsdata — Read-only lookups of existing infrastructurevariable — Input parametersoutput — Exported values after applymodule — Reusable configuration packageslocals — Named local expressions to reduce repetitionresource_type.name.attribute in expressions.locals versus variable blocks?
.tfvars, or CI. They define the module's contract and should stay minimal and stable.local.
resource blockterraform.tfstate?
terraform force-unlock only after confirming no active apply is running — otherwise you risk state corruption.
terraform import, and what does it not do for you?
terraform import associates an existing cloud resource with a resource address in state. Use it when infrastructure was created outside Terraform or after state loss.resource block yourself; newer versions may assist with plan -generate-config-out depending on version). Import also does not change remote infrastructure — it only updates state.plan and reconcile until the plan is clean (config must match reality).
backend block (or change it) in terraform configuration.terraform init -migrate-state (or follow prompts on re-init). Terraform copies state from the old backend to the new one.terraform state mv / state rm with extreme care and read-only validation plans first.
.tf files with optional inputs (variable) and outputs (output). It encapsulates a reusable piece of infrastructure (VPC, EKS cluster, RDS instance).module blocks. Everything else is a child module.
output blocks in the child module. In the root, reference them as module.module_name.output_name. Those values can feed other modules or root-level outputs.module "x" { ... } arguments mapped to variable blocks inside the child.
source = "git::https://..." with a ?ref= tag, branch, or commit SHA. Prefer immutable refs (tags or SHAs) for production — not main without pinning.source = "namespace/name/provider" with a version constraint in the module block. Semver ranges give controlled upgrades; the registry resolves compatible versions.depends_on instead of implicit dependencies?
depends_on when there is a real ordering requirement that is not visible in the configuration — for example, a resource must exist before another API becomes consistent, or IAM propagation delays.depends_on hides the data flow and can slow applies; prefer references when possible.
count and for_each for multiple resource instances.
count — Integer index [0], [1]. Simple but reordering the list can cause destroy/recreate of the "wrong" index. Use for homogeneous sets where order is stable or you accept replacement.for_each — Map or set of string keys; instance addresses use the key. Safer when identities must stay stable when the collection changes (rename keys deliberately). Required for resources that do not support count in some edge cases — generally preferred for maps of named objects.lifecycle block control? Name common meta-arguments.
lifecycle changes how Terraform manages a specific resource instance. Common meta-arguments:
create_before_destroy — Create replacement before destroying old (reduces downtime when supported)prevent_destroy — Fail plan/apply if destroy is proposedignore_changes — Do not update for listed attributes (drift or external updates)replace_triggered_by — Force replace when other resources change (1.2+)create_before_destroy do, and when is it useful?
plan, Terraform refreshes state from providers (unless refresh is disabled) and compares to desired config, proposing updates to reconcile. terraform plan -refresh-only focuses on refreshing state without other changes.
data source instead of a resource?
data when you need to read existing infrastructure you do not manage in this configuration (shared VPC, AMI lookup, current AWS account ID, secrets metadata). Data sources never create or destroy remote objects.resource when this Terraform project should own the lifecycle of that object.
provider blocks with the alias meta-argument and different settings (region, assume_role, etc.). Pass provider = aws.west (or map of providers) into modules/resources that should use that instance.alias.
env:/dev, env:/prod prefixes). They let one configuration switch state with workspace select.-var and -var-file flags on the commandTF_VAR_nameterraform.tfvars, *.auto.tfvarsvariable blocks.terraform.lock.hcl, and should it be committed?
init. It ensures reproducible installs across laptops and CI.-target acceptable, and what are the risks?
-target limits the plan/apply graph to specific resources — useful for emergency remediation, breaking circular dependency deadlocks during migration, or incremental import workflows.TF_VAR_ or ephemeral workspacessensitive = true on a variable or output do?
<sensitive>). It does not encrypt values in state or on disk — state remains sensitive. Use for reducing accidental exposure in logs; combine with proper secret storage and backend controls.
check blocks (Terraform 1.5+), and how do they relate to Sentinel or OPA?
assume_role in the provider from a central tooling account; CI role with least privilege per accountdata "terraform_remote_state" or SSM data sources