Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module error on duplicate NSG names #1

Open
cliv opened this issue Apr 2, 2020 · 0 comments
Open

Module error on duplicate NSG names #1

cliv opened this issue Apr 2, 2020 · 0 comments

Comments

@cliv
Copy link

cliv commented Apr 2, 2020

If you cut and past this module to create multiple sets of network security policies and don't change the key name for your NSGs, the module will create both NSGs, then crash on any subsequent runs.

This TF should reproduce the error:

module "test1" {
  source = "github.com/oracle-terraform-modules/terraform-oci-tdf-network-security?ref=v0.9.7"

  default_compartment_id = oci_identity_compartment.this.id
  vcn_id                 = oci_core_vcn.this.id

  security_lists = {}
  nsgs = {
    test = {
       ....Trimmed for brevity, but the content here doesn't matter as long as it's valid...
     }
  }
}

module "test2" {
  source = "github.com/oracle-terraform-modules/terraform-oci-tdf-network-security?ref=v0.9.7"

  default_compartment_id = oci_identity_compartment.this.id
  vcn_id                 = oci_core_vcn.this.id

  security_lists = {}
  nsgs = {
    test = {
       ....Trimmed for brevity, but the content here doesn't matter as long as it's valid...
     }
  }
}

you can terraform apply this with no errors, but on subsequent runs, you get the following:

Error: Duplicate object key

  on .terraform/modules/test1/main_nsg.tf line 20, in locals:
  20:   remote_nsg_ids        = { for i in data.oci_core_network_security_groups.this.network_security_groups : i.display_name => i.id }
    |----------------
    | i.display_name is "test"

Two different items produced the key "test" in this 'for' expression. If
duplicates are expected, use the ellipsis (...) after the value expression to
enable grouping by key.


Error: Duplicate object key

  on .terraform/modules/test1/main_nsg.tf line 20, in locals:
  20:   remote_nsg_ids        = { for i in data.oci_core_network_security_groups.this.network_security_groups : i.display_name => i.id }
    |----------------
    | i.display_name is "test"

Two different items produced the key "test" in this 'for' expression. If
duplicates are expected, use the ellipsis (...) after the value expression to
enable grouping by key.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant