Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

371
Views
Creating dynamic resources with Terraform for_each

I would like to create AWS SSM Parameters using Terraform, with the parameters being passed in as input variables.

I see there is a for_each feature, but how can this be applied to top level properties within a terraform resource? From the documentation, the use of for_each appears to be restricted to not work on top level properties of a resource, am I misunderstanding?

This is what I am trying to accomplish:

main.tf

resource "aws_ssm_parameter" "ssm_parameters" {
  for_each = var.params
  content {
      name = name.value
      type  = "String"
      overwrite = true
      value = paramValue.value

      tags = var.tags 
      lifecycle {
        ignore_changes = [
          tags,
          value
        ]
      }
  }  
}

variables.tf

variable "params" {
  default = [
    {
      name   = "albUrl"
      paramValue = "testa"
    },
    {
      name   = "rdsUrl1"
      paramValue = "testb"
    },
    {
      name   = "rdsUrl2"
      valparamValueue = "testc"
    },
  ]
}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can use for each, but you need to modify its syntax and fix syntax in your var.params:

variable "params" {
  default = [
    {
      name   = "albUrl"
      paramValue = "testa"
    },
    {
      name   = "rdsUrl1"
      paramValue = "testb"
    },
    {
      name   = "rdsUrl2"
      paramValue = "testc"
    },
  ]
}

Then to use for each, and create 3 ssm parameters:

resource "aws_ssm_parameter" "ssm_parameters" {

  for_each = {for v in var.params: v.name => v.paramValue}
  
  type  = "String"

  name = each.key
  value = each.value
  
  overwrite = true
}

In the above you have to project your list(map) to a map as it is required for for_each.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!