Using Terraform.workspace Interpolation
📖 Scenario: You are managing infrastructure for multiple environments like development and production. You want to use Terraform to create resources that change based on the current workspace.
🎯 Goal: Build a Terraform configuration that uses terraform.workspace interpolation to set resource names dynamically depending on the active workspace.
📋 What You'll Learn
Create a Terraform variable to hold a base resource name
Define a local value that combines the base name with the current workspace using
terraform.workspaceCreate an AWS S3 bucket resource using the combined name
Add a tag to the bucket that shows the current workspace
💡 Why This Matters
🌍 Real World
Terraform workspaces help manage multiple environments like dev, test, and prod using the same configuration but different resource names.
💼 Career
Cloud engineers use <code>terraform.workspace</code> interpolation to write reusable infrastructure code that adapts to different deployment environments.
Progress0 / 4 steps