'Terraform- How to iterate through a list of maps without making duplicates?

  • I have a list that contains the names (strings) of the secret scopes that I want to create

Example:

ss-list = ["name1", "name2"]
  • I have a map that contains 2 objects that are applied to each name in my ss-list. Example:
 keyvault-map = {

    kv1 = {
      id = "abc",
      dns-name = "123"
    },

    kv2 = {
      id = "def",
      dns-name = "456"
    }
  }     
  • So for each item in ss-list I need to pull the 2 items inside the map and append to make 1 list.

  • The end result list that I desire to be returned is...

[

  {
    "keyvault-id" = "abc"

    "keyvault-uri" = "123"

    "name" = "name1"
  },

  {

    "keyvault-id" = "def"

    "keyvault-uri" = "456"

    "name" = "name2"

  }

]
  • I'm looking for how I can iterate through this list and map and return my desired list (with no duplicates).


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source