如何在 terraform 变量中传递 json?

csa*_*aju 1 terraform aws-ssm

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

resource "aws_ssm_parameter" "secret" {
  name        = "/something/env"
  description = "This is a something values"
  type        = "SecureString"
  value       = "test"
  
  tags = {
    environment = "production"
  }
} 
Run Code Online (Sandbox Code Playgroud)

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

这样AWS参数存储值就会像

{
   "key": "value"
}
Run Code Online (Sandbox Code Playgroud)

Erv*_*gyi 5

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

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

  tags = {
    environment = "production"
  }
} 
Run Code Online (Sandbox Code Playgroud)