You have a Terraform configuration that uses a remote state data source to read outputs from another workspace. What will happen if the remote state backend is unreachable during terraform apply?
data "terraform_remote_state" "vpc" { backend = "s3" config = { bucket = "my-terraform-state" key = "vpc/terraform.tfstate" region = "us-east-1" } } resource "aws_instance" "web" { ami = "ami-123456" instance_type = "t2.micro" subnet_id = data.terraform_remote_state.vpc.outputs.subnet_id }
Think about what happens if Terraform cannot access the state it depends on.
If Terraform cannot access the remote state backend, it cannot retrieve the outputs needed for resource creation. This causes the apply to fail with an error.
Which Terraform configuration snippet correctly defines a remote state data source to read outputs from an S3 backend?
Check the syntax for the remote state data source and required config keys.
Option C correctly uses the data source block with backend and config keys. Option C misses the config block. Option C uses invalid syntax. Option C misses the region key which is required for S3 backend.
You want to manage multiple environments (dev, staging, prod) using Terraform with remote state stored in S3. Which architecture ensures isolation and safe state management?
Think about cost, isolation, and ease of management.
Using one bucket with separate key prefixes isolates states per environment while keeping management simple and cost-effective. Separate buckets increase complexity and cost. Single key risks overwriting states. Local storage is unsafe for collaboration.
Which practice best secures access to Terraform remote state stored in an S3 bucket?
Consider AWS best practices for security and access control.
Enabling versioning protects against accidental deletions. Restricting access with IAM policies limits who can read or modify state. Public buckets or sharing root credentials are insecure. Disabling encryption exposes sensitive data.
You have multiple Terraform modules that depend on outputs from a shared network module stored in remote state. What is the best practice to manage these dependencies to avoid state conflicts and ensure consistency?
Think about modularity, state isolation, and automation.
Using terraform_remote_state data sources allows modules to consume outputs from shared modules without merging states, preserving isolation and consistency. Manual copying or scripts are error-prone. Merging all modules reduces modularity and increases risk of conflicts.