From e04fe9795980edaf3c9250db24968fdd00f33cb8 Mon Sep 17 00:00:00 2001 From: The Magician Date: Thu, 13 May 2021 12:07:53 -0700 Subject: [PATCH] allow api gateway to change (#4782) (#3248) Signed-off-by: Modular Magician --- .changelog/4782.txt | 3 +++ google-beta/resource_api_gateway_gateway.go | 14 ++++++++++++-- google-beta/resource_api_gateway_gateway_test.go | 3 +++ website/docs/r/api_gateway_gateway.html.markdown | 3 ++- 4 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 .changelog/4782.txt diff --git a/.changelog/4782.txt b/.changelog/4782.txt new file mode 100644 index 0000000000..52683a6419 --- /dev/null +++ b/.changelog/4782.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +apigateway: allowed field `apiconfig` to change on resource `google_apigateway_gateway` +``` diff --git a/google-beta/resource_api_gateway_gateway.go b/google-beta/resource_api_gateway_gateway.go index 982e7b70ee..e160fdbb22 100644 --- a/google-beta/resource_api_gateway_gateway.go +++ b/google-beta/resource_api_gateway_gateway.go @@ -45,9 +45,9 @@ func resourceApiGatewayGateway() *schema.Resource { "api_config": { Type: schema.TypeString, Required: true, - ForceNew: true, DiffSuppressFunc: compareResourceNames, - Description: `Resource name of the API Config for this Gateway. Format: projects/{project}/locations/global/apis/{api}/configs/{apiConfig}`, + Description: `Resource name of the API Config for this Gateway. Format: projects/{project}/locations/global/apis/{api}/configs/{apiConfig}. +When changing api configs please ensure the new config is a new resource and the lifecycle rule 'create_before_destroy' is set.`, }, "gateway_id": { Type: schema.TypeString, @@ -256,6 +256,12 @@ func resourceApiGatewayGatewayUpdate(d *schema.ResourceData, meta interface{}) e } else if v, ok := d.GetOkExists("display_name"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, displayNameProp)) { obj["displayName"] = displayNameProp } + apiConfigProp, err := expandApiGatewayGatewayApiConfig(d.Get("api_config"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("api_config"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, apiConfigProp)) { + obj["apiConfig"] = apiConfigProp + } labelsProp, err := expandApiGatewayGatewayLabels(d.Get("labels"), d, config) if err != nil { return err @@ -275,6 +281,10 @@ func resourceApiGatewayGatewayUpdate(d *schema.ResourceData, meta interface{}) e updateMask = append(updateMask, "displayName") } + if d.HasChange("api_config") { + updateMask = append(updateMask, "apiConfig") + } + if d.HasChange("labels") { updateMask = append(updateMask, "labels") } diff --git a/google-beta/resource_api_gateway_gateway_test.go b/google-beta/resource_api_gateway_gateway_test.go index fb6584f15c..fa2cb747f1 100644 --- a/google-beta/resource_api_gateway_gateway_test.go +++ b/google-beta/resource_api_gateway_gateway_test.go @@ -39,6 +39,9 @@ resource "google_api_gateway_api_config" "api_gw" { provider = google-beta api = google_api_gateway_api.api_gw.api_id api_config_id = "tf-test-api-gw%{random_suffix}" + lifecycle { + create_before_destroy = true + } openapi_documents { document { diff --git a/website/docs/r/api_gateway_gateway.html.markdown b/website/docs/r/api_gateway_gateway.html.markdown index 6646e7bed8..e6058b93bd 100644 --- a/website/docs/r/api_gateway_gateway.html.markdown +++ b/website/docs/r/api_gateway_gateway.html.markdown @@ -77,7 +77,8 @@ The following arguments are supported: * `api_config` - (Required) - Resource name of the API Config for this Gateway. Format: projects/{project}/locations/global/apis/{api}/configs/{apiConfig} + Resource name of the API Config for this Gateway. Format: projects/{project}/locations/global/apis/{api}/configs/{apiConfig}. + When changing api configs please ensure the new config is a new resource and the lifecycle rule `create_before_destroy` is set. * `gateway_id` - (Required)