RousselTMLEARNING

Article · Terraform: from discovery to expertise

Environments and organisation

1. Several environments #

Folders, tfvars or workspaces.

Comparison #

ApproachAdvantagesLimits
Folder per environmentStrong isolation, separate backendsSome duplication (reduced by modules)
tfvars filesOne codebase, values per environmentSame backend: be careful
CLI workspacesSeveral states for the same codeEasy to pick the wrong workspace; no permission isolation

Example #

envs/
  recette/  main.tf  backend.tf  recette.tfvars
  prod/     main.tf  backend.tf  prod.tfvars
modules/
  reseau/ app/ base/

cd envs/prod && terraform plan -var-file=prod.tfvars

2. Splitting into layers #

Smaller states.

Layers #

Infrastructure layers
An application change cannot destroy the network by mistake.
data "terraform_remote_state" "reseau" {
  backend = "s3"
  config  = { bucket = "etat-terraform-123", key = "reseau/prod.tfstate", region = "eu-west-3" }
}

module "app" {
  source     = "../../modules/app"
  subnet_ids = data.terraform_remote_state.reseau.outputs.private_subnets
}

3. Complementary tools #

Reducing repetition.

Tools #

  • Terragrunt: DRY configuration of backends and dependencies between layers.
  • HCP Terraform: remote workspaces with variables, permissions and runs per team.
  • Reading outputs through data sources (SSM parameters, tags) rather than terraform_remote_state to reduce coupling.

📄 Terraform multi-environment, workspaces and repository organization →

My progress

  • ⏱ Estimated time : ≈ 5 min

Sign in to track your progress and take notes. Sign in

⭐ Rate this lesson

5.0 initial rating from the teaching team

Sign in to rate this lesson →

💬 Questions about this lesson

No questions yet: be the first to ask for help or share your configuration.

Ask a question about this lesson →

Recommended Articles

Terraform best practices: structure, state, security, review and maintenance

Terraform best practices for teams: repository structure, naming, pinned versions, encrypted and ...

Terraform modules: designing, versioning and reusing

Structure Terraform with modules: root module and child modules, inputs and outputs, sources (loc...

Terraform state: remote backends, locking, import and refactoring

Manage Terraform state: the role of the state file, sensitive data, remote backends (S3, azurerm,...

Preparing for the HashiCorp Certified: Terraform Associate certification

Preparation guide for the Terraform Associate: format, official objectives (IaC concepts, workflo...

Terraform: principles, architecture and workflow

Understand Terraform: declarative infrastructure as code, architecture (core, providers, state), ...

The HCL language: resources, variables, outputs, data and expressions

Writing Terraform: terraform, provider, resource and data blocks, typed variables with validation...

Testing and securing Terraform: validate, terraform test, tflint, Checkov and policies

Ensure the quality of Terraform code: fmt and validate, native terraform test tests with mocked p...

Terraform in CI/CD: pipelines, plan review, OIDC and GitOps

Automate Terraform: plan pipeline on merge requests and apply after approval, posting the plan as...

Terraform across multiple clouds: AWS, Azure, Google Cloud, OVHcloud and Kubernetes

Use Terraform with the main providers: aws, azurerm, google, ovh and openstack, kubernetes and he...

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!