Terraform variables within variables

Terraform does not support variables inside a variable. If you want to generate a value based on two or more variables then you can try Terraform locals.

You can define the locals like this:

locals {
  tags = {
    Environment = "${var.EnvironmentName}"
    CostCentre  = "C1234"
    Project     = "TerraformTest"
    Department  = "Systems"
  }
}

And then you can access them using local.tags:

resource “azurerm_resource_group” “TestAppRG” {
  name     = “EUW-RGs-${var.EnvShortName}”
  location = “${var.Location}”
  tags     = “${local.tags}”
}

Leave a Comment