Apply module composition, workspace isolation, remote state sharing, DynamoDB state locking, and Terragrunt DRY configuration.
0 / 5 completed
1 / 5
What is Terraform module composition and why is it used?
Module composition: a root module calls child modules (e.g. module "vpc" { source = "./modules/vpc" }) passing variables. Child modules encapsulate opinionated defaults. Versioned registry modules (source = "terraform-aws-modules/vpc/aws" version = "5.0") enable teams to consume battle-tested infrastructure patterns without writing the underlying resources.
2 / 5
What is the purpose of Terraform workspaces?
Workspaces: the terraform.workspace variable returns the current workspace name, enabling environment-specific logic: instance_count = terraform.workspace == "prod" ? 3 : 1. Each workspace maintains its own terraform.tfstate in the backend, so terraform apply in "dev" never touches the "prod" state.
3 / 5
What is remote state in Terraform and what problem does it solve?
Remote state: local state files cause conflicts when multiple engineers run terraform apply concurrently. A shared S3 backend with DynamoDB state locking ensures only one operation runs at a time. The terraform_remote_state data source also lets one stack read outputs from another's state, enabling cross-stack dependencies.
4 / 5
What is state locking in Terraform and how does DynamoDB enable it for S3 backends?
State locking: configure backend "s3" { dynamodb_table = "terraform-locks" }. Before apply, Terraform calls PutItem on the DynamoDB table. After completion, it deletes the item. If a previous operation crashed without releasing the lock, terraform force-unlock <LOCK_ID> can release it manually.
5 / 5
What problem does Terragrunt solve that vanilla Terraform does not?
Terragrunt: without it, every Terraform module in a multi-environment repo needs its own backend block, provider config, and repeated variables. Terragrunt's generate blocks and inputs inheritance propagate configuration down a directory hierarchy. It also adds dependency ordering (dependency blocks) for applying stacks in the correct sequence.