Search code examples
terraformaws-ssm

How to pass json inside the terraform variable?


I am trying to create an AWS parameter store via terraform that can also pass default values with the JSON format. Here is a sample of the code.

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

Instead of passing out a single value as a "test" from value, how can I pass the json one inside value one.

So that AWS parameter store value will be like

{
   "key": "value"
}

Solution

  • I think you are looking for jsonencode, which could be used as such:

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