2

假设我有一张这样的地图:

variable "test_parameters" {
type = map
default = {
"A" = "subnet-73e35d3e",
"B" = "subnet-7e00d503",
"C" = "subnet-d9d446b2",
}

}

什么是 terraform-code

  1. 将地图的值存储在单个aws_ssm_parameter 中?
  2. 从参数中获取单个值,例如: B = subnet-7e00d503 或 B:subnet-7e00d503 ?

非常感谢您的帮助;)

4

1 回答 1

1

您可以将其存储为 json,然后将 json 取回。

resource "aws_ssm_parameter" "foo" {
  name  = "myparam"
  type  = "String"
  value = jsonencode(var.test_parameters)
}

要阅读它:

data "aws_ssm_parameter" "foo" {
  name = "myparam"
}

# to use 

locals {
  myparam_values = jsondecode(data.aws_ssm_parameter.foo.value)
}
于 2021-05-03T11:21:31.673 回答