Skip to content

Commit

Permalink
Filestore protocol GA (#12063) (#19982)
Browse files Browse the repository at this point in the history
[upstream:7a04aecaaba252d0e5543a1c3f7cb210dd8b6c2c]

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Oct 23, 2024
1 parent 58f0b86 commit 3c44f22
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/12063.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
filestore: Migrated `protocol` property for `google_filestore_instance` from Beta to GA
```
32 changes: 32 additions & 0 deletions google/services/filestore/resource_filestore_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,17 @@ Please refer to the field 'effective_labels' for all of the labels present on th
Description: `The name of the location of the instance. This can be a region for ENTERPRISE tier instances.`,
ExactlyOneOf: []string{},
},
"protocol": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: verify.ValidateEnum([]string{"NFS_V3", "NFS_V4_1", ""}),
Description: `Either NFSv3, for using NFS version 3 as file sharing protocol,
or NFSv4.1, for using NFS version 4.1 as file sharing protocol.
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",
},
"zone": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -320,6 +331,12 @@ func resourceFilestoreInstanceCreate(d *schema.ResourceData, meta interface{}) e
} else if v, ok := d.GetOkExists("tier"); !tpgresource.IsEmptyValue(reflect.ValueOf(tierProp)) && (ok || !reflect.DeepEqual(v, tierProp)) {
obj["tier"] = tierProp
}
protocolProp, err := expandFilestoreInstanceProtocol(d.Get("protocol"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("protocol"); !tpgresource.IsEmptyValue(reflect.ValueOf(protocolProp)) && (ok || !reflect.DeepEqual(v, protocolProp)) {
obj["protocol"] = protocolProp
}
fileSharesProp, err := expandFilestoreInstanceFileShares(d.Get("file_shares"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -493,6 +510,9 @@ func resourceFilestoreInstanceRead(d *schema.ResourceData, meta interface{}) err
if err := d.Set("tier", flattenFilestoreInstanceTier(res["tier"], d, config)); err != nil {
return fmt.Errorf("Error reading Instance: %s", err)
}
if err := d.Set("protocol", flattenFilestoreInstanceProtocol(res["protocol"], d, config)); err != nil {
return fmt.Errorf("Error reading Instance: %s", err)
}
if err := d.Set("labels", flattenFilestoreInstanceLabels(res["labels"], d, config)); err != nil {
return fmt.Errorf("Error reading Instance: %s", err)
}
Expand Down Expand Up @@ -732,6 +752,14 @@ func flattenFilestoreInstanceTier(v interface{}, d *schema.ResourceData, config
return v
}

func flattenFilestoreInstanceProtocol(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil || tpgresource.IsEmptyValue(reflect.ValueOf(v)) {
return "NFS_V3"
}

return v
}

func flattenFilestoreInstanceLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return v
Expand Down Expand Up @@ -950,6 +978,10 @@ func expandFilestoreInstanceTier(v interface{}, d tpgresource.TerraformResourceD
return v, nil
}

func expandFilestoreInstanceProtocol(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandFilestoreInstanceFileShares(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
req := make([]interface{}, 0, len(l))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,53 @@ resource "google_filestore_instance" "instance" {
`, context)
}

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

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckFilestoreInstanceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccFilestoreInstance_filestoreInstanceProtocolExample(context),
},
{
ResourceName: "google_filestore_instance.instance",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"labels", "location", "name", "terraform_labels", "zone"},
},
},
})
}

func testAccFilestoreInstance_filestoreInstanceProtocolExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_filestore_instance" "instance" {
name = "tf-test-test-instance%{random_suffix}"
location = "us-central1"
tier = "ENTERPRISE"
protocol = "NFS_V4_1"
file_shares {
capacity_gb = 1024
name = "share1"
}
networks {
network = "default"
modes = ["MODE_IPV4"]
}
}
`, context)
}

func testAccCheckFilestoreInstanceDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
Expand Down
3 changes: 1 addition & 2 deletions website/docs/r/filestore_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ resource "google_filestore_instance" "instance" {

```hcl
resource "google_filestore_instance" "instance" {
provider = google-beta
name = "test-instance"
location = "us-central1"
tier = "ENTERPRISE"
Expand Down Expand Up @@ -278,7 +277,7 @@ The following arguments are supported:
A description of the instance.

* `protocol` -
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
(Optional)
Either NFSv3, for using NFS version 3 as file sharing protocol,
or NFSv4.1, for using NFS version 4.1 as file sharing protocol.
NFSv4.1 can be used with HIGH_SCALE_SSD, ZONAL, REGIONAL and ENTERPRISE.
Expand Down

0 comments on commit 3c44f22

Please sign in to comment.