如何在 terraform 变量中传递 json?

How to pass json inside the terraform variable?

我正在尝试通过 terraform 创建一个 AWS 参数存储,它也可以使用 JSON 格式传递默认值。这是代码示例。

resource "aws_ssm_parameter" "secret" {
  name        = "/something/env"
  description = "This is a something values"
  type        = "SecureString"
  value       = "test"
  
  tags = {
    environment = "production"
  }
} 

我如何传递值一内的 json 而不是传递单个值作为值的“测试”。

这样 AWS 参数存储值就会像

{
   "key": "value"
}

我认为您正在寻找 jsonencode,可以这样使用:

resource "aws_ssm_parameter" "secret" {
  name        = "/something/env"
  description = "This is a something values"
  type        = "SecureString"
  value = jsonencode({
    "key" : "value"
  })

  tags = {
    environment = "production"
  }
}