Skip to content

Commit

Permalink
Add tags field to Filestore Backups for TagsR2401 (#12442)
Browse files Browse the repository at this point in the history
Co-authored-by: Nick Elliot <[email protected]>
  • Loading branch information
aniket-gupta and NickElliot authored Dec 17, 2024
1 parent 41106d3 commit c8d6ede
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
9 changes: 9 additions & 0 deletions mmv1/products/filestore/Backup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,12 @@ properties:
description: |
KMS key name used for data encryption.
output: 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_value_id}.
The field is ignored (both PUT & PATCH) when empty.
immutable: true
ignore_read: true
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-provider-google/google/acctest"
"github.com/hashicorp/terraform-provider-google/google/envvar"
)

func TestAccFilestoreBackup_update(t *testing.T) {
Expand Down Expand Up @@ -113,3 +114,72 @@ resource "google_filestore_backup" "backup" {
`, instName, bkupName)
}

func TestAccFilestoreBackup_tags(t *testing.T) {
t.Parallel()

org := envvar.GetTestOrgFromEnv(t)
instanceName := fmt.Sprintf("tf-fs-inst-%d", acctest.RandInt(t))
backupName := fmt.Sprintf("tf-fs-bkup-%d", acctest.RandInt(t))
tagKey := acctest.BootstrapSharedTestTagKey(t, "filestore-backups-tagkey")
tagValue := acctest.BootstrapSharedTestTagValue(t, "filestore-backups-tagvalue", tagKey)

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckFilestoreBackupDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccFilestoreBackupTags(instanceName, backupName, map[string]string{org + "/" + tagKey: tagValue}),
},
{
ResourceName: "google_filestore_backup.backup",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"labels", "terraform_labels", "description", "location", "tags"},
},
},
})
}

func testAccFilestoreBackupTags(instanceName string, backupName string, tags map[string]string) string {

r := fmt.Sprintf(`
resource "google_filestore_instance" "instance" {
name = "%s"
location = "us-central1-b"
tier = "BASIC_HDD"
file_shares {
capacity_gb = 1024
name = "share1"
}
networks {
network = "default"
modes = ["MODE_IPV4"]
connect_mode = "DIRECT_PEERING"
}
}
resource "google_filestore_backup" "backup" {
name = "%s"
location = "us-central1"
description = "This is a filestore backup for the test instance"
source_instance = google_filestore_instance.instance.id
source_file_share = "share1"
labels = {
"files":"label1",
"other-label": "label2"
}
tags = {`, instanceName, backupName)

l := ""
for key, value := range tags {
l += fmt.Sprintf("%q = %q\n", key, value)
}

l += fmt.Sprintf("}\n}")
return r + l
}

0 comments on commit c8d6ede

Please sign in to comment.