From e726000864b6753d6c5661fdb4dafc0a7c3bf9f3 Mon Sep 17 00:00:00 2001 From: Harshith Patte Date: Fri, 13 Sep 2024 17:31:57 +0530 Subject: [PATCH 1/2] make immutability granular by removing it on the whole resource --- mmv1/products/compute/Interconnect.yaml | 4 +- ...source_compute_interconnect_macsec_test.go | 90 +++++++++++++++++++ 2 files changed, 93 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..b11ef755b28d --- /dev/null +++ b/mmv1/third_party/terraform/services/compute/resource_compute_interconnect_macsec_test.go @@ -0,0 +1,90 @@ +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" + fail_open = true + } + } +} +`, context) +} From 39cd359dbfcd5552d673872fc822a881125e997a Mon Sep 17 00:00:00 2001 From: Harshith Patte Date: Tue, 17 Sep 2024 22:59:20 +0530 Subject: [PATCH 2/2] fix test --- .../compute/resource_compute_interconnect_macsec_test.go | 1 - 1 file changed, 1 deletion(-) 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 index b11ef755b28d..e068b37898cf 100644 --- 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 @@ -82,7 +82,6 @@ resource "google_compute_interconnect" "example-interconnect" { pre_shared_keys { name = "test-key" start_time = "2023-07-01T21:00:01.000Z" - fail_open = true } } }