Skip to content

Commit b658350

Browse files
Add tags field to Filestore Instances for TagsR2401 (#12712)
[upstream:83b3b9bf0734efa462648384ab469f1f37f929d7] Signed-off-by: Modular Magician <[email protected]>
1 parent 017653e commit b658350

File tree

5 files changed

+103
-5
lines changed

5 files changed

+103
-5
lines changed

.changelog/12712.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
filestore: added support for `tags` field to `google_filestore_instance` resource
3+
```

google-beta/services/filestore/resource_filestore_instance.go

+32
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,21 @@ NFSv4.1 can be used with HIGH_SCALE_SSD, ZONAL, REGIONAL and ENTERPRISE.
318318
The default is NFSv3. Default value: "NFS_V3" Possible values: ["NFS_V3", "NFS_V4_1"]`,
319319
Default: "NFS_V3",
320320
},
321+
"tags": {
322+
Type: schema.TypeMap,
323+
Optional: true,
324+
ForceNew: true,
325+
Description: `A map of resource manager tags. Resource manager tag keys
326+
and values have the same definition as resource manager
327+
tags. Keys must be in the format tagKeys/{tag_key_id},
328+
and values are in the format tagValues/456. The field is
329+
ignored when empty. The field is immutable and causes
330+
resource replacement when mutated. This field is only set
331+
at create time and modifying this field after creation
332+
will trigger recreation. To apply tags to an existing
333+
resource, see the 'google_tags_tag_value' resource.`,
334+
Elem: &schema.Schema{Type: schema.TypeString},
335+
},
321336
"zone": {
322337
Type: schema.TypeString,
323338
Computed: true,
@@ -424,6 +439,12 @@ func resourceFilestoreInstanceCreate(d *schema.ResourceData, meta interface{}) e
424439
} else if v, ok := d.GetOkExists("performance_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(performanceConfigProp)) && (ok || !reflect.DeepEqual(v, performanceConfigProp)) {
425440
obj["performanceConfig"] = performanceConfigProp
426441
}
442+
tagsProp, err := expandFilestoreInstanceTags(d.Get("tags"), d, config)
443+
if err != nil {
444+
return err
445+
} else if v, ok := d.GetOkExists("tags"); !tpgresource.IsEmptyValue(reflect.ValueOf(tagsProp)) && (ok || !reflect.DeepEqual(v, tagsProp)) {
446+
obj["tags"] = tagsProp
447+
}
427448
labelsProp, err := expandFilestoreInstanceEffectiveLabels(d.Get("effective_labels"), d, config)
428449
if err != nil {
429450
return err
@@ -1406,6 +1427,17 @@ func expandFilestoreInstancePerformanceConfigFixedIopsMaxIops(v interface{}, d t
14061427
return v, nil
14071428
}
14081429

1430+
func expandFilestoreInstanceTags(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
1431+
if v == nil {
1432+
return map[string]string{}, nil
1433+
}
1434+
m := make(map[string]string)
1435+
for k, val := range v.(map[string]interface{}) {
1436+
m[k] = val.(string)
1437+
}
1438+
return m, nil
1439+
}
1440+
14091441
func expandFilestoreInstanceEffectiveLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
14101442
if v == nil {
14111443
return map[string]string{}, nil

google-beta/services/filestore/resource_filestore_instance_generated_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func TestAccFilestoreInstance_filestoreInstanceBasicExample(t *testing.T) {
4949
ResourceName: "google_filestore_instance.instance",
5050
ImportState: true,
5151
ImportStateVerify: true,
52-
ImportStateVerifyIgnore: []string{"labels", "location", "name", "terraform_labels", "zone"},
52+
ImportStateVerifyIgnore: []string{"labels", "location", "name", "tags", "terraform_labels", "zone"},
5353
},
5454
},
5555
})
@@ -94,7 +94,7 @@ func TestAccFilestoreInstance_filestoreInstanceFullExample(t *testing.T) {
9494
ResourceName: "google_filestore_instance.instance",
9595
ImportState: true,
9696
ImportStateVerify: true,
97-
ImportStateVerifyIgnore: []string{"labels", "location", "name", "terraform_labels", "zone"},
97+
ImportStateVerifyIgnore: []string{"labels", "location", "name", "tags", "terraform_labels", "zone"},
9898
},
9999
},
100100
})
@@ -154,7 +154,7 @@ func TestAccFilestoreInstance_filestoreInstanceProtocolExample(t *testing.T) {
154154
ResourceName: "google_filestore_instance.instance",
155155
ImportState: true,
156156
ImportStateVerify: true,
157-
ImportStateVerifyIgnore: []string{"labels", "location", "name", "terraform_labels", "zone"},
157+
ImportStateVerifyIgnore: []string{"labels", "location", "name", "tags", "terraform_labels", "zone"},
158158
},
159159
},
160160
})

google-beta/services/filestore/resource_filestore_instance_test.go

+53-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import (
88
"reflect"
99
"testing"
1010

11+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1112
"github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest"
13+
"github.com/hashicorp/terraform-provider-google-beta/google-beta/envvar"
1214
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/filestore"
13-
14-
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1515
)
1616

1717
func testResourceFilestoreInstanceStateDataV0() map[string]interface{} {
@@ -411,3 +411,54 @@ resource "google_filestore_instance" "instance" {
411411
}
412412
`, name, location, tier)
413413
}
414+
415+
func TestAccFilestoreInstance_tags(t *testing.T) {
416+
t.Parallel()
417+
name := fmt.Sprintf("tf-test-%d", acctest.RandInt(t))
418+
org := envvar.GetTestOrgFromEnv(t)
419+
tagKey := acctest.BootstrapSharedTestTagKey(t, "filestore-instances-tagkey")
420+
tagValue := acctest.BootstrapSharedTestTagValue(t, "filestore-instances-tagvalue", tagKey)
421+
422+
acctest.VcrTest(t, resource.TestCase{
423+
PreCheck: func() { acctest.AccTestPreCheck(t) },
424+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
425+
CheckDestroy: testAccCheckFilestoreInstanceDestroyProducer(t),
426+
Steps: []resource.TestStep{
427+
{
428+
Config: testAccFileInstanceTags(name, map[string]string{org + "/" + tagKey: tagValue}),
429+
},
430+
{
431+
ResourceName: "google_filestore_instance.instance",
432+
ImportState: true,
433+
ImportStateVerify: true,
434+
ImportStateVerifyIgnore: []string{"zone", "location", "networks.0.reserved_ip_range", "tags"},
435+
},
436+
},
437+
})
438+
}
439+
440+
func testAccFileInstanceTags(name string, tags map[string]string) string {
441+
r := fmt.Sprintf(`
442+
resource "google_filestore_instance" "instance" {
443+
name = "tf-test-instance-%s"
444+
zone = "us-central1-b"
445+
tier = "BASIC_HDD"
446+
file_shares {
447+
capacity_gb = 1024
448+
name = "share1"
449+
}
450+
networks {
451+
network = "default"
452+
modes = ["MODE_IPV4"]
453+
reserved_ip_range = "172.19.31.8/29"
454+
}
455+
tags = {`, name)
456+
457+
l := ""
458+
for key, value := range tags {
459+
l += fmt.Sprintf("%q = %q\n", key, value)
460+
}
461+
462+
l += fmt.Sprintf("}\n}")
463+
return r + l
464+
}

website/docs/r/filestore_instance.html.markdown

+12
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,18 @@ The following arguments are supported:
310310
the default performance settings will be used.
311311
Structure is [documented below](#nested_performance_config).
312312

313+
* `tags` -
314+
(Optional)
315+
A map of resource manager tags. Resource manager tag keys
316+
and values have the same definition as resource manager
317+
tags. Keys must be in the format tagKeys/{tag_key_id},
318+
and values are in the format tagValues/456. The field is
319+
ignored when empty. The field is immutable and causes
320+
resource replacement when mutated. This field is only set
321+
at create time and modifying this field after creation
322+
will trigger recreation. To apply tags to an existing
323+
resource, see the `google_tags_tag_value` resource.
324+
313325
* `zone` -
314326
(Optional, Deprecated)
315327
The name of the Filestore zone of the instance.

0 commit comments

Comments
 (0)