Skip to content

Commit

Permalink
Add protocol field for filestore Instance product (#10324) (#7254)
Browse files Browse the repository at this point in the history
[upstream:a508f995c2934263f88d2f4030008079225698ec]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Apr 17, 2024
1 parent f52eb40 commit 3051522
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/10324.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
filestore: Added `protocol` property for `google_filestore_instance` instance to support NFSv3 and NFSv4.1
```
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 @@ -246,6 +246,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 @@ -310,6 +321,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 @@ -471,6 +488,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 @@ -684,6 +704,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 @@ -894,6 +922,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,54 @@ 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.ProtoV5ProviderBetaFactories(t),
CheckDestroy: testAccCheckFilestoreInstanceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccFilestoreInstance_filestoreInstanceProtocolExample(context),
},
{
ResourceName: "google_filestore_instance.instance",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"name", "zone", "location", "labels", "terraform_labels"},
},
},
})
}

func testAccFilestoreInstance_filestoreInstanceProtocolExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_filestore_instance" "instance" {
provider = google-beta
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
37 changes: 37 additions & 0 deletions website/docs/r/filestore_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,34 @@ resource "google_filestore_instance" "instance" {
}
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=filestore_instance_protocol&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Filestore Instance Protocol


```hcl
resource "google_filestore_instance" "instance" {
provider = google-beta
name = "test-instance"
location = "us-central1"
tier = "ENTERPRISE"
protocol = "NFS_V4_1"
file_shares {
capacity_gb = 1024
name = "share1"
}
networks {
network = "default"
modes = ["MODE_IPV4"]
}
}
```
## Example Usage - Filestore Instance Enterprise


Expand Down Expand Up @@ -249,6 +277,15 @@ The following arguments are supported:
(Optional)
A description of the instance.

* `protocol` -
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
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 is `NFS_V3`.
Possible values are: `NFS_V3`, `NFS_V4_1`.

* `labels` -
(Optional)
Resource labels to represent user-provided metadata.
Expand Down

0 comments on commit 3051522

Please sign in to comment.