title: Terraform - Copy AWS SSM Parameters
body: <p>longtime lurker first time poster</p>
  <p>Looking for some guidance from you all. I'm trying to replicate the aws command to essentially get the parameters (ssm get-parameters-by-path) then loop through the parameters and get them
  then loop through and put them into a new parameter (ssm put-parameter)</p>
  <p>I understand there's a for loop expression in TF but for the life of me I can't put together how I would achieve this.
  so thanks to the wonderful breakdown below, I've gotten closer! But have this one issue.  Code below:</p>
  <pre><code>provider &quot;aws&quot; {
    region = &quot;us-east-1&quot;
  }
  
  
  data &quot;aws_ssm_parameters_by_path&quot; &quot;parameters&quot; {
    path = &quot;/${var.old_env}&quot;
    recursive = true
  }
  
  output &quot;old_params_by_path&quot; {
    value = data.aws_ssm_parameters_by_path.parameters
    sensitive = true
  }
  
  locals {
    names = toset(data.aws_ssm_parameters_by_path.parameters.names)
  }
  
  data &quot;aws_ssm_parameter&quot; &quot;old_param_name&quot; {
    for_each = local.names
    name = each.key
  }
  
  output &quot;old_params_names&quot; {
    value = data.aws_ssm_parameter.old_param_name
    sensitive = true
  }
  
  resource &quot;aws_ssm_parameter&quot; &quot;new_params&quot; {
    for_each = local.names
    name = replace(data.aws_ssm_parameter.old_param_name[each.key].name, var.old_env, var.new_env)
    type = data.aws_ssm_parameter.old_param_name[each.key].type
    value = data.aws_ssm_parameter.old_param_name[each.key].value
  }
  </code></pre>
  <p>I have another file like how the helpful poster mentioned and created the initial dataset.  But what's interesting is that after you create the set after the second set, it overwrites the first set!  The idea is that I would be able to tell terraform, I have this current set of SSM parameters and I want you to copy that info (values, type) and create a brand new set of parameters (and not destroy anything that's already there).</p>
  <p>Any and all help would be appreciated!</p>