From 74483d6cc29cbe29f2c710efb4caa93f102d8324 Mon Sep 17 00:00:00 2001 From: harshithpatte-g Date: Tue, 17 Sep 2024 23:57:58 +0530 Subject: [PATCH] Fix interconnect immutability issue causing macsec failure (#11700) --- mmv1/products/compute/Interconnect.yaml | 4 +- ...source_compute_interconnect_macsec_test.go | 89 +++++++++++++++++++ 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 mmv1/third_party/terraform/services/compute/resource_compute_interconnect_macsec_test.go diff --git a/mmv1/products/compute/Interconnect.yaml b/mmv1/products/compute/Interconnect.yaml index 809df72e6e80..234adccbc2f0 100644 --- a/mmv1/products/compute/Interconnect.yaml +++ b/mmv1/products/compute/Interconnect.yaml @@ -23,7 +23,7 @@ references: !ruby/object:Api::Resource::ReferenceLinks api: 'https://cloud.google.com/compute/docs/reference/rest/v1/interconnects' base_url: 'projects/{{project}}/global/interconnects' self_link: 'projects/{{project}}/global/interconnects/{{name}}' -immutable: true +update_verb: :PATCH async: !ruby/object:Api::OpAsync operation: !ruby/object:Api::OpAsync::Operation kind: 'compute#operation' @@ -366,11 +366,13 @@ properties: MACsec enablement fails if the MACsec object is not specified. - !ruby/object:Api::Type::String name: 'remoteLocation' + immutable: true description: | Indicates that this is a Cross-Cloud Interconnect. This field specifies the location outside of Google's network that the interconnect is connected to. - !ruby/object:Api::Type::Array name: 'requestedFeatures' + immutable: true description: | interconnects.list of features requested for this Interconnect connection. Options: IF_MACSEC ( If specified then the connection is created on MACsec capable hardware ports. If not diff --git a/mmv1/third_party/terraform/services/compute/resource_compute_interconnect_macsec_test.go b/mmv1/third_party/terraform/services/compute/resource_compute_interconnect_macsec_test.go new file mode 100644 index 000000000000..e068b37898cf --- /dev/null +++ b/mmv1/third_party/terraform/services/compute/resource_compute_interconnect_macsec_test.go @@ -0,0 +1,89 @@ +package compute_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + + "github.com/hashicorp/terraform-provider-google/google/acctest" +) + +func TestAccComputeInterconnect_computeInterconnectMacsecTest(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(t, 10), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckComputeInterconnectDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccComputeInterconnect_computeInterconnectCreate(context), + }, + { + ResourceName: "google_compute_interconnect.example-interconnect", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"labels", "location", "terraform_labels"}, + }, + { + Config: testAccComputeInterconnect_computeInterconnectEnableMacsec(context), + }, + { + ResourceName: "google_compute_interconnect.example-interconnect", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"labels", "location", "terraform_labels"}, + }, + }, + }) +} + +func testAccComputeInterconnect_computeInterconnectCreate(context map[string]interface{}) string { + return acctest.Nprintf(` +data "google_project" "project" {} + +resource "google_compute_interconnect" "example-interconnect" { + name = "tf-test-example-interconnect%{random_suffix}" + customer_name = "internal_customer" # Special customer only available for Google testing. + interconnect_type = "DEDICATED" + link_type = "LINK_TYPE_ETHERNET_100G_LR" + location = "https://www.googleapis.com/compute/v1/projects/${data.google_project.project.name}/global/interconnectLocations/z2z-us-east4-zone1-lciadl-a" # Special location only available for Google testing. + requested_link_count = 1 + admin_enabled = true + description = "example description" + macsec_enabled = false + noc_contact_email = "user@example.com" + requested_features = ["IF_MACSEC"] +} +`, context) +} + +func testAccComputeInterconnect_computeInterconnectEnableMacsec(context map[string]interface{}) string { + return acctest.Nprintf(` +data "google_project" "project" {} + +resource "google_compute_interconnect" "example-interconnect" { + name = "tf-test-example-interconnect%{random_suffix}" + customer_name = "internal_customer" # Special customer only available for Google testing. + interconnect_type = "DEDICATED" + link_type = "LINK_TYPE_ETHERNET_100G_LR" + location = "https://www.googleapis.com/compute/v1/projects/${data.google_project.project.name}/global/interconnectLocations/z2z-us-east4-zone1-lciadl-a" # Special location only available for Google testing. + requested_link_count = 1 + admin_enabled = true + description = "example description" + macsec_enabled = true + noc_contact_email = "user@example.com" + requested_features = ["IF_MACSEC"] + macsec { + pre_shared_keys { + name = "test-key" + start_time = "2023-07-01T21:00:01.000Z" + } + } +} +`, context) +}