Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terraform: How to store a map in a single ssm-parameter and get back a value pair?

let's assume i have a map like this:

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

}

What is the terraform-code

  1. to store the values of the map in a single aws_ssm_parameter ?
  2. get a single value from the parameter like: B = subnet-7e00d503 or B:subnet-7e00d503 ?

Many thanks for help ;)

like image 941
RELiABLE Avatar asked Oct 16 '25 20:10

RELiABLE


1 Answers

You can store it as json, and then get json back.

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

To read it:

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

# to use 

locals {
  myparam_values = jsondecode(data.aws_ssm_parameter.foo.value)
}
like image 139
Marcin Avatar answered Oct 19 '25 13:10

Marcin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!