Q: You have a Terraform configuration that manages resources in 3 AWS accounts. How do you structure this?
Use multiple provider configurations with aliases or split into multiple workspaces/modules:
Want to master this scenario in a live sandbox? KodeKloud's HashiCorp Certified Terraform Associate (003) Interactive Labs covers this exact problem with hands-on terminal drills.
🛠️ Production Runbook & Step-by-Step Resolution
Direct Answer: "Treat Terraform code with the same rigor as application code: pre-merge plans, state locks, and automated drift detection. When addressing this question, I walk the interviewer through our production incident runbook: isolating the blast radius, checking diagnostic logs and metrics, and applying a safe fix."
Production Solution & Architecture
Use multiple provider configurations with aliases or split into multiple workspaces/modules: Better approach at scale: separate Terraform root modules per account. Each module has its own state file, backend config, and runs independently. Avoid cross-account state dependencies — they create tight coupling. Use Terragrunt to DRY (Don't Repeat Yourself) across multiple root modules.
provider "aws" {
alias = "account-a"
assume_role {
role_arn = "arn:aws:iam::111111111:role/terraform"
}
}
provider "aws" {
alias = "account-b"
assume_role {
role_arn = "arn:aws:iam::222222222:role/terraform"
}
}
resource "aws_s3_bucket" "a" {
provider = aws.account-a
bucket = "my-bucket-a"
}
- Immediate Triage: Use multiple provider configurations with aliases or split into multiple workspaces/modules:
- Run targeted verification commands before modifying configuration.
- Automate permanent guardrails (CI check, alerts, IaC policy) to prevent recurrence.
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
- Relying on legacy bucket ACLs instead of modern S3 Block Public Access and IAM bucket policies when configuring Terraform configuration manages AWS recommends disabling ACLs (Bucket Owner Enforced) in favor of centralized declarative bucket policies and account-level Block Public Access controls.
-
Confusing SSE-S3 encryption with KMS customer-managed key (SSE-KMS) authorization policies when configuring Terraform configuration manages
Accessing SSE-KMS encrypted objects requires both
s3:GetObjectandkms:Decryptpermissions; neglecting KMS key policies causes silent 403 Forbidden errors. - Using sequential timestamps or predictable prefixes for high-throughput S3 read and write keys when configuring Terraform configuration manages Sequential key prefixes limit S3 horizontal partitioning; randomized hash prefixes distribute workloads across partitions to achieve 3,500 PUT and 5,500 GET requests/sec.
- Failing to audit S3 object delete markers when troubleshooting missing versioned objects when configuring Terraform configuration manages Issuing a DELETE on a versioned bucket only adds a delete marker; engineers must retrieve previous versions or purge markers to restore data.