Repository: GoogleCloudPlatform/magic-modules
Pull request #13565: Adding tags field to Redis Instances for TagsR2401
Author: login: rajeshgupthar
Labels: name: service/redis-instance
Created: 2025-04-07T12:10:53Z | Merged: 2025-04-14T20:31:29Z

<!--
Complete the self-review checklist to help speed up the review process: https://googlecloudplatform.github.io/magic-modules/contribute/review-pr/

If your PR is still work in progress, please create it in draft mode.

Put a description of what this PR is for here, along with any references to issues that this resolves or contributes to.
For example: Fixes https://github.com/hashicorp/terraform-provider-google/issues/ISSUE_ID
-->
Add tags field to instance resource to allow setting tags on instance resources at creation time.
Part of b/367402264
**Release Note Template for Downstream PRs (will be copied)**

See [Write release notes](https://googlecloudplatform.github.io/magic-modules/contribute/release-notes/) for guidance.

```release-note:enhancement
redis: added `tags` field to `google_redis_instance` resource to allow setting tags for instances at creation time
```



Diff:
diff --git a/mmv1/products/redis/Instance.yaml b/mmv1/products/redis/Instance.yaml
index 419ae6c60bb7..a86b63745bdd 100644
--- a/mmv1/products/redis/Instance.yaml
+++ b/mmv1/products/redis/Instance.yaml
@@ -568,3 +568,11 @@ properties:
       Optional. The KMS key reference that you want to use to encrypt the data at rest for this Redis
       instance. If this is provided, CMEK is enabled.
     immutable: true
+  - name: 'tags'
+    type: KeyValuePairs
+    description: |
+      A map of resource manager tags.
+      Resource manager tag keys and values have the same definition as resource manager tags.
+      Keys must be in the format tagKeys/{tag_key_id}, and values are in the format tagValues/{tag_key_value}.
+    immutable: true
+    ignore_read: true
diff --git a/mmv1/third_party/terraform/services/redis/resource_redis_instance_test.go b/mmv1/third_party/terraform/services/redis/resource_redis_instance_test.go
index 43f53e4ce0e2..d5a0c6d0ae30 100644
--- a/mmv1/third_party/terraform/services/redis/resource_redis_instance_test.go
+++ b/mmv1/third_party/terraform/services/redis/resource_redis_instance_test.go
@@ -461,3 +461,45 @@ resource "google_redis_instance" "test" {
 }
 `, name)
 }
+
+func TestAccRedisInstance_tags(t *testing.T) {
+
+	t.Parallel()
+
+	tagKey := acctest.BootstrapSharedTestTagKey(t, "redis-instances-tagkey")
+	context := map[string]interface{}{
+		"org":           envvar.GetTestOrgFromEnv(t),
+		"tagKey":        tagKey,
+		"tagValue":      acctest.BootstrapSharedTestTagValue(t, "redis-instances-tagvalue", tagKey),
+		"random_suffix": acctest.RandString(t, 10),
+	}
+	acctest.VcrTest(t, resource.TestCase{
+		PreCheck:                 func() { acctest.AccTestPreCheck(t) },
+		ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
+		CheckDestroy:             testAccCheckRedisInstanceDestroyProducer(t),
+		Steps: []resource.TestStep{
+			{
+				Config: testAccRedisInstanceTags(context),
+			},
+			{
+				ResourceName:            "google_redis_instance.test",
+				ImportState:             true,
+				ImportStateVerify:       true,
+				ImportStateVerifyIgnore: []string{"tags"},
+			},
+		},
+	})
+}
+
+func testAccRedisInstanceTags(context map[string]interface{}) string {
+
+	return acctest.Nprintf(`
+	resource "google_redis_instance" "test" {
+	  name = "tf-test-instance-%{random_suffix}"
+	  memory_size_gb = 5
+	  tags = {
+	"%{org}/%{tagKey}" = "%{tagValue}"
+  }
+}
+`, context)
+}


Reviews:
user: login: zli82016
body: The test TestAccRedisInstance_tags failed.
state: CHANGES_REQUESTED
author_association: MEMBER
submitted_at: 2025-04-09T18:13:14Z
user: login: SamanthaMathews
state: COMMENTED
author_association: NONE
submitted_at: 2025-04-11T14:42:57Z
user: login: zli82016
body: LGTM
state: APPROVED
author_association: MEMBER
submitted_at: 2025-04-14T16:19:09Z
user: login: SamanthaMathews
state: APPROVED
author_association: NONE
submitted_at: 2025-04-14T19:53:34Z

Review comments:
diff_hunk: @@ -461,3 +461,46 @@ resource "google_redis_instance" "test" {
 }
 `, name)
 }
+
+func TestAccRedisInstance_tags(t *testing.T) {
+
+	t.Parallel()
+
+	name := fmt.Sprintf("tf-test-%d", acctest.RandInt(t))
+	org := envvar.GetTestOrgFromEnv(t)
+	tagKey := acctest.BootstrapSharedTestTagKey(t, "redis-instances-tagkey")
+	tagValue := acctest.BootstrapSharedTestTagValue(t, "redis-instances-tagvalue", tagKey)
+	acctest.VcrTest(t, resource.TestCase{
+		PreCheck:                 func() { acctest.AccTestPreCheck(t) },
+		ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
+		CheckDestroy:             testAccCheckRedisInstanceDestroyProducer(t),
+		Steps: []resource.TestStep{
+			{
+				Config: testAccRedisInstanceTags(name, map[string]string{org + "/" + tagKey: tagValue}),
path: mmv1/third_party/terraform/services/redis/resource_redis_instance_test.go
user: login: zli82016
body: We don't want to use the map to list the tags with only one pair of key and value. It prevents the detection of the test for the field `tags` and is not readable. 

Can you remove the usage of map by following this example? https://github.com/GoogleCloudPlatform/magic-modules/blob/main/mmv1/third_party/terraform/services/filestore/resource_filestore_instance_test.go#L413

Thanks.
created_at: 2025-04-09T18:10:06Z
author_association: MEMBER
diff_hunk: @@ -461,3 +461,46 @@ resource "google_redis_instance" "test" {
 }
 `, name)
 }
+
+func TestAccRedisInstance_tags(t *testing.T) {
+
+	t.Parallel()
+
+	name := fmt.Sprintf("tf-test-%d", acctest.RandInt(t))
+	org := envvar.GetTestOrgFromEnv(t)
+	tagKey := acctest.BootstrapSharedTestTagKey(t, "redis-instances-tagkey")
+	tagValue := acctest.BootstrapSharedTestTagValue(t, "redis-instances-tagvalue", tagKey)
+	acctest.VcrTest(t, resource.TestCase{
+		PreCheck:                 func() { acctest.AccTestPreCheck(t) },
+		ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
+		CheckDestroy:             testAccCheckRedisInstanceDestroyProducer(t),
+		Steps: []resource.TestStep{
+			{
+				Config: testAccRedisInstanceTags(name, map[string]string{org + "/" + tagKey: tagValue}),
path: mmv1/third_party/terraform/services/redis/resource_redis_instance_test.go
user: login: SamanthaMathews
body: sure, updating this 
created_at: 2025-04-11T14:42:56Z
author_association: NONE

PR comments:
user: login: github-actions[bot]
created_at: 2025-04-07T12:12:15Z
body: Hello! I am a robot. Tests will require approval from a repository maintainer to run. Googlers: see go/terraform-auto-test-runs to set up automatic test runs.

@zli82016, a repository maintainer, has been assigned to [review your changes](https://googlecloudplatform.github.io/magic-modules/contribute/review-pr/). If you have not received review feedback within 2 business days, please leave a comment on this PR asking them to take a look.

You can help make sure that review is quick by [doing a self-review](https://googlecloudplatform.github.io/magic-modules/contribute/review-pr/) and by [running impacted tests locally](https://googlecloudplatform.github.io/magic-modules/get-started/run-provider-tests/).

author_association: NONE
user: login: modular-magician
created_at: 2025-04-07T12:23:12Z
body: Hi there, I'm the Modular magician. I've detected the following information about your changes:

## Diff report

Your PR generated some diffs in downstreams - here they are.

`google` provider: [Diff](https://github.com/modular-magician/terraform-provider-google/compare/auto-pr-13565-old..auto-pr-13565) ( 5 files changed, 81 insertions(+), 5 deletions(-))
`google-beta` provider: [Diff](https://github.com/modular-magician/terraform-provider-google-beta/compare/auto-pr-13565-old..auto-pr-13565) ( 5 files changed, 81 insertions(+), 5 deletions(-))
`terraform-google-conversion`: [Diff](https://github.com/modular-magician/terraform-google-conversion/compare/auto-pr-13565-old..auto-pr-13565) ( 1 file changed, 17 insertions(+))



## Missing test report
Your PR includes resource fields which are not covered by any test.

Resource: `google_redis_instance` (13 total tests)
Please add an acceptance test which includes these fields. The test should include the following:

```hcl
resource "google_redis_instance" "primary" {
  tags = # value needed
}


```



author_association: COLLABORATOR
user: login: modular-magician
created_at: 2025-04-07T12:26:25Z
body: #### Tests analytics
Total tests: 32
Passed tests: 31
Skipped tests: 0
Affected tests: 1

<details>
<summary>Click here to see the affected service packages</summary>
<blockquote>

<ul>
<li>redis</li>

</ul>

</blockquote>
</details>

#### Action taken
<details>
<summary>Found 1 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
</summary>
<blockquote>
<ul>
<li>TestAccRedisInstance_tags</li>

</ul>
</blockquote>
</details>

[Get to know how VCR tests work](https://googlecloudplatform.github.io/magic-modules/develop/test/test/)
author_association: COLLABORATOR
user: login: modular-magician
created_at: 2025-04-07T12:26:40Z
body: 🔴 Tests failed during RECORDING mode:
`TestAccRedisInstance_tags` [[Error message](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-13565/artifacts/c6bcd0d2-b453-44be-8b9d-3fd1ffa5e187/build-log/recording_build/TestAccRedisInstance_tags_recording_test.log)] [[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-13565/artifacts/c6bcd0d2-b453-44be-8b9d-3fd1ffa5e187/recording/TestAccRedisInstance_tags.log)]



🔴 Errors occurred during RECORDING mode. Please fix them to complete your PR.



View the [build log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-13565/artifacts/c6bcd0d2-b453-44be-8b9d-3fd1ffa5e187/build-log/recording_test.log) or the [debug log](https://console.cloud.google.com/storage/browser/ci-vcr-logs/beta/refs/heads/auto-pr-13565/artifacts/c6bcd0d2-b453-44be-8b9d-3fd1ffa5e187/recording) for each test
author_association: COLLABORATOR
user: login: modular-magician
created_at: 2025-04-14T03:32:40Z
body: Hi there, I'm the Modular magician. I've detected the following information about your changes:

## Diff report

Your PR generated some diffs in downstreams - here they are.

`google` provider: [Diff](https://github.com/modular-magician/terraform-provider-google/compare/auto-pr-13565-old..auto-pr-13565) ( 5 files changed, 80 insertions(+), 5 deletions(-))
`google-beta` provider: [Diff](https://github.com/modular-magician/terraform-provider-google-beta/compare/auto-pr-13565-old..auto-pr-13565) ( 5 files changed, 80 insertions(+), 5 deletions(-))
`terraform-google-conversion`: [Diff](https://github.com/modular-magician/terraform-google-conversion/compare/auto-pr-13565-old..auto-pr-13565) ( 1 file changed, 17 insertions(+))





## Missing doc report (experimental)


The following resources have fields missing in documents. 

- `google_redis_instance` 
  - Expected Document Path: `/website/docs/r/redis_instance.html.markdown`
  - Fields: `[tags]`


The following data sources are missing documents:

- `google_redis_instance`, expect file `/website/docs/d/redis_instance.html.markdown` to exist.
author_association: COLLABORATOR
user: login: modular-magician
created_at: 2025-04-14T03:32:47Z
body: Hi there, I'm the Modular magician. I've detected the following information about your changes:

## Diff report

Your PR generated some diffs in downstreams - here they are.

`google` provider: [Diff](https://github.com/modular-magician/terraform-provider-google/compare/auto-pr-13565-old..auto-pr-13565) ( 5 files changed, 80 insertions(+), 5 deletions(-))
`google-beta` provider: [Diff](https://github.com/modular-magician/terraform-provider-google-beta/compare/auto-pr-13565-old..auto-pr-13565) ( 5 files changed, 80 insertions(+), 5 deletions(-))
`terraform-google-conversion`: [Diff](https://github.com/modular-magician/terraform-google-conversion/compare/auto-pr-13565-old..auto-pr-13565) ( 1 file changed, 17 insertions(+))





## Missing doc report (experimental)


The following resources have fields missing in documents. 

- `google_redis_instance` 
  - Expected Document Path: `/website/docs/r/redis_instance.html.markdown`
  - Fields: `[tags]`


The following data sources are missing documents:

- `google_redis_instance`, expect file `/website/docs/d/redis_instance.html.markdown` to exist.
author_association: COLLABORATOR
user: login: modular-magician
created_at: 2025-04-14T03:35:55Z
body: #### Tests analytics
Total tests: 34
Passed tests: 33
Skipped tests: 0
Affected tests: 1

<details>
<summary>Click here to see the affected service packages</summary>
<blockquote>

<ul>
<li>redis</li>

</ul>

</blockquote>
</details>

#### Action taken
<details>
<summary>Found 1 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
</summary>
<blockquote>
<ul>
<li>TestAccRedisInstance_tags</li>

</ul>
</blockquote>
</details>

[Get to know how VCR tests work](https://googlecloudplatform.github.io/magic-modules/develop/test/test/)
author_association: COLLABORATOR
user: login: modular-magician
created_at: 2025-04-14T03:36:29Z
body: #### Tests analytics
Total tests: 34
Passed tests: 33
Skipped tests: 0
Affected tests: 1

<details>
<summary>Click here to see the affected service packages</summary>
<blockquote>

<ul>
<li>redis</li>

</ul>

</blockquote>
</details>

#### Action taken
<details>
<summary>Found 1 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
</summary>
<blockquote>
<ul>
<li>TestAccRedisInstance_tags</li>

</ul>
</blockquote>
</details>

[Get to know how VCR tests work](https://googlecloudplatform.github.io/magic-modules/develop/test/test/)
author_association: COLLABORATOR
user: login: modular-magician
created_at: 2025-04-14T03:45:04Z
body: 🟢 Tests passed during RECORDING mode:
`TestAccRedisInstance_tags` [[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-13565/artifacts/4e0fd3d7-12aa-42ec-8c3f-5c5d88995441/recording/TestAccRedisInstance_tags.log)]

🟢 No issues found for passed tests after REPLAYING rerun.

---






🟢 All tests passed!

View the [build log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-13565/artifacts/4e0fd3d7-12aa-42ec-8c3f-5c5d88995441/build-log/recording_test.log) or the [debug log](https://console.cloud.google.com/storage/browser/ci-vcr-logs/beta/refs/heads/auto-pr-13565/artifacts/4e0fd3d7-12aa-42ec-8c3f-5c5d88995441/recording) for each test
author_association: COLLABORATOR
user: login: modular-magician
created_at: 2025-04-14T03:46:02Z
body: 🟢 Tests passed during RECORDING mode:
`TestAccRedisInstance_tags` [[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-13565/artifacts/049f6ad4-62e4-4393-9b45-f8ac9969a05d/recording/TestAccRedisInstance_tags.log)]

🟢 No issues found for passed tests after REPLAYING rerun.

---






🟢 All tests passed!

View the [build log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-13565/artifacts/049f6ad4-62e4-4393-9b45-f8ac9969a05d/build-log/recording_test.log) or the [debug log](https://console.cloud.google.com/storage/browser/ci-vcr-logs/beta/refs/heads/auto-pr-13565/artifacts/049f6ad4-62e4-4393-9b45-f8ac9969a05d/recording) for each test
author_association: COLLABORATOR
user: login: zli82016
created_at: 2025-04-14T16:20:02Z
body: @SamanthaMathews, do you mind reviewing the PR? Thanks.
author_association: MEMBER
user: login: SamanthaMathews
created_at: 2025-04-14T19:53:21Z
body: > @SamanthaMathews, do you mind reviewing the PR? Thanks.

LGTM
author_association: NONE