|
6 | 6 |
|
7 | 7 | "github.com/hashicorp/terraform-plugin-testing/helper/resource"
|
8 | 8 | "github.com/hashicorp/terraform-provider-google/google/acctest"
|
| 9 | + "github.com/hashicorp/terraform-provider-google/google/envvar" |
9 | 10 | )
|
10 | 11 |
|
11 | 12 | func TestAccFilestoreBackup_update(t *testing.T) {
|
@@ -113,3 +114,72 @@ resource "google_filestore_backup" "backup" {
|
113 | 114 |
|
114 | 115 | `, instName, bkupName)
|
115 | 116 | }
|
| 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