From cec6d62e04abfb41a334e8b07d481e3e3076abde Mon Sep 17 00:00:00 2001 From: "Stephen Lewis (Burrows)" Date: Wed, 21 Aug 2024 09:51:13 -0700 Subject: [PATCH] Promoted labelFingerprint field to GA (#11504) --- mmv1/products/compute/GlobalAddress.yaml | 1 - .../terraform/acctest/resource_test_utils.go | 23 +++++ ...esource_compute_global_address_test.go.erb | 84 +++++++++++++++++++ 3 files changed, 107 insertions(+), 1 deletion(-) diff --git a/mmv1/products/compute/GlobalAddress.yaml b/mmv1/products/compute/GlobalAddress.yaml index 0e71cbac5890..6ee244e5bb53 100644 --- a/mmv1/products/compute/GlobalAddress.yaml +++ b/mmv1/products/compute/GlobalAddress.yaml @@ -100,7 +100,6 @@ properties: internally during updates. update_url: 'projects/{{project}}/global/addresses/{{name}}/setLabels' update_verb: :POST - min_version: beta - !ruby/object:Api::Type::Enum name: 'ipVersion' description: | diff --git a/mmv1/third_party/terraform/acctest/resource_test_utils.go b/mmv1/third_party/terraform/acctest/resource_test_utils.go index 58371fd89cb5..dba6be890954 100644 --- a/mmv1/third_party/terraform/acctest/resource_test_utils.go +++ b/mmv1/third_party/terraform/acctest/resource_test_utils.go @@ -1,17 +1,40 @@ package acctest import ( + "context" + "errors" "fmt" + "slices" "testing" "time" + tfjson "github.com/hashicorp/terraform-json" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/plancheck" "github.com/hashicorp/terraform-plugin-testing/terraform" transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport" ) // General test utils +var _ plancheck.PlanCheck = expectNoDelete{} + +type expectNoDelete struct{} + +func (e expectNoDelete) CheckPlan(ctx context.Context, req plancheck.CheckPlanRequest, resp *plancheck.CheckPlanResponse) { + var result error + for _, rc := range req.Plan.ResourceChanges { + if slices.Contains(rc.Change.Actions, tfjson.ActionDelete) { + result = errors.Join(result, fmt.Errorf("expected no deletion of resources, but %s has planned deletion", rc.Address)) + } + } + resp.Error = result +} + +func ExpectNoDelete() plancheck.PlanCheck { + return expectNoDelete{} +} + // TestExtractResourceAttr navigates a test's state to find the specified resource (or data source) attribute and makes the value // accessible via the attributeValue string pointer. func TestExtractResourceAttr(resourceName string, attributeName string, attributeValue *string) resource.TestCheckFunc { diff --git a/mmv1/third_party/terraform/services/compute/resource_compute_global_address_test.go.erb b/mmv1/third_party/terraform/services/compute/resource_compute_global_address_test.go.erb index d7f2b3fba139..3466e2882f3f 100644 --- a/mmv1/third_party/terraform/services/compute/resource_compute_global_address_test.go.erb +++ b/mmv1/third_party/terraform/services/compute/resource_compute_global_address_test.go.erb @@ -7,8 +7,48 @@ 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 TestAccComputeGlobalAddress_update(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: testAccCheckComputeGlobalAddressDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccComputeGlobalAddress_update1(context), + }, + { + ResourceName: "google_compute_global_address.foobar", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"labels", "terraform_labels"}, + }, + { + Config: testAccComputeGlobalAddress_update2(context), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + acctest.ExpectNoDelete(), + }, + }, + }, + { + ResourceName: "google_compute_global_address.foobar", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"labels", "terraform_labels"}, + }, + }, + }) +} + func TestAccComputeGlobalAddress_ipv6(t *testing.T) { t.Parallel() @@ -75,3 +115,47 @@ resource "google_compute_global_address" "foobar" { } `, networkName, addressName) } + +func testAccComputeGlobalAddress_update1(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_compute_network" "foobar" { + name = "tf-test-address-%{random_suffix}" +} + +resource "google_compute_global_address" "foobar" { + address = "172.20.181.0" + description = "Description" + name = "tf-test-address-%{random_suffix}" + labels = { + foo = "bar" + } + ip_version = "IPV4" + prefix_length = 24 + address_type = "INTERNAL" + purpose = "VPC_PEERING" + network = google_compute_network.foobar.self_link +} +`, context) +} + +func testAccComputeGlobalAddress_update2(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_compute_network" "foobar" { + name = "tf-test-address-%{random_suffix}" +} + +resource "google_compute_global_address" "foobar" { + address = "172.20.181.0" + description = "Description" + name = "tf-test-address-%{random_suffix}" + labels = { + foo = "baz" + } + ip_version = "IPV4" + prefix_length = 24 + address_type = "INTERNAL" + purpose = "VPC_PEERING" + network = google_compute_network.foobar.self_link +} +`, context) +}