csaju
csaju

Reputation: 394

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"
}

Upvotes: 1

Views: 8513

Answers (1)

Ervin Szilagyi
Ervin Szilagyi

Reputation: 16775

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"
  }
} 

Upvotes: 5

Related Questions