Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promoted labelFingerprint field to GA #11504

Merged
merged 3 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
melinath marked this conversation as resolved.
Show resolved Hide resolved
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)
}
Loading