oci-landing-zones / terraform-oci-modules-networking

This repository contains Terraform OCI (Oracle Cloud Infrastructure) modules for networking related resources that help customers align their OCI implementations with the CIS (Center for Internet Security) OCI Foundations Benchmark recommendations.
Universal Permissive License v1.0
15 stars 5 forks source link

Bug when assigning `oci_core_cross_connect` to a `oci_core_cross_connect_group` #37

Open brodster2 opened 3 months ago

brodster2 commented 3 months ago

Hello 👋 We are using the oracle oci-landing-zones/terraform-oci-modules-orchestrator to setup our OCI LZ. We've run into a problem when trying to create cross connects as part of cross connect groups, an example of our configuration:

...
"cross_connect_groups": {
  "FC-UK3-Equinix-LD6": {
    "compartment_id": "CMP-LZP-NETWORK-KEY",
    "cross_connects": {
      "FC-UK3-Equinix-LD6-1": {
        "compartment_id": "CMP-LZP-NETWORK-KEY",
        "location_name": "Equinix LD6",
        "port_speed_shape_name": "10 Gbps"
      }
    }
  }
}
...

This gets sent to the networking module https://github.com/oci-landing-zones/terraform-oci-modules-orchestrator/blob/17f621d5efb08577cd105859fbf05d4cdeac9376/networking.tf#L8

We have no problem when creating just the cross connect groups, the issue comes when the oci_core_cross_connect is created and assigned to a oci_core_cross_connect_group here which results in the error:

│ Error: Invalid index
│ 
│   on .terraform/modules/oci_lz_network/cross-connects.tf line 54, in resource "oci_core_cross_connect" "these":
│   54:   cross_connect_group_id                       = oci_core_cross_connect_group.these[each.key].id
│     ├────────────────
│     │ each.key is "FC-UK3-Equinix-LD6-1"
│     │ oci_core_cross_connect_group.these is object with 1 attributes

Which makes sense, because the cross connect group attribute will be oci_core_cross_connect_group.these[FC-UK3-Equinix-LD6] but the code on line 54 of cross-connects.tf is looking for oci_core_cross_connect_group.these[FC-UK3-Equinix-LD6-1] which doesn't exist because that is the unique key of the cross connect. I think line 54 needs to be updated from:

cross_connect_group_id                       = oci_core_cross_connect_group.these[each.key].id

to:

cross_connect_group_id                       = oci_core_cross_connect_group.these[each.value.cross_connect_group_id].id
andrecorreaneto commented 3 months ago

Hello brodster2, thanks for reporting. I agree there's a bug and we'll have this fixed in the next release.

andrecorreaneto commented 3 months ago

Hi brodster2, can you please test https://github.com/oci-landing-zones/terraform-oci-modules-orchestrator/tree/release-2.0.4? It has the fix. In a few days we'll be merging this candidate release into main.

andrecorreaneto commented 2 months ago

Fix available in v0.6.9.

brodster2 commented 2 months ago

Hi brodster2, can you please test https://github.com/oci-landing-zones/terraform-oci-modules-orchestrator/tree/release-2.0.4? It has the fix. In a few days we'll be merging this candidate release into main.

Hi @andrecorreaneto, thanks for the quick response, we attempted to test that branch but ran across this error:

│ Error: Experiment has concluded
│ 
│   on providers.tf line 58, in terraform:
│   58:   experiments = [module_variable_optional_attrs]
│ 
│ Experiment "module_variable_optional_attrs" is no longer available. The
│ final feature corresponding to this experiment differs from the
│ experimental form and is available in the Terraform language from Terraform
│ v1.3.0 onwards.

since that branch requires terraform versions >=1.3.0 but still has the module_variable_optional_attrs experiment set. We tried with Terraform versions 1.3.x and 1.5.x

brodster2 commented 2 months ago

https://github.com/hashicorp/terraform/issues/31931 has some details on it

andrecorreaneto commented 2 months ago

Please retry, just pushed the fix. Sorry about that.

brodster2 commented 2 months ago

Hi @andrecorreaneto, we had to create the cross connects manually to get the LOAs to our provider. But using the branch https://github.com/oci-landing-zones/terraform-oci-modules-orchestrator/tree/release-2.0.4 we had no issues importing them into state with no changes shown. So I'm happy to call this issue closed. Thanks for your quick fix.