Getting Object Name from Vars

Hi ,

I have a set of SSM Parameters , sequenced in package structure as below .

ssm_list = {
"/ssmstore/key1" = {  value = val1 , type = text , description = my param1},
"/ssmstore/key2" = {  value = val2 , type = text , description = my param2}
.
..
..
"/ssmstore/key3" = {  value = val3 , type = text , description = my param2}
Pardon the syntax : Only representation

Am trying to setup a variables (vars )definition using map object .

I would like to retrieve
param_name =
param_value = objectname.value … So on .

Thanks and Regards
GVK

You can define a map variable in your Terraform configuration that corresponds to your ssm_list structure, like this:

variable “ssm_params” {
type = map(object({
value = string
type = string
description = string
}))
default = {
“/ssmstore/key1” = {
value = “val1”
type = “text”
description = “my param1”
}
“/ssmstore/key2” = {
value = “val2”
type = “text”
description = “my param2”
}
“/ssmstore/key3” = {
value = “val3”
type = “text”
description = “my param3”
}
}
}

You can then reference this variable in your Terraform code to retrieve the parameter name and value, like this:

locals {
param_name = [for k, v in var.ssm_params : k]
param_value = [for k, v in var.ssm_params : v.value]
}

This will create two local variables param_name and param_value that contain lists of the parameter names and values, respectively. You can then use these local variables elsewhere in your Terraform code as needed.