Skip to content

Add tags field to Filestore Instances for TagsR2401 #9086

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

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
3 changes: 3 additions & 0 deletions .changelog/12712.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
filestore: added support for `tags` field to `google_filestore_instance` resource
```
32 changes: 32 additions & 0 deletions google-beta/services/filestore/resource_filestore_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,21 @@ NFSv4.1 can be used with HIGH_SCALE_SSD, ZONAL, REGIONAL and ENTERPRISE.
The default is NFSv3. Default value: "NFS_V3" Possible values: ["NFS_V3", "NFS_V4_1"]`,
Default: "NFS_V3",
},
"tags": {
Type: schema.TypeMap,
Optional: true,
ForceNew: true,
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/456. The field is
ignored when empty. The field is immutable and causes
resource replacement when mutated. This field is only set
at create time and modifying this field after creation
will trigger recreation. To apply tags to an existing
resource, see the 'google_tags_tag_value' resource.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"zone": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -424,6 +439,12 @@ func resourceFilestoreInstanceCreate(d *schema.ResourceData, meta interface{}) e
} else if v, ok := d.GetOkExists("performance_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(performanceConfigProp)) && (ok || !reflect.DeepEqual(v, performanceConfigProp)) {
obj["performanceConfig"] = performanceConfigProp
}
tagsProp, err := expandFilestoreInstanceTags(d.Get("tags"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("tags"); !tpgresource.IsEmptyValue(reflect.ValueOf(tagsProp)) && (ok || !reflect.DeepEqual(v, tagsProp)) {
obj["tags"] = tagsProp
}
labelsProp, err := expandFilestoreInstanceEffectiveLabels(d.Get("effective_labels"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -1406,6 +1427,17 @@ func expandFilestoreInstancePerformanceConfigFixedIopsMaxIops(v interface{}, d t
return v, nil
}

func expandFilestoreInstanceTags(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
if v == nil {
return map[string]string{}, nil
}
m := make(map[string]string)
for k, val := range v.(map[string]interface{}) {
m[k] = val.(string)
}
return m, nil
}

func expandFilestoreInstanceEffectiveLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
if v == nil {
return map[string]string{}, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestAccFilestoreInstance_filestoreInstanceBasicExample(t *testing.T) {
ResourceName: "google_filestore_instance.instance",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"labels", "location", "name", "terraform_labels", "zone"},
ImportStateVerifyIgnore: []string{"labels", "location", "name", "tags", "terraform_labels", "zone"},
},
},
})
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestAccFilestoreInstance_filestoreInstanceFullExample(t *testing.T) {
ResourceName: "google_filestore_instance.instance",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"labels", "location", "name", "terraform_labels", "zone"},
ImportStateVerifyIgnore: []string{"labels", "location", "name", "tags", "terraform_labels", "zone"},
},
},
})
Expand Down Expand Up @@ -154,7 +154,7 @@ func TestAccFilestoreInstance_filestoreInstanceProtocolExample(t *testing.T) {
ResourceName: "google_filestore_instance.instance",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"labels", "location", "name", "terraform_labels", "zone"},
ImportStateVerifyIgnore: []string{"labels", "location", "name", "tags", "terraform_labels", "zone"},
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"reflect"
"testing"

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

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

func testResourceFilestoreInstanceStateDataV0() map[string]interface{} {
Expand Down Expand Up @@ -411,3 +411,54 @@ resource "google_filestore_instance" "instance" {
}
`, name, location, tier)
}

func TestAccFilestoreInstance_tags(t *testing.T) {
t.Parallel()
name := fmt.Sprintf("tf-test-%d", acctest.RandInt(t))
org := envvar.GetTestOrgFromEnv(t)
tagKey := acctest.BootstrapSharedTestTagKey(t, "filestore-instances-tagkey")
tagValue := acctest.BootstrapSharedTestTagValue(t, "filestore-instances-tagvalue", tagKey)

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckFilestoreInstanceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccFileInstanceTags(name, map[string]string{org + "/" + tagKey: tagValue}),
},
{
ResourceName: "google_filestore_instance.instance",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"zone", "location", "networks.0.reserved_ip_range", "tags"},
},
},
})
}

func testAccFileInstanceTags(name string, tags map[string]string) string {
r := fmt.Sprintf(`
resource "google_filestore_instance" "instance" {
name = "tf-test-instance-%s"
zone = "us-central1-b"
tier = "BASIC_HDD"
file_shares {
capacity_gb = 1024
name = "share1"
}
networks {
network = "default"
modes = ["MODE_IPV4"]
reserved_ip_range = "172.19.31.8/29"
}
tags = {`, name)

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

l += fmt.Sprintf("}\n}")
return r + l
}
12 changes: 12 additions & 0 deletions website/docs/r/filestore_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,18 @@ The following arguments are supported:
the default performance settings will be used.
Structure is [documented below](#nested_performance_config).

* `tags` -
(Optional)
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/456. The field is
ignored when empty. The field is immutable and causes
resource replacement when mutated. This field is only set
at create time and modifying this field after creation
will trigger recreation. To apply tags to an existing
resource, see the `google_tags_tag_value` resource.

* `zone` -
(Optional, Deprecated)
The name of the Filestore zone of the instance.
Expand Down
Loading