местные жители не работают внутри переменных в Terraform - PullRequest
0 голосов
/ 15 марта 2020
locals {
  cool_style = {
    palette = "cool"
    type    = "solid"
    width   = "normal"
  }
  orange_style = {
    palette = "orange"
    type    = "solid"
    width   = "normal"
  }
}

variable "query_timeseries" {
  default = [
    {
      q     = "avg:xx.xxxx{xxx:xx}"
      type  = "bars"
      style = local.cool_style
    },
    {
      q     = "avg:xx.xxxx{xxx:xx}"
      type  = "bars"
      style = local.orange_style
    }
}

Невозможно повторно использовать объявленную переменную в файле .tf

enter image description here

Что мне нужно?:

Мне нужно объявить переменную, вставив в нее существующую переменную

1 Ответ

0 голосов
/ 30 марта 2020

Преобразование variable в local, чтобы оно могло использовать другие локальные переменные, является правильным решением. Используя terraform 0.12.x, следующие действия ожидаются, как это видно из terraform apply.

locals {
  cool_style = {
    palette = "cool"
    type    = "solid"
    width   = "normal"
  }
  orange_style = {
    palette = "orange"
    type    = "solid"
    width   = "normal"
  }
  query_timeseries = [
    {
      q     = "avg:xx.xxxx{xxx:xx}"
      type  = "bars"
      style = local.cool_style
    },
    {
      q     = "avg:xx.xxxx{xxx:xx}"
      type  = "bars"
      style = local.orange_style
    }
  ]
}

output "query_timeseries" {
  value = local.query_timeseries
}
$ terraform init
$ terraform apply
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

query_timeseries = [
  {
    "q" = "avg:xx.xxxx{xxx:xx}"
    "style" = {
      "palette" = "cool"
      "type" = "solid"
      "width" = "normal"
    }
    "type" = "bars"
  },
  {
    "q" = "avg:xx.xxxx{xxx:xx}"
    "style" = {
      "palette" = "orange"
      "type" = "solid"
      "width" = "normal"
    }
    "type" = "bars"
  },
]
...