Terraform Lab: Using `locals` (Real Project Style)
📁 Project Structure terraform-locals-lab/ ├── main.tf ├── variables.tf ├── outputs.tf ├── providers.tf ├── terraform.tfvars 1️⃣ providers.tf provider "aws" { region = var.aws_region } 2️⃣ variable...

Source: DEV Community
📁 Project Structure terraform-locals-lab/ ├── main.tf ├── variables.tf ├── outputs.tf ├── providers.tf ├── terraform.tfvars 1️⃣ providers.tf provider "aws" { region = var.aws_region } 2️⃣ variables.tf 👉 Only inputs (NO hardcoding) variable "aws_region" { type = string } variable "project_name" { type = string } variable "environment" { type = string } variable "bucket_suffix" { type = string } 3️⃣ locals (MAIN PART) 👉 This is where magic happens locals { name_prefix = "${var.project_name}-${var.environment}" common_tags = { Project = var.project_name Environment = var.environment ManagedBy = "Terraform" } bucket_name = "${local.name_prefix}-${var.bucket_suffix}" } 4️⃣ main.tf resource "aws_s3_bucket" "this" { bucket = local.bucket_name tags = local.common_tags } 5️⃣ terraform.tfvars aws_region = "us-east-2" project_name = "jumptotech" environment = "dev" bucket_suffix = "lab" 6️⃣ outputs.tf output "bucket_name" { value = local.bucket_name } 🚀 How to Run terraform init terraform pla