Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tags field to Filestore Backups for TagsR2401 #12442

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions mmv1/products/filestore/Backup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,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
}
Loading