Skip to content

Commit

Permalink
Filestore enterprise support (GoogleCloudPlatform#5450)
Browse files Browse the repository at this point in the history
* Move tier to string

* Add note on possible values

* Add note for beta-only on enterprise

* Starting to move to location

* Add precreate

* Write state migration

* Use location in examples

* Use upgrade state function instead of migrate

* Fix linter

* Update validator test to use location

* Update TFV test config to use location
  • Loading branch information
slevenick authored and betsy-lichtenberg committed Apr 25, 2022
1 parent b4e77f1 commit 145d122
Show file tree
Hide file tree
Showing 10 changed files with 285 additions and 31 deletions.
32 changes: 19 additions & 13 deletions mmv1/products/filestore/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ async: !ruby/object:Api::OpAsync
objects:
- !ruby/object:Api::Resource
name: 'Instance'
create_url: projects/{{project}}/locations/{{zone}}/instances?instanceId={{name}}
self_link: projects/{{project}}/locations/{{zone}}/instances/{{name}}
base_url: projects/{{project}}/locations/{{zone}}/instances
create_url: projects/{{project}}/locations/{{location}}/instances?instanceId={{name}}
self_link: projects/{{project}}/locations/{{location}}/instances/{{name}}
base_url: projects/{{project}}/locations/{{location}}/instances
update_verb: :PATCH
update_mask: true
description: |
Expand All @@ -69,7 +69,19 @@ objects:
name: 'zone'
description: |
The name of the Filestore zone of the instance.
required: true
deprecation_message: "Deprecated in favor of location."
exactly_one_of:
- 'zone'
- 'location'
input: true
url_param_only: true
- !ruby/object:Api::Type::String
name: 'location'
description: |
The name of the location of the instance. This can be a region for ENTERPRISE tier instances.
exactly_one_of:
- zone
- location
input: true
url_param_only: true
properties:
Expand All @@ -79,7 +91,7 @@ objects:
The resource name of the instance.
required: true
url_param_only: true
pattern: projects/{{project}}/locations/{{zone}}/instances/{{name}}
pattern: projects/{{project}}/locations/{{location}}/instances/{{name}}
- !ruby/object:Api::Type::String
name: 'description'
description: |
Expand All @@ -100,19 +112,13 @@ objects:
name: 'createTime'
description: Creation timestamp in RFC3339 text format.
output: true
- !ruby/object:Api::Type::Enum
- !ruby/object:Api::Type::String
name: 'tier'
description: |
The service tier of the instance.
Possible values include: STANDARD, PREMIUM, BASIC_HDD, BASIC_SSD, HIGH_SCALE_SSD and ENTERPRISE (beta only)
required: true
input: true
values:
- :TIER_UNSPECIFIED
- :STANDARD
- :PREMIUM
- :BASIC_HDD
- :BASIC_SSD
- :HIGH_SCALE_SSD
- !ruby/object:Api::Type::KeyValuePairs
name: 'labels'
description: |
Expand Down
6 changes: 6 additions & 0 deletions mmv1/products/filestore/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides
update_minutes: 6
delete_minutes: 6
autogen_async: true
schema_version: 1
examples:
- !ruby/object:Provider::Terraform::Examples
name: "filestore_instance_basic"
Expand All @@ -38,12 +39,17 @@ overrides: !ruby/object:Overrides::ResourceOverrides
custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.erb'
zone: !ruby/object:Overrides::Terraform::PropertyOverride
ignore_read: true
default_from_api: true
location: !ruby/object:Overrides::Terraform::PropertyOverride
ignore_read: true
default_from_api: true
networks.reservedIpRange: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
networks.connectMode: !ruby/object:Overrides::Terraform::PropertyOverride
custom_flatten: 'templates/terraform/custom_flatten/default_if_empty.erb'
custom_code: !ruby/object:Provider::Terraform::CustomCode
constants: templates/terraform/constants/filestore.erb
pre_create: templates/terraform/pre_create/filestore_instance.go.erb

# This is for copying files over
files: !ruby/object:Provider::Config::Files
Expand Down
4 changes: 4 additions & 0 deletions mmv1/templates/terraform/constants/filestore.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<%# We have to change the name of 'file' to 'filestore' for magic-modules generation reasons.-%>
import (
<% if version == "ga" -%>
filestore "google.golang.org/api/file/v1beta1"
<% else -%>
filestore "google.golang.org/api/file/v1"
<% end -%>
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
resource "google_filestore_instance" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]["instance_name"] %>"
zone = "us-central1-b"
location = "us-central1-b"
tier = "PREMIUM"

file_shares {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
resource "google_filestore_instance" "<%= ctx[:primary_resource_id] %>" {
provider = google-beta
name = "<%= ctx[:vars]["instance_name"] %>"
zone = "us-central1-b"
location = "us-central1-b"
tier = "BASIC_SSD"

file_shares {
Expand Down
17 changes: 17 additions & 0 deletions mmv1/templates/terraform/pre_create/filestore_instance.go.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
if d.Get("location") == "" {
zone, err := getZone(d, config)
if err != nil {
return err
}
err = d.Set("location", zone)
if err != nil {
return err
}
}
if strings.Contains(url, "locations//") {
// re-compute url now that location must be set
url, err = replaceVars(d, config, "<%= "{{#{object.__product.name}BasePath}}#{object.create_uri}" -%>")
if err != nil {
return err
}
}
188 changes: 188 additions & 0 deletions mmv1/templates/terraform/state_migrations/filestore_instance.go.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
func resourceFilestoreInstanceResourceV0() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"file_shares": {
Type: schema.TypeList,
Required: true,
Description: `File system shares on the instance. For this version, only a
single file share is supported.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"capacity_gb": {
Type: schema.TypeInt,
Required: true,
Description: `File share capacity in GiB. This must be at least 1024 GiB
for the standard tier, or 2560 GiB for the premium tier.`,
},
"name": {
Type: schema.TypeString,
Required: true,
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",
},
},
},
},
},
},
},
"name": {
Type: schema.TypeString,
Required: true,
Description: `The resource name of the instance.`,
},
"networks": {
Type: schema.TypeList,
Required: true,
ForceNew: true,
Description: `VPC networks to which the instance is connected. For this version,
only a single network is supported.`,
MinItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"modes": {
Type: schema.TypeList,
Required: true,
ForceNew: true,
Description: `IP versions for which the instance has
IP addresses assigned. Possible values: ["ADDRESS_MODE_UNSPECIFIED", "MODE_IPV4", "MODE_IPV6"]`,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{"ADDRESS_MODE_UNSPECIFIED", "MODE_IPV4", "MODE_IPV6"}, false),
},
},
"network": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `The name of the GCE VPC network to which the
instance is connected.`,
},
"connect_mode": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{"DIRECT_PEERING", "PRIVATE_SERVICE_ACCESS", ""}, false),
Description: `The network connect mode of the Filestore instance.
If not provided, the connect mode defaults to
DIRECT_PEERING. Default value: "DIRECT_PEERING" Possible values: ["DIRECT_PEERING", "PRIVATE_SERVICE_ACCESS"]`,
Default: "DIRECT_PEERING",
},
"reserved_ip_range": {
Type: schema.TypeString,
Computed: true,
Optional: true,
Description: `A /29 CIDR block that identifies the range of IP
addresses reserved for this instance.`,
},
"ip_addresses": {
Type: schema.TypeList,
Computed: true,
Description: `A list of IPv4 or IPv6 addresses.`,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
"tier": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
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,
Required: true,
ForceNew: true,
Description: `The name of the Filestore zone of the instance.`,
},
"description": {
Type: schema.TypeString,
Optional: true,
Description: `A description of the instance.`,
},
"labels": {
Type: schema.TypeMap,
Optional: true,
Description: `Resource labels to represent user-provided metadata.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"create_time": {
Type: schema.TypeString,
Computed: true,
Description: `Creation timestamp in RFC3339 text format.`,
},
"etag": {
Type: schema.TypeString,
Computed: true,
Description: `Server-specified ETag for the instance resource to prevent
simultaneous updates from overwriting each other.`,
},
"project": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
},
}
}

func resourceFilestoreInstanceUpgradeV0(_ context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {
log.Printf("[DEBUG] Attributes before migration: %#v", rawState)

rawState["location"] = rawState["zone"]
log.Printf("[DEBUG] Attributes after migration: %#v", rawState)
return rawState, nil
}
Loading

0 comments on commit 145d122

Please sign in to comment.