Skip to content

Commit 95b5cc5

Browse files
Support apigee environment properties update (#12794) (#9107)
[upstream:4601a9407ad1ad40daee1b3a1f0efe983211b307] Signed-off-by: Modular Magician <[email protected]>
1 parent 89ece64 commit 95b5cc5

File tree

2 files changed

+35
-49
lines changed

2 files changed

+35
-49
lines changed

Diff for: .changelog/12794.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note: bug
2+
apigee: fixed `properties` field update on `google_apigee_environment` resource
3+
```

Diff for: google-beta/services/apigee/resource_apigee_environment.go

+32-49
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,12 @@ func resourceApigeeEnvironmentUpdate(d *schema.ResourceData, meta interface{}) e
376376
billingProject := ""
377377

378378
obj := make(map[string]interface{})
379+
nameProp, err := expandApigeeEnvironmentName(d.Get("name"), d, config)
380+
if err != nil {
381+
return err
382+
} else if v, ok := d.GetOkExists("name"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, nameProp)) {
383+
obj["name"] = nameProp
384+
}
379385
displayNameProp, err := expandApigeeEnvironmentDisplayName(d.Get("display_name"), d, config)
380386
if err != nil {
381387
return err
@@ -388,6 +394,18 @@ func resourceApigeeEnvironmentUpdate(d *schema.ResourceData, meta interface{}) e
388394
} else if v, ok := d.GetOkExists("description"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, descriptionProp)) {
389395
obj["description"] = descriptionProp
390396
}
397+
deploymentTypeProp, err := expandApigeeEnvironmentDeploymentType(d.Get("deployment_type"), d, config)
398+
if err != nil {
399+
return err
400+
} else if v, ok := d.GetOkExists("deployment_type"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, deploymentTypeProp)) {
401+
obj["deploymentType"] = deploymentTypeProp
402+
}
403+
apiProxyTypeProp, err := expandApigeeEnvironmentApiProxyType(d.Get("api_proxy_type"), d, config)
404+
if err != nil {
405+
return err
406+
} else if v, ok := d.GetOkExists("api_proxy_type"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, apiProxyTypeProp)) {
407+
obj["apiProxyType"] = apiProxyTypeProp
408+
}
391409
nodeConfigProp, err := expandApigeeEnvironmentNodeConfig(d.Get("node_config"), d, config)
392410
if err != nil {
393411
return err
@@ -420,62 +438,27 @@ func resourceApigeeEnvironmentUpdate(d *schema.ResourceData, meta interface{}) e
420438

421439
log.Printf("[DEBUG] Updating Environment %q: %#v", d.Id(), obj)
422440
headers := make(http.Header)
423-
updateMask := []string{}
424-
425-
if d.HasChange("display_name") {
426-
updateMask = append(updateMask, "displayName")
427-
}
428-
429-
if d.HasChange("description") {
430-
updateMask = append(updateMask, "description")
431-
}
432-
433-
if d.HasChange("node_config") {
434-
updateMask = append(updateMask, "nodeConfig")
435-
}
436-
437-
if d.HasChange("type") {
438-
updateMask = append(updateMask, "type")
439-
}
440-
441-
if d.HasChange("forward_proxy_uri") {
442-
updateMask = append(updateMask, "forwardProxyUri")
443-
}
444-
445-
if d.HasChange("properties") {
446-
updateMask = append(updateMask, "properties")
447-
}
448-
// updateMask is a URL parameter but not present in the schema, so ReplaceVars
449-
// won't set it
450-
url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
451-
if err != nil {
452-
return err
453-
}
454441

455442
// err == nil indicates that the billing_project value was found
456443
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
457444
billingProject = bp
458445
}
459446

460-
// if updateMask is empty we are not updating anything so skip the post
461-
if len(updateMask) > 0 {
462-
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
463-
Config: config,
464-
Method: "PATCH",
465-
Project: billingProject,
466-
RawURL: url,
467-
UserAgent: userAgent,
468-
Body: obj,
469-
Timeout: d.Timeout(schema.TimeoutUpdate),
470-
Headers: headers,
471-
})
472-
473-
if err != nil {
474-
return fmt.Errorf("Error updating Environment %q: %s", d.Id(), err)
475-
} else {
476-
log.Printf("[DEBUG] Finished updating Environment %q: %#v", d.Id(), res)
477-
}
447+
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
448+
Config: config,
449+
Method: "PUT",
450+
Project: billingProject,
451+
RawURL: url,
452+
UserAgent: userAgent,
453+
Body: obj,
454+
Timeout: d.Timeout(schema.TimeoutUpdate),
455+
Headers: headers,
456+
})
478457

458+
if err != nil {
459+
return fmt.Errorf("Error updating Environment %q: %s", d.Id(), err)
460+
} else {
461+
log.Printf("[DEBUG] Finished updating Environment %q: %#v", d.Id(), res)
479462
}
480463

481464
return resourceApigeeEnvironmentRead(d, meta)

0 commit comments

Comments
 (0)