0
0
Terraformcloud~20 mins

Workspaces and remote state in Terraform - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Terraform Workspace & Remote State Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Terraform Workspaces

What is the primary purpose of Terraform workspaces?

ATo store Terraform configuration files remotely for team collaboration.
BTo encrypt sensitive variables in Terraform configurations.
CTo automatically back up state files to cloud storage.
DTo manage multiple distinct state files within the same configuration, allowing isolated environments like dev and prod.
Attempts:
2 left
💡 Hint

Think about how Terraform separates environments using the same code.

Configuration
intermediate
2:00remaining
Remote State Backend Configuration

Which backend configuration snippet correctly sets up Terraform to use an AWS S3 bucket for remote state storage with state locking?

A
terraform {
  backend "s3" {
    bucket = "my-terraform-state"
    key    = "prod/terraform.tfstate"
    region = "us-east-1"
    dynamodb_table = "terraform-lock"
    encrypt = true
  }
}
B
terraform {
  backend "local" {
    path = "./terraform.tfstate"
  }
}
C
terraform {
  backend "s3" {
    bucket = "my-terraform-state"
    key    = "prod/terraform.tfstate"
    region = "us-east-1"
    encrypt = false
  }
}
D
terraform {
  backend "s3" {
    bucket = "my-terraform-state"
    key    = "prod/terraform.tfstate"
    region = "us-east-1"
    dynamodb_table = ""
    encrypt = true
  }
}
Attempts:
2 left
💡 Hint

Look for the option that includes state locking and encryption.

Architecture
advanced
2:00remaining
Choosing Workspace Strategy for Multiple Environments

You have a Terraform configuration for a web app. You want to deploy it to dev, staging, and production environments. Which approach best uses Terraform workspaces to manage these environments?

ACreate three workspaces named dev, staging, and prod. Use the same configuration and switch workspaces to deploy to each environment.
BCreate separate Terraform configurations for each environment and use only the default workspace.
CUse a single workspace and pass environment variables to differentiate environments during deployment.
DUse local state files for each environment and avoid workspaces.
Attempts:
2 left
💡 Hint

Think about how workspaces isolate state but share configuration.

security
advanced
2:00remaining
Securing Remote State Access

Which practice best secures access to Terraform remote state stored in an AWS S3 bucket?

AStore the state file locally and share it via email to avoid cloud exposure.
BMake the S3 bucket public so all team members can access the state file easily.
CUse IAM policies to restrict access to the S3 bucket and DynamoDB table only to authorized users and roles.
DDisable encryption on the S3 bucket to improve performance.
Attempts:
2 left
💡 Hint

Consider AWS best practices for securing sensitive data.

service_behavior
expert
2:00remaining
Effect of Workspace Switch on Terraform State

Given a Terraform configuration with multiple workspaces, what happens to the state when you run terraform workspace select staging?

ATerraform deletes the current workspace state and replaces it with the 'staging' workspace state.
BTerraform switches to the 'staging' workspace and loads its separate state file, isolating resources from other workspaces.
CTerraform ignores the workspace switch and continues using the default workspace state.
DTerraform merges the 'staging' workspace state with the default workspace state into a single file.
Attempts:
2 left
💡 Hint

Think about how workspaces isolate state files.