0
votes

We're provisioning a Landing Zone in Azure and will predominantly use the following:

  1. Terraform as our IaC.
  2. Azure Pipelines for provisioning the required Azure resources.

As we will be provisioning across multiple environments - Dev, Test and Prod, we've identified a modular approach to be the preferred option for our Terraform code. I'd therefore like a very basic example of how I can put together a Terraform module for 3 Resource Groups deployed across all three environments - Dev, Test and Prod.

Hopefully, I can then adopt the same concept to provision other resources in a modular manner.

1

1 Answers

0
votes

There's a number of ways to accomplish this. If you are using Terraform's Cloud backend for state management I would recommend looking at Terraform Workspaces.

Alternatively, we work with multiple environments with internal modules quite a bit here. The way we achieved it:

/
README.md
main.tf
variables.tf
environments/
../dev/
....terraform.tfvars

This allows you to have X amount of variables, and with CI you can just point to these differnet variables per environment files to separate things out by specifying these files. We use Gitlab CI/CD and Gitlab's backend for state:

build:
  stage: build
  interruptible: true
  script:
    - gitlab-terraform plan -var-file=$TFVARS_DIR/terraform.tfvars
    - gitlab-terraform plan-json

main.tf will include modules or we can break it out once it goes > 100 lines.