
LAB: Terraform Alias + Workspace + Import (Production Style)
📁 Project Structure (Skeleton) terraform-alias-workspace-import-lab/ │ ├── providers.tf ├── variables.tf ├── main.tf ├── outputs.tf ├── terraform.tfvars.example │ ├── backend.tf │ └── scripts/ └── import.sh 1️⃣ providers.tf terraform { required_version = ">= 1.5.0" required_providers { aws = { source = "hashicorp/aws" version = "~> 5.0" } } } # Default provider (primary region) provider "aws" { region = var . primary_region } # Alias provider (secondary region) provider "aws" { alias = "secondary" region = var . secondary_region } 2️⃣ variables.tf (NO hardcoding) variable "project_name" { type = string } variable "environment" { type = string } variable "primary_region" { type = string } variable "secondary_region" { type = string } variable "bucket_name" { type = string } variable "common_tags" { type = map ( string ) default = {} } 3️⃣ main.tf 🔹 Uses: workspace alias provider dynamic naming locals { env = terraform . workspace name_prefix = "${var.project_name}-${local.env}" tags = m
Continue reading on Dev.to Tutorial
Opens in a new tab


