diff --git a/build/terraform b/build/terraform index b85473619c6e..5bc1050045b8 160000 --- a/build/terraform +++ b/build/terraform @@ -1 +1 @@ -Subproject commit b85473619c6e985f3cbe5438bb14b908f541bdc4 +Subproject commit 5bc1050045b86fef2a13fa8f9b784a166bd58806 diff --git a/products/redis/api.yaml b/products/redis/api.yaml index e4e94d1f1cc8..6ec5b1551f87 100644 --- a/products/redis/api.yaml +++ b/products/redis/api.yaml @@ -27,6 +27,7 @@ objects: base_url: | projects/{{project}}/locations/{{region}}/instances?instanceId={{name}} self_link: projects/{{project}}/locations/{{region}}/instances/{{name}} + update_verb: :PATCH description: | A Google Cloud Redis instance. references: !ruby/object:Api::Resource::ReferenceLinks @@ -34,7 +35,6 @@ objects: 'Official Documentation': 'https://cloud.google.com/memorystore/docs/redis/' api: 'https://cloud.google.com/memorystore/docs/redis/reference/rest/' - input: true # TODO(danawillow): support for updates <%= # Cloud Redis takes a fair bit of time to provision, try six minutes. indent(compile_file({timeouts: { insert_sec: 6 * 60 }}, @@ -46,6 +46,7 @@ objects: description: | The name of the Redis region of the instance. required: true + input: true properties: - !ruby/object:Api::Type::String name: alternativeLocationId @@ -54,12 +55,14 @@ objects: against zonal failures by provisioning it across two zones. If provided, it must be a different zone from the one provided in [locationId]. + input: true - !ruby/object:Api::Type::String name: authorizedNetwork description: | The full name of the Google Compute Engine network to which the instance is connected. If left unspecified, the default network will be used. + input: true - !ruby/object:Api::Type::Time name: createTime description: | @@ -75,6 +78,7 @@ objects: instances, this can be either [locationId] or [alternativeLocationId] and can change after a failover event. output: true + input: true - !ruby/object:Api::Type::String name: displayName description: | @@ -98,11 +102,13 @@ objects: instances will be created across two zones for protection against zonal failures. If [alternativeLocationId] is also provided, it must be different from [locationId]. + input: true - !ruby/object:Api::Type::String name: name description: | The ID of the instance or a fully qualified identifier for the instance. required: true + input: true - !ruby/object:Api::Type::Integer name: memorySizeGb description: Redis memory size in GiB. @@ -118,6 +124,7 @@ objects: version will be used. Updating the version will perform an upgrade/downgrade to the new version. Currently, the supported values are REDIS_3_2 for Redis 3.2. + input: true - !ruby/object:Api::Type::String name: reservedIpRange description: | @@ -126,6 +133,7 @@ objects: block, for example, 10.0.0.0/29 or 192.168.0.0/29. Ranges must be unique and non-overlapping with existing subnets in an authorized network. + input: true - !ruby/object:Api::Type::Enum name: tier description: | @@ -137,3 +145,4 @@ objects: - :BASIC - :STANDARD_HA default_value: :BASIC + input: true diff --git a/products/redis/terraform.yaml b/products/redis/terraform.yaml index e66cce188ecc..fcf48a1565ad 100644 --- a/products/redis/terraform.yaml +++ b/products/redis/terraform.yaml @@ -20,6 +20,7 @@ overrides: !ruby/object:Provider::ResourceOverrides custom_code: !ruby/object:Provider::Terraform::CustomCode decoder: 'templates/terraform/decoders/redis_instance.erb' encoder: 'templates/terraform/encoders/redis_instance.erb' + pre_update: 'templates/terraform/pre_update/redis_instance.erb' examples: | ### Basic Usage ```hcl diff --git a/templates/terraform/pre_update/redis_instance.erb b/templates/terraform/pre_update/redis_instance.erb new file mode 100644 index 000000000000..0e0bd0d57817 --- /dev/null +++ b/templates/terraform/pre_update/redis_instance.erb @@ -0,0 +1,16 @@ +updateMask := []string{} +if d.HasChange("display_name") { + updateMask = append(updateMask, "displayName") +} +if d.HasChange("labels") { + updateMask = append(updateMask, "labels") +} +if d.HasChange("memory_size_gb") { + updateMask = append(updateMask, "memorySizeGb") +} +// updateMask is a URL parameter but not present in the schema, so replaceVars +// won't set it +url, err = addQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")}) +if err != nil { + return err +} diff --git a/templates/terraform/transport.go b/templates/terraform/transport.go index 32a4765f3341..ea931843ef2d 100644 --- a/templates/terraform/transport.go +++ b/templates/terraform/transport.go @@ -106,15 +106,12 @@ func sendRequest(config *Config, method, rawurl string, body map[string]interfac } } - u, err := url.Parse(rawurl) + u, err := addQueryParams(rawurl, map[string]string{"alt": "json"}) if err != nil { return nil, err } - q := u.Query() - q.Set("alt", "json") - u.RawQuery = q.Encode() - req, err := http.NewRequest(method, u.String(), &buf) + req, err := http.NewRequest(method, u, &buf) if err != nil { return nil, err } @@ -136,6 +133,19 @@ func sendRequest(config *Config, method, rawurl string, body map[string]interfac return result, nil } +func addQueryParams(rawurl string, params map[string]string) (string, error) { + u, err := url.Parse(rawurl) + if err != nil { + return "", err + } + q := u.Query() + for k, v := range params { + q.Set(k, v) + } + u.RawQuery = q.Encode() + return u.String(), nil +} + func replaceVars(d TerraformResourceData, config *Config, linkTmpl string) (string, error) { re := regexp.MustCompile("{{([[:word:]]+)}}") var project, region, zone string