Skip to content

Commit

Permalink
Promoted labelFingerprint field to GA (#11504)
Browse files Browse the repository at this point in the history
  • Loading branch information
melinath authored Aug 21, 2024
1 parent 8a8e61c commit cec6d62
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 1 deletion.
1 change: 0 additions & 1 deletion mmv1/products/compute/GlobalAddress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
23 changes: 23 additions & 0 deletions mmv1/third_party/terraform/acctest/resource_test_utils.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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)
}

0 comments on commit cec6d62

Please sign in to comment.