Skip to content

Commit

Permalink
allow api gateway to change (#4782) (#3248)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored May 13, 2021
1 parent c651102 commit e04fe97
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .changelog/4782.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
apigateway: allowed field `apiconfig` to change on resource `google_apigateway_gateway`
```
14 changes: 12 additions & 2 deletions google-beta/resource_api_gateway_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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")
}
Expand Down
3 changes: 3 additions & 0 deletions google-beta/resource_api_gateway_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion website/docs/r/api_gateway_gateway.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e04fe97

Please sign in to comment.