From c5cd53864b3d5f8dbf18a03bc7066993e3276aa8 Mon Sep 17 00:00:00 2001 From: "Stephen Lewis (Burrows)" Date: Tue, 14 Jan 2025 11:50:01 -0800 Subject: [PATCH] Fixed TestAccNetworkServicesGateway_update (#12749) --- mmv1/products/networkservices/Gateway.yaml | 3 +-- .../terraform/pre_update/network_services_gateway.go.tmpl | 5 ----- .../update_encoder/network_services_gateway.go.tmpl | 8 ++++++++ .../resource_network_services_gateway_test.go | 8 +++++++- 4 files changed, 16 insertions(+), 8 deletions(-) delete mode 100644 mmv1/templates/terraform/pre_update/network_services_gateway.go.tmpl create mode 100644 mmv1/templates/terraform/update_encoder/network_services_gateway.go.tmpl diff --git a/mmv1/products/networkservices/Gateway.yaml b/mmv1/products/networkservices/Gateway.yaml index 20b788a5cebf..725d48d30dfe 100644 --- a/mmv1/products/networkservices/Gateway.yaml +++ b/mmv1/products/networkservices/Gateway.yaml @@ -48,7 +48,7 @@ async: custom_code: constants: 'templates/terraform/constants/network_services_gateway.go.tmpl' post_delete: 'templates/terraform/post_delete/network_services_gateway.go.tmpl' - pre_update: 'templates/terraform/pre_update/network_services_gateway.go.tmpl' + update_encoder: 'templates/terraform/update_encoder/network_services_gateway.go.tmpl' examples: - name: 'network_services_gateway_basic' primary_resource_id: 'default' @@ -147,7 +147,6 @@ properties: The proxy binds to the specified ports. Gateways of type 'SECURE_WEB_GATEWAY' are limited to 1 port. Gateways of type 'OPEN_MESH' listen on 0.0.0.0 and support multiple ports. required: true - immutable: true item_type: type: Integer - name: 'scope' diff --git a/mmv1/templates/terraform/pre_update/network_services_gateway.go.tmpl b/mmv1/templates/terraform/pre_update/network_services_gateway.go.tmpl deleted file mode 100644 index 3f976f267b19..000000000000 --- a/mmv1/templates/terraform/pre_update/network_services_gateway.go.tmpl +++ /dev/null @@ -1,5 +0,0 @@ -if d.Get("type") == "SECURE_WEB_GATEWAY" { - obj["name"] = d.Get("name") - obj["type"] = d.Get("type") - obj["routingMode"] = d.Get("routingMode") -} \ No newline at end of file diff --git a/mmv1/templates/terraform/update_encoder/network_services_gateway.go.tmpl b/mmv1/templates/terraform/update_encoder/network_services_gateway.go.tmpl new file mode 100644 index 000000000000..b867343f9c33 --- /dev/null +++ b/mmv1/templates/terraform/update_encoder/network_services_gateway.go.tmpl @@ -0,0 +1,8 @@ +// Always force-send some attributes even if they were not modified. This works around extra API-side requirements. +obj["scope"] = d.Get("scope") +if d.Get("type") == "SECURE_WEB_GATEWAY" { + obj["name"] = d.Get("name") + obj["type"] = d.Get("type") + obj["routingMode"] = d.Get("routingMode") +} +return obj, nil \ No newline at end of file diff --git a/mmv1/third_party/terraform/services/networkservices/resource_network_services_gateway_test.go b/mmv1/third_party/terraform/services/networkservices/resource_network_services_gateway_test.go index 6f20ec7a7dae..d5478d2a0542 100644 --- a/mmv1/third_party/terraform/services/networkservices/resource_network_services_gateway_test.go +++ b/mmv1/third_party/terraform/services/networkservices/resource_network_services_gateway_test.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/plancheck" ) func TestAccNetworkServicesGateway_update(t *testing.T) { @@ -30,6 +31,11 @@ func TestAccNetworkServicesGateway_update(t *testing.T) { }, { Config: testAccNetworkServicesGateway_update(gatewayName), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction("google_network_services_gateway.foobar", plancheck.ResourceActionUpdate), + }, + }, }, { ResourceName: "google_network_services_gateway.foobar", @@ -59,7 +65,7 @@ resource "google_network_services_gateway" "foobar" { name = "%s" scope = "default-scope-update" type = "OPEN_MESH" - ports = [443] + ports = [1000] description = "update description" labels = { foo = "bar"