From 49ae8323479007675f87298af3b040d30e9d7f02 Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Tue, 14 Nov 2023 17:18:11 +0000 Subject: [PATCH] Add memcached-1.6.15 to the list of allowed memcache versions (#9375) [upstream:905133647a32023e4aab64b0336b3f265f563295] Signed-off-by: Modular Magician --- .changelog/9375.txt | 3 + .../memcache/resource_memcache_instance.go | 60 +++++++++++++++---- .../resource_memcache_instance_test.go | 2 + .../docs/r/memcache_instance.html.markdown | 2 +- 4 files changed, 54 insertions(+), 13 deletions(-) create mode 100644 .changelog/9375.txt diff --git a/.changelog/9375.txt b/.changelog/9375.txt new file mode 100644 index 0000000000..2fc3758dff --- /dev/null +++ b/.changelog/9375.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +memcache: added `MEMCACHE_1_6_15` as a possible value for `memcache_version` in `google_memcache_instance` +``` diff --git a/google-beta/services/memcache/resource_memcache_instance.go b/google-beta/services/memcache/resource_memcache_instance.go index ebf493678b..786b60b45a 100644 --- a/google-beta/services/memcache/resource_memcache_instance.go +++ b/google-beta/services/memcache/resource_memcache_instance.go @@ -237,10 +237,10 @@ resolution and up to nine fractional digits.`, "memcache_version": { Type: schema.TypeString, Optional: true, - ValidateFunc: verify.ValidateEnum([]string{"MEMCACHE_1_5", ""}), + ValidateFunc: verify.ValidateEnum([]string{"MEMCACHE_1_5", "MEMCACHE_1_6_15", ""}), Description: `The major version of Memcached software. If not provided, latest supported version will be used. Currently the latest supported major version is MEMCACHE_1_5. The minor version will be automatically -determined by our system based on the latest supported minor version. Default value: "MEMCACHE_1_5" Possible values: ["MEMCACHE_1_5"]`, +determined by our system based on the latest supported minor version. Default value: "MEMCACHE_1_5" Possible values: ["MEMCACHE_1_5", "MEMCACHE_1_6_15"]`, Default: "MEMCACHE_1_5", }, "region": { @@ -613,12 +613,6 @@ func resourceMemcacheInstanceUpdate(d *schema.ResourceData, meta interface{}) er } else if v, ok := d.GetOkExists("node_count"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, nodeCountProp)) { obj["nodeCount"] = nodeCountProp } - memcacheVersionProp, err := expandMemcacheInstanceMemcacheVersion(d.Get("memcache_version"), d, config) - if err != nil { - return err - } else if v, ok := d.GetOkExists("memcache_version"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, memcacheVersionProp)) { - obj["memcacheVersion"] = memcacheVersionProp - } maintenancePolicyProp, err := expandMemcacheInstanceMaintenancePolicy(d.Get("maintenance_policy"), d, config) if err != nil { return err @@ -648,10 +642,6 @@ func resourceMemcacheInstanceUpdate(d *schema.ResourceData, meta interface{}) er updateMask = append(updateMask, "nodeCount") } - if d.HasChange("memcache_version") { - updateMask = append(updateMask, "memcacheVersion") - } - if d.HasChange("maintenance_policy") { updateMask = append(updateMask, "maintenancePolicy") } @@ -697,6 +687,52 @@ func resourceMemcacheInstanceUpdate(d *schema.ResourceData, meta interface{}) er return err } } + d.Partial(true) + + if d.HasChange("memcache_version") { + obj := make(map[string]interface{}) + + memcacheVersionProp, err := expandMemcacheInstanceMemcacheVersion(d.Get("memcache_version"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("memcache_version"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, memcacheVersionProp)) { + obj["memcacheVersion"] = memcacheVersionProp + } + + url, err := tpgresource.ReplaceVars(d, config, "{{MemcacheBasePath}}projects/{{project}}/locations/{{region}}/instances/{{name}}:upgrade") + if err != nil { + return err + } + + // err == nil indicates that the billing_project value was found + if bp, err := tpgresource.GetBillingProject(d, config); err == nil { + billingProject = bp + } + + res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "POST", + Project: billingProject, + RawURL: url, + UserAgent: userAgent, + Body: obj, + Timeout: d.Timeout(schema.TimeoutUpdate), + }) + if err != nil { + return fmt.Errorf("Error updating Instance %q: %s", d.Id(), err) + } else { + log.Printf("[DEBUG] Finished updating Instance %q: %#v", d.Id(), res) + } + + err = MemcacheOperationWaitTime( + config, res, project, "Updating Instance", userAgent, + d.Timeout(schema.TimeoutUpdate)) + if err != nil { + return err + } + } + + d.Partial(false) return resourceMemcacheInstanceRead(d, meta) } diff --git a/google-beta/services/memcache/resource_memcache_instance_test.go b/google-beta/services/memcache/resource_memcache_instance_test.go index 956084a9be..14531420dc 100644 --- a/google-beta/services/memcache/resource_memcache_instance_test.go +++ b/google-beta/services/memcache/resource_memcache_instance_test.go @@ -88,6 +88,8 @@ resource "google_memcache_instance" "test" { "max-item-size" = "8388608" } } + + memcache_version = "MEMCACHE_1_6_15" } data "google_compute_network" "memcache_network" { diff --git a/website/docs/r/memcache_instance.html.markdown b/website/docs/r/memcache_instance.html.markdown index 4cce889efa..5b64e4fe18 100644 --- a/website/docs/r/memcache_instance.html.markdown +++ b/website/docs/r/memcache_instance.html.markdown @@ -147,7 +147,7 @@ The following arguments are supported: Currently the latest supported major version is MEMCACHE_1_5. The minor version will be automatically determined by our system based on the latest supported minor version. Default value is `MEMCACHE_1_5`. - Possible values are: `MEMCACHE_1_5`. + Possible values are: `MEMCACHE_1_5`, `MEMCACHE_1_6_15`. * `memcache_parameters` - (Optional)