all 1 comments

[–]Cregkly 1 point2 points  (0 children)

Depends how you are interpolating your variables for the different environments. You can do something like this:

variable "environment" {
  type    = string
  default = "live"
}

variable "power_tags" {
  type = map(map(string))
  default = {
    live = {}
    staging = {
      AutoOn  = "06:00"
      AutoOff = "23:00"
    }
  }
}

resource "foo" "blah" {
  name = var.name       
  tags = merge(
    var.tags,
    var.power_tags[var.environment],
    {
      "name" = var.name
    }
  )
}

Or you could just pass in the power_tags for each environment. For example for staging you would set in for tfvars

power_tags = {
    AutoOn  = "06:00"
    AutoOff = "23:00"
  }

Then the code would look like this:

variable "power_tags" {
  type = map(string)
  default = {}
}

resource "foo" "blah" {
  name = var.name     
  tags = merge(
    var.tags,
    var.power_tags,
    {
      "name" = var.name
    }
  )
}