Var to tfvars questions

Hi there,

I am creating simple param store module something like this:

resource "aws_ssm_parameter" "secret" {
  for_each = var.parameters_name_value

  name        = each.key
  description = each.key
  type        = "SecureString"
  value       = each.value

  tags = {
    ManagedBy = "Terraform"
  }
}

variable "parameters_name_value" {
  description = "Declare parameter name as key, and parameter value as a value"
  default = {
  "parameter1"                                    = <<EOT
test=2
test=3
  EOT
  "parameter2"            = <<EOT
test=2
test=3
      EOT
  }
}

Like this the module is working as expected but I don’t have idea how to refactor this code in order to use -var-file=something.tfvars to apply different params and values for different environments.
Do you have any suggestions on how to use tfvars with this configuration instead of default values.

Thank you very much in advance!

#something.tfvars

parameters_name_value = {
“parameter1” = “test=2\ntest=3”
“parameter2” = “test=2\ntest=3”
}

Or you could also do this, but it’s kind of hard to read:

parameters_name_value = {
“parameter1” = <<EOT
test=2
test=3
EOT
“parameter2” = <<EOT
test=2
test=3
EOT
}

Thanks for the suggestion. Actually I manage to find a way. I am not sure that it’s very clean but its working :slight_smile:

resource "aws_ssm_parameter" "bla" {
  for_each = { for x in var.ssm_params : x.name => x }

  name      = each.value.name
  type      = "SecureString"
  value     = each.value.value
  overwrite = true
}

variable "ssm_params" {
  type = map(object({
    name  = string
    value = string
  }))
  default = {
    name : {
      name  = "pesho"
      value = "blaa2"
    },
    blaa : {
      name  = "gosho"
      value = "blaa1"
    }
  }
}


//When you call the module use TF-VAR example
//ssm_params = {
//  "param1" : {
//    "name" : "param1",
//    "value" : <<EOT
//valueA=1
//valueB=2
//valueC=3
//   EOT
//  },
//  "param2" : {
//    "name" : "param2",
//    "value" : <<EOT
//valueA=1
//valueB=2
//valueC=3
//   EOT
//  }
//}