Skip to content

Commit 0f3024e

Browse files
Promoted labelFingerprint field to GA (#11504) (#8008)
[upstream:cec6d62e04abfb41a334e8b07d481e3e3076abde] Signed-off-by: Modular Magician <[email protected]>
1 parent 9cadd5f commit 0f3024e

File tree

4 files changed

+113
-1
lines changed

4 files changed

+113
-1
lines changed

.changelog/11504.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
```release-note:enhancement
2+
compute: added `label_fingerprint` field to `google_compute_global_address` resource (ga)
3+
```
4+
```release-note:bug
5+
compute: fixed bug where the `labels` field could not be updated on `google_compute_global_address` (ga)
6+
```

google-beta/acctest/resource_test_utils.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,40 @@
33
package acctest
44

55
import (
6+
"context"
7+
"errors"
68
"fmt"
9+
"slices"
710
"testing"
811
"time"
912

13+
tfjson "github.com/hashicorp/terraform-json"
1014
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
15+
"github.com/hashicorp/terraform-plugin-testing/plancheck"
1116
"github.com/hashicorp/terraform-plugin-testing/terraform"
1217
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
1318
)
1419

1520
// General test utils
1621

22+
var _ plancheck.PlanCheck = expectNoDelete{}
23+
24+
type expectNoDelete struct{}
25+
26+
func (e expectNoDelete) CheckPlan(ctx context.Context, req plancheck.CheckPlanRequest, resp *plancheck.CheckPlanResponse) {
27+
var result error
28+
for _, rc := range req.Plan.ResourceChanges {
29+
if slices.Contains(rc.Change.Actions, tfjson.ActionDelete) {
30+
result = errors.Join(result, fmt.Errorf("expected no deletion of resources, but %s has planned deletion", rc.Address))
31+
}
32+
}
33+
resp.Error = result
34+
}
35+
36+
func ExpectNoDelete() plancheck.PlanCheck {
37+
return expectNoDelete{}
38+
}
39+
1740
// TestExtractResourceAttr navigates a test's state to find the specified resource (or data source) attribute and makes the value
1841
// accessible via the attributeValue string pointer.
1942
func TestExtractResourceAttr(resourceName string, attributeName string, attributeValue *string) resource.TestCheckFunc {

google-beta/services/compute/resource_compute_global_address_test.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,48 @@ import (
88
"testing"
99

1010
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
11+
"github.com/hashicorp/terraform-plugin-testing/plancheck"
1112
)
1213

14+
func TestAccComputeGlobalAddress_update(t *testing.T) {
15+
t.Parallel()
16+
17+
context := map[string]interface{}{
18+
"random_suffix": acctest.RandString(t, 10),
19+
}
20+
21+
acctest.VcrTest(t, resource.TestCase{
22+
PreCheck: func() { acctest.AccTestPreCheck(t) },
23+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
24+
CheckDestroy: testAccCheckComputeGlobalAddressDestroyProducer(t),
25+
Steps: []resource.TestStep{
26+
{
27+
Config: testAccComputeGlobalAddress_update1(context),
28+
},
29+
{
30+
ResourceName: "google_compute_global_address.foobar",
31+
ImportState: true,
32+
ImportStateVerify: true,
33+
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
34+
},
35+
{
36+
Config: testAccComputeGlobalAddress_update2(context),
37+
ConfigPlanChecks: resource.ConfigPlanChecks{
38+
PreApply: []plancheck.PlanCheck{
39+
acctest.ExpectNoDelete(),
40+
},
41+
},
42+
},
43+
{
44+
ResourceName: "google_compute_global_address.foobar",
45+
ImportState: true,
46+
ImportStateVerify: true,
47+
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
48+
},
49+
},
50+
})
51+
}
52+
1353
func TestAccComputeGlobalAddress_ipv6(t *testing.T) {
1454
t.Parallel()
1555

@@ -76,3 +116,47 @@ resource "google_compute_global_address" "foobar" {
76116
}
77117
`, networkName, addressName)
78118
}
119+
120+
func testAccComputeGlobalAddress_update1(context map[string]interface{}) string {
121+
return acctest.Nprintf(`
122+
resource "google_compute_network" "foobar" {
123+
name = "tf-test-address-%{random_suffix}"
124+
}
125+
126+
resource "google_compute_global_address" "foobar" {
127+
address = "172.20.181.0"
128+
description = "Description"
129+
name = "tf-test-address-%{random_suffix}"
130+
labels = {
131+
foo = "bar"
132+
}
133+
ip_version = "IPV4"
134+
prefix_length = 24
135+
address_type = "INTERNAL"
136+
purpose = "VPC_PEERING"
137+
network = google_compute_network.foobar.self_link
138+
}
139+
`, context)
140+
}
141+
142+
func testAccComputeGlobalAddress_update2(context map[string]interface{}) string {
143+
return acctest.Nprintf(`
144+
resource "google_compute_network" "foobar" {
145+
name = "tf-test-address-%{random_suffix}"
146+
}
147+
148+
resource "google_compute_global_address" "foobar" {
149+
address = "172.20.181.0"
150+
description = "Description"
151+
name = "tf-test-address-%{random_suffix}"
152+
labels = {
153+
foo = "baz"
154+
}
155+
ip_version = "IPV4"
156+
prefix_length = 24
157+
address_type = "INTERNAL"
158+
purpose = "VPC_PEERING"
159+
network = google_compute_network.foobar.self_link
160+
}
161+
`, context)
162+
}

website/docs/r/compute_global_address.html.markdown

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ In addition to the arguments listed above, the following computed attributes are
150150
Creation timestamp in RFC3339 text format.
151151

152152
* `label_fingerprint` -
153-
([Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
154153
The fingerprint used for optimistic locking of this resource. Used
155154
internally during updates.
156155

0 commit comments

Comments
 (0)