Workspaces vs Directory-Based Separation in Terraform
📖 Scenario: You are managing infrastructure for a company that has multiple environments: development and production. You want to organize your Terraform code to handle these environments safely and efficiently.Two common ways to separate environments are using Terraform workspaces or using directory-based separation with different folders for each environment.
🎯 Goal: Build two simple Terraform configurations: one using terraform workspace to separate dev and prod environments, and another using separate directories for dev and prod. You will create a resource in each setup that shows how the environment name is used.
📋 What You'll Learn
Create a Terraform configuration with a variable
environment set by workspaceCreate a resource that uses the
environment variable in its nameCreate a separate directory structure for
dev and prod with their own terraform.tfvarsCreate a resource in each directory that uses the
environment variable from terraform.tfvars💡 Why This Matters
🌍 Real World
Managing multiple environments safely is common in real-world infrastructure projects. Workspaces and directory separation are two practical ways to organize Terraform code for this.
💼 Career
Cloud engineers and DevOps professionals often need to manage infrastructure for multiple environments. Knowing how to separate environments using Terraform workspaces or directories is a key skill.
Progress0 / 4 steps