Skip to content

Commit 13b9f0b

Browse files
Adds params.resource_manager_tags to google_compute_region_commitment so IAM resource manager tags can be bound at commitment creation. The field is input-only and ForceNew, matching the existing pattern on google_compute_network (#14119) and other Compute resources.
The acceptance test has no `CheckDestroy` because `RegionCommitment` is `exclude_delete: true`; recording it creates a real, non-deletable multi-year commitment, so it should be recorded once on a sacrificial project and replayed in CI. ```release-note:enhancement compute: added `params.resource_manager_tags` field to `google_compute_region_commitment` resource ```
1 parent 4a20a4d commit 13b9f0b

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

mmv1/products/compute/RegionCommitment.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,18 @@ properties:
203203
description: |
204204
Specifies the already existing reservations to attach to the Commitment.
205205
default_from_api: true
206+
- name: 'params'
207+
type: NestedObject
208+
ignore_read: true
209+
immutable: true
210+
description: |
211+
Additional params passed with the request, but not persisted as part of resource payload
212+
properties:
213+
- name: 'resourceManagerTags'
214+
type: KeyValuePairs
215+
description: |
216+
Resource manager tags to be bound to the commitment. Tag keys and values have the
217+
same definition as resource manager tags. Keys must be in the format tagKeys/{tag_key_id},
218+
and values are in the format tagValues/456.
219+
api_name: resourceManagerTags
220+
ignore_read: true
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package compute_test
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
8+
"github.com/hashicorp/terraform-provider-google/google/acctest"
9+
"github.com/hashicorp/terraform-provider-google/google/envvar"
10+
)
11+
12+
// WARNING: RECORDING this test creates a real, non-deletable multi-year commitment
13+
// (RegionCommitment has exclude_delete: true). Use VCR REPLAYING in CI; only RECORD
14+
// on a sacrificial project where orphaned commitments are acceptable.
15+
func TestAccComputeRegionCommitment_resourceManagerTags(t *testing.T) {
16+
17+
t.Parallel()
18+
19+
org := envvar.GetTestOrgFromEnv(t)
20+
suffixName := acctest.RandString(t, 10)
21+
tagKeyResult := acctest.BootstrapSharedTestTagKeyDetails(t, "crm-region-commitment-tagkey", "organizations/"+org, make(map[string]interface{}))
22+
sharedTagkey, _ := tagKeyResult["shared_tag_key"]
23+
tagValueResult := acctest.BootstrapSharedTestTagValueDetails(t, "crm-region-commitment-tagvalue", sharedTagkey, org)
24+
25+
context := map[string]interface{}{
26+
"commitment_name": fmt.Sprintf("tf-test-commitment-rmt-%s", suffixName),
27+
"tag_key_id": tagKeyResult["name"],
28+
"tag_value_id": tagValueResult["name"],
29+
}
30+
31+
acctest.VcrTest(t, resource.TestCase{
32+
PreCheck: func() { acctest.AccTestPreCheck(t) },
33+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
34+
// No CheckDestroy: RegionCommitment has exclude_delete: true.
35+
Steps: []resource.TestStep{
36+
{
37+
Config: testAccComputeRegionCommitment_resourceManagerTags(context),
38+
},
39+
},
40+
})
41+
}
42+
43+
func testAccComputeRegionCommitment_resourceManagerTags(context map[string]interface{}) string {
44+
return acctest.Nprintf(`
45+
resource "google_compute_region_commitment" "foobar" {
46+
name = "%{commitment_name}"
47+
plan = "TWELVE_MONTH"
48+
resources {
49+
type = "VCPU"
50+
amount = "1"
51+
}
52+
resources {
53+
type = "MEMORY"
54+
amount = "1"
55+
}
56+
params {
57+
resource_manager_tags = {
58+
"%{tag_key_id}" = "%{tag_value_id}"
59+
}
60+
}
61+
}
62+
`, context)
63+
}

0 commit comments

Comments
 (0)