Skip to content

Commit c8d6ede

Browse files
Add tags field to Filestore Backups for TagsR2401 (#12442)
Co-authored-by: Nick Elliot <[email protected]>
1 parent 41106d3 commit c8d6ede

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

mmv1/products/filestore/Backup.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,12 @@ properties:
140140
description: |
141141
KMS key name used for data encryption.
142142
output: true
143+
- name: 'tags'
144+
type: KeyValuePairs
145+
description: |
146+
A map of resource manager tags.
147+
Resource manager tag keys and values have the same definition as resource manager tags.
148+
Keys must be in the format tagKeys/{tag_key_id}, and values are in the format tagValues/{tag_value_id}.
149+
The field is ignored (both PUT & PATCH) when empty.
150+
immutable: true
151+
ignore_read: true

mmv1/third_party/terraform/services/filestore/resource_filestore_backup_test.go

+70
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
88
"github.com/hashicorp/terraform-provider-google/google/acctest"
9+
"github.com/hashicorp/terraform-provider-google/google/envvar"
910
)
1011

1112
func TestAccFilestoreBackup_update(t *testing.T) {
@@ -113,3 +114,72 @@ resource "google_filestore_backup" "backup" {
113114
114115
`, instName, bkupName)
115116
}
117+
118+
func TestAccFilestoreBackup_tags(t *testing.T) {
119+
t.Parallel()
120+
121+
org := envvar.GetTestOrgFromEnv(t)
122+
instanceName := fmt.Sprintf("tf-fs-inst-%d", acctest.RandInt(t))
123+
backupName := fmt.Sprintf("tf-fs-bkup-%d", acctest.RandInt(t))
124+
tagKey := acctest.BootstrapSharedTestTagKey(t, "filestore-backups-tagkey")
125+
tagValue := acctest.BootstrapSharedTestTagValue(t, "filestore-backups-tagvalue", tagKey)
126+
127+
acctest.VcrTest(t, resource.TestCase{
128+
PreCheck: func() { acctest.AccTestPreCheck(t) },
129+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
130+
CheckDestroy: testAccCheckFilestoreBackupDestroyProducer(t),
131+
Steps: []resource.TestStep{
132+
{
133+
Config: testAccFilestoreBackupTags(instanceName, backupName, map[string]string{org + "/" + tagKey: tagValue}),
134+
},
135+
{
136+
ResourceName: "google_filestore_backup.backup",
137+
ImportState: true,
138+
ImportStateVerify: true,
139+
ImportStateVerifyIgnore: []string{"labels", "terraform_labels", "description", "location", "tags"},
140+
},
141+
},
142+
})
143+
}
144+
145+
func testAccFilestoreBackupTags(instanceName string, backupName string, tags map[string]string) string {
146+
147+
r := fmt.Sprintf(`
148+
resource "google_filestore_instance" "instance" {
149+
name = "%s"
150+
location = "us-central1-b"
151+
tier = "BASIC_HDD"
152+
153+
file_shares {
154+
capacity_gb = 1024
155+
name = "share1"
156+
}
157+
158+
networks {
159+
network = "default"
160+
modes = ["MODE_IPV4"]
161+
connect_mode = "DIRECT_PEERING"
162+
}
163+
}
164+
165+
resource "google_filestore_backup" "backup" {
166+
name = "%s"
167+
location = "us-central1"
168+
description = "This is a filestore backup for the test instance"
169+
source_instance = google_filestore_instance.instance.id
170+
source_file_share = "share1"
171+
172+
labels = {
173+
"files":"label1",
174+
"other-label": "label2"
175+
}
176+
tags = {`, instanceName, backupName)
177+
178+
l := ""
179+
for key, value := range tags {
180+
l += fmt.Sprintf("%q = %q\n", key, value)
181+
}
182+
183+
l += fmt.Sprintf("}\n}")
184+
return r + l
185+
}

0 commit comments

Comments
 (0)