Skip to content

Commit

Permalink
add tiers and nfs_export_options (#3766) (#2289)
Browse files Browse the repository at this point in the history
* add tiers and nfs_export_options

* update docs, make full test beta

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Jul 22, 2020
1 parent 7b66b35 commit 9d4a63e
Show file tree
Hide file tree
Showing 7 changed files with 350 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .changelog/3766.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```release-note:enhancement
filestore: added support for filestore high scale tier.
```
```release-note:enhancement
filestore: added `nfs_export_options` field on `google_filestore_instance.file_shares`. (beta-only)
```
2 changes: 1 addition & 1 deletion google-beta/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ var DatastoreDefaultBasePath = "https://datastore.googleapis.com/v1/"
var DeploymentManagerDefaultBasePath = "https://www.googleapis.com/deploymentmanager/v2/"
var DialogflowDefaultBasePath = "https://dialogflow.googleapis.com/v2/"
var DNSDefaultBasePath = "https://www.googleapis.com/dns/v1beta2/"
var FilestoreDefaultBasePath = "https://file.googleapis.com/v1/"
var FilestoreDefaultBasePath = "https://file.googleapis.com/v1beta1/"
var FirebaseDefaultBasePath = "https://firebase.googleapis.com/v1beta1/"
var FirestoreDefaultBasePath = "https://firestore.googleapis.com/v1/"
var GameServicesDefaultBasePath = "https://gameservices.googleapis.com/v1beta/"
Expand Down
2 changes: 1 addition & 1 deletion google-beta/filestore_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (w *FilestoreOperationWaiter) QueryOp() (interface{}, error) {
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
}
// Returns the proper get.
url := fmt.Sprintf("https://file.googleapis.com/v1/%s", w.CommonOperationWaiter.Op.Name)
url := fmt.Sprintf("https://file.googleapis.com/v1beta1/%s", w.CommonOperationWaiter.Op.Name)
return sendRequest(w.Config, "GET", w.Project, url, nil)
}

Expand Down
204 changes: 200 additions & 4 deletions google-beta/resource_filestore_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,56 @@ for the standard tier, or 2560 GiB for the premium tier.`,
ForceNew: true,
Description: `The name of the fileshare (16 characters or less)`,
},
"nfs_export_options": {
Type: schema.TypeList,
Optional: true,
Description: `Nfs Export Options. There is a limit of 10 export options per file share.`,
MaxItems: 10,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"access_mode": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"READ_ONLY", "READ_WRITE", ""}, false),
Description: `Either READ_ONLY, for allowing only read requests on the exported directory,
or READ_WRITE, for allowing both read and write requests. The default is READ_WRITE. Default value: "READ_WRITE" Possible values: ["READ_ONLY", "READ_WRITE"]`,
Default: "READ_WRITE",
},
"anon_gid": {
Type: schema.TypeInt,
Optional: true,
Description: `An integer representing the anonymous group id with a default value of 65534.
Anon_gid may only be set with squashMode of ROOT_SQUASH. An error will be returned
if this field is specified for other squashMode settings.`,
},
"anon_uid": {
Type: schema.TypeInt,
Optional: true,
Description: `An integer representing the anonymous user id with a default value of 65534.
Anon_uid may only be set with squashMode of ROOT_SQUASH. An error will be returned
if this field is specified for other squashMode settings.`,
},
"ip_ranges": {
Type: schema.TypeList,
Optional: true,
Description: `List of either IPv4 addresses, or ranges in CIDR notation which may mount the file share.
Overlapping IP ranges are not allowed, both within and across NfsExportOptions. An error will be returned.
The limit is 64 IP ranges/addresses for each FileShareConfig among all NfsExportOptions.`,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"squash_mode": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"NO_ROOT_SQUASH", "ROOT_SQUASH", ""}, false),
Description: `Either NO_ROOT_SQUASH, for allowing root access on the exported directory, or ROOT_SQUASH,
for not allowing root access. The default is NO_ROOT_SQUASH. Default value: "NO_ROOT_SQUASH" Possible values: ["NO_ROOT_SQUASH", "ROOT_SQUASH"]`,
Default: "NO_ROOT_SQUASH",
},
},
},
},
},
},
},
Expand Down Expand Up @@ -120,8 +170,8 @@ addresses reserved for this instance.`,
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{"TIER_UNSPECIFIED", "STANDARD", "PREMIUM"}, false),
Description: `The service tier of the instance. Possible values: ["TIER_UNSPECIFIED", "STANDARD", "PREMIUM"]`,
ValidateFunc: validation.StringInSlice([]string{"TIER_UNSPECIFIED", "STANDARD", "PREMIUM", "BASIC_HDD", "BASIC_SSD", "HIGH_SCALE_SSD"}, false),
Description: `The service tier of the instance. Possible values: ["TIER_UNSPECIFIED", "STANDARD", "PREMIUM", "BASIC_HDD", "BASIC_SSD", "HIGH_SCALE_SSD"]`,
},
"zone": {
Type: schema.TypeString,
Expand Down Expand Up @@ -441,8 +491,9 @@ func flattenFilestoreInstanceFileShares(v interface{}, d *schema.ResourceData, c
continue
}
transformed = append(transformed, map[string]interface{}{
"name": flattenFilestoreInstanceFileSharesName(original["name"], d, config),
"capacity_gb": flattenFilestoreInstanceFileSharesCapacityGb(original["capacityGb"], d, config),
"name": flattenFilestoreInstanceFileSharesName(original["name"], d, config),
"capacity_gb": flattenFilestoreInstanceFileSharesCapacityGb(original["capacityGb"], d, config),
"nfs_export_options": flattenFilestoreInstanceFileSharesNfsExportOptions(original["nfsExportOptions"], d, config),
})
}
return transformed
Expand All @@ -468,6 +519,74 @@ func flattenFilestoreInstanceFileSharesCapacityGb(v interface{}, d *schema.Resou
return v // let terraform core handle it otherwise
}

func flattenFilestoreInstanceFileSharesNfsExportOptions(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return v
}
l := v.([]interface{})
transformed := make([]interface{}, 0, len(l))
for _, raw := range l {
original := raw.(map[string]interface{})
if len(original) < 1 {
// Do not include empty json objects coming back from the api
continue
}
transformed = append(transformed, map[string]interface{}{
"ip_ranges": flattenFilestoreInstanceFileSharesNfsExportOptionsIpRanges(original["ipRanges"], d, config),
"access_mode": flattenFilestoreInstanceFileSharesNfsExportOptionsAccessMode(original["accessMode"], d, config),
"squash_mode": flattenFilestoreInstanceFileSharesNfsExportOptionsSquashMode(original["squashMode"], d, config),
"anon_uid": flattenFilestoreInstanceFileSharesNfsExportOptionsAnonUid(original["anonUid"], d, config),
"anon_gid": flattenFilestoreInstanceFileSharesNfsExportOptionsAnonGid(original["anonGid"], d, config),
})
}
return transformed
}
func flattenFilestoreInstanceFileSharesNfsExportOptionsIpRanges(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenFilestoreInstanceFileSharesNfsExportOptionsAccessMode(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenFilestoreInstanceFileSharesNfsExportOptionsSquashMode(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenFilestoreInstanceFileSharesNfsExportOptionsAnonUid(v interface{}, d *schema.ResourceData, config *Config) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
return intVal
}
}

// number values are represented as float64
if floatVal, ok := v.(float64); ok {
intVal := int(floatVal)
return intVal
}

return v // let terraform core handle it otherwise
}

func flattenFilestoreInstanceFileSharesNfsExportOptionsAnonGid(v interface{}, d *schema.ResourceData, config *Config) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
return intVal
}
}

// number values are represented as float64
if floatVal, ok := v.(float64); ok {
intVal := int(floatVal)
return intVal
}

return v // let terraform core handle it otherwise
}

func flattenFilestoreInstanceNetworks(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return v
Expand Down Expand Up @@ -552,6 +671,13 @@ func expandFilestoreInstanceFileShares(v interface{}, d TerraformResourceData, c
transformed["capacityGb"] = transformedCapacityGb
}

transformedNfsExportOptions, err := expandFilestoreInstanceFileSharesNfsExportOptions(original["nfs_export_options"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedNfsExportOptions); val.IsValid() && !isEmptyValue(val) {
transformed["nfsExportOptions"] = transformedNfsExportOptions
}

req = append(req, transformed)
}
return req, nil
Expand All @@ -565,6 +691,76 @@ func expandFilestoreInstanceFileSharesCapacityGb(v interface{}, d TerraformResou
return v, nil
}

func expandFilestoreInstanceFileSharesNfsExportOptions(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
req := make([]interface{}, 0, len(l))
for _, raw := range l {
if raw == nil {
continue
}
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedIpRanges, err := expandFilestoreInstanceFileSharesNfsExportOptionsIpRanges(original["ip_ranges"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedIpRanges); val.IsValid() && !isEmptyValue(val) {
transformed["ipRanges"] = transformedIpRanges
}

transformedAccessMode, err := expandFilestoreInstanceFileSharesNfsExportOptionsAccessMode(original["access_mode"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedAccessMode); val.IsValid() && !isEmptyValue(val) {
transformed["accessMode"] = transformedAccessMode
}

transformedSquashMode, err := expandFilestoreInstanceFileSharesNfsExportOptionsSquashMode(original["squash_mode"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedSquashMode); val.IsValid() && !isEmptyValue(val) {
transformed["squashMode"] = transformedSquashMode
}

transformedAnonUid, err := expandFilestoreInstanceFileSharesNfsExportOptionsAnonUid(original["anon_uid"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedAnonUid); val.IsValid() && !isEmptyValue(val) {
transformed["anonUid"] = transformedAnonUid
}

transformedAnonGid, err := expandFilestoreInstanceFileSharesNfsExportOptionsAnonGid(original["anon_gid"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedAnonGid); val.IsValid() && !isEmptyValue(val) {
transformed["anonGid"] = transformedAnonGid
}

req = append(req, transformed)
}
return req, nil
}

func expandFilestoreInstanceFileSharesNfsExportOptionsIpRanges(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandFilestoreInstanceFileSharesNfsExportOptionsAccessMode(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandFilestoreInstanceFileSharesNfsExportOptionsSquashMode(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandFilestoreInstanceFileSharesNfsExportOptionsAnonUid(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandFilestoreInstanceFileSharesNfsExportOptionsAnonGid(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandFilestoreInstanceNetworks(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
req := make([]interface{}, 0, len(l))
Expand Down
53 changes: 53 additions & 0 deletions google-beta/resource_filestore_instance_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,59 @@ resource "google_filestore_instance" "instance" {
`, context)
}

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

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

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProvidersOiCS,
CheckDestroy: testAccCheckFilestoreInstanceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccFilestoreInstance_filestoreInstanceFullExample(context),
},
},
})
}

func testAccFilestoreInstance_filestoreInstanceFullExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_filestore_instance" "instance" {
name = "tf-test-test-instance%{random_suffix}"
zone = "us-central1-b"
tier = "BASIC_SSD"
file_shares {
capacity_gb = 2660
name = "share1"
nfs_export_options {
ip_ranges = ["10.0.0.0/24"]
access_mode = "READ_WRITE"
squash_mode = "NO_ROOT_SQUASH"
}
nfs_export_options {
ip_ranges = ["10.10.0.0/24"]
access_mode = "READ_ONLY"
squash_mode = "ROOT_SQUASH"
anon_uid = 123
anon_gid = 456
}
}
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
4 changes: 2 additions & 2 deletions google-beta/resource_filestore_instance_sweeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func testSweepFilestoreInstance(region string) error {
},
}

listTemplate := strings.Split("https://file.googleapis.com/v1/projects/{{project}}/locations/{{zone}}/instances", "?")[0]
listTemplate := strings.Split("https://file.googleapis.com/v1beta1/projects/{{project}}/locations/{{zone}}/instances", "?")[0]
listUrl, err := replaceVars(d, config, listTemplate)
if err != nil {
log.Printf("[INFO][SWEEPER_LOG] error preparing sweeper list url: %s", err)
Expand Down Expand Up @@ -99,7 +99,7 @@ func testSweepFilestoreInstance(region string) error {
continue
}

deleteTemplate := "https://file.googleapis.com/v1/projects/{{project}}/locations/{{zone}}/instances/{{name}}"
deleteTemplate := "https://file.googleapis.com/v1beta1/projects/{{project}}/locations/{{zone}}/instances/{{name}}"
deleteUrl, err := replaceVars(d, config, deleteTemplate)
if err != nil {
log.Printf("[INFO][SWEEPER_LOG] error preparing delete url: %s", err)
Expand Down
Loading

0 comments on commit 9d4a63e

Please sign in to comment.