Skip to content

Commit 1209187

Browse files
committed
add post_create autoscale support
1 parent 4d4b21f commit 1209187

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

mmv1/products/vmwareengine/PrivateCloud.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ custom_code:
5252
update_encoder: 'templates/terraform/update_encoder/private_cloud.go.tmpl'
5353
decoder: 'templates/terraform/decoders/private_cloud.go.tmpl'
5454
pre_create: 'templates/terraform/pre_create/vmwareengine_private_cloud.go.tmpl'
55+
post_create: 'templates/terraform/post_create/private_cloud.go.tmpl'
5556
post_delete: 'templates/terraform/post_delete/private_cloud.go.tmpl'
5657
post_update: 'templates/terraform/post_update/private_cloud.go.tmpl'
5758
pre_delete: 'templates/terraform/pre_delete/vmwareengine_private_cloud.go.tmpl'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
mgmtClusterProp, err := expandVmwareenginePrivateCloudManagementCluster(d.Get("management_cluster"), d, config)
2+
if v, ok := d.GetOkExists("management_cluster"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, mgmtClusterProp)) {
3+
obj["managementCluster"] = mgmtClusterProp
4+
}
5+
6+
mgmtMap := mgmtClusterProp.(map[string]interface{})
7+
parentUrl, err := tpgresource.ReplaceVars(d, config, "{{"{{"}}VmwareengineBasePath{{"}}"}}projects/{{"{{"}}project{{"}}"}}/locations/{{"{{"}}location{{"}}"}}/privateClouds/{{"{{"}}name{{"}}"}}")
8+
if err != nil {
9+
return err
10+
}
11+
12+
clusterUrl := fmt.Sprintf("%s/clusters/%s", parentUrl, mgmtMap["clusterId"])
13+
clusterUpdateMask := []string{}
14+
clusterObj := make(map[string]interface{})
15+
16+
if v, ok := d.GetOkExists("management_cluster"); !tpgresource.IsEmptyValue(reflect.ValueOf(mgmtClusterProp)) && (ok || !reflect.DeepEqual(v, mgmtClusterProp)) {
17+
clusterObj["autoscalingSettings"] = mgmtMap["autoscalingSettings"]
18+
}
19+
20+
if d.HasChange("management_cluster") {
21+
clusterUpdateMask = append(clusterUpdateMask, "autoscalingSettings")
22+
}
23+
24+
clusterPatchUrl, err := transport_tpg.AddQueryParams(clusterUrl, map[string]string{"updateMask": strings.Join(clusterUpdateMask, ",")})
25+
if err != nil {
26+
return err
27+
}
28+
29+
// check if there is anything to update to avoid API call if not required.
30+
if len(clusterUpdateMask) > 0 {
31+
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
32+
Config: config,
33+
Method: "PATCH",
34+
Project: billingProject,
35+
RawURL: clusterPatchUrl,
36+
UserAgent: userAgent,
37+
Body: clusterObj,
38+
Timeout: d.Timeout(schema.TimeoutUpdate),
39+
})
40+
41+
if err != nil {
42+
return fmt.Errorf("Error updating magament cluster %q: %s", d.Id(), err)
43+
} else {
44+
log.Printf("[DEBUG] Finished updating magament cluster %q: %#v", d.Id(), res)
45+
}
46+
47+
err = VmwareengineOperationWaitTime(
48+
config, res, project, "Updating Managment Cluster", userAgent,
49+
d.Timeout(schema.TimeoutUpdate))
50+
51+
if err != nil {
52+
return err
53+
}
54+
}

0 commit comments

Comments
 (0)