Skip to content

Commit 68ad896

Browse files
committed
Add autoscale settings to pc management cluster
1 parent b0450ba commit 68ad896

File tree

4 files changed

+237
-5
lines changed

4 files changed

+237
-5
lines changed

mmv1/products/vmwareengine/PrivateCloud.yaml

+116
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,122 @@ properties:
218218
type: String
219219
description: |
220220
Additional zone for a higher level of availability and load balancing.
221+
- name: 'autoscalingSettings'
222+
type: NestedObject
223+
description: |
224+
Configuration of the autoscaling applied to this cluster
225+
properties:
226+
- name: 'autoscalingPolicies'
227+
type: Map
228+
required: true
229+
description: |
230+
The map with autoscaling policies applied to the cluster.
231+
The key is the identifier of the policy.
232+
It must meet the following requirements:
233+
* Only contains 1-63 alphanumeric characters and hyphens
234+
* Begins with an alphabetical character
235+
* Ends with a non-hyphen character
236+
* Not formatted as a UUID
237+
* Complies with [RFC 1034](https://datatracker.ietf.org/doc/html/rfc1034) (section 3.5)
238+
239+
Currently there map must contain only one element
240+
that describes the autoscaling policy for compute nodes.
241+
key_name: 'autoscale_policy_id'
242+
key_description: 'The key is the identifier of the policy.'
243+
value_type:
244+
name: AutoscalingPolicy
245+
type: NestedObject
246+
properties:
247+
- name: 'nodeTypeId'
248+
type: String
249+
required: true
250+
description: |
251+
The canonical identifier of the node type to add or remove.
252+
- name: 'scaleOutSize'
253+
type: Integer
254+
required: true
255+
description: |
256+
Number of nodes to add to a cluster during a scale-out operation.
257+
Must be divisible by 2 for stretched clusters.
258+
- name: 'minNodeCount'
259+
type: Integer
260+
description: |
261+
Minimum number of nodes of the given type in a cluster.
262+
The number is coerced to the minimum number of nodes of any type in the cluster.
263+
- name: 'maxNodeCount'
264+
type: Integer
265+
description: |
266+
Maximum number of nodes of the given type in a cluster.
267+
The number is coerced to the maximum number of nodes of any type in the cluster.
268+
- name: 'cpuThresholds'
269+
type: NestedObject
270+
description: |
271+
Utilization thresholds pertaining to CPU utilization.
272+
properties:
273+
- name: 'scaleOut'
274+
type: Integer
275+
description: |
276+
The utilization triggering the scale-out operation in percent.
277+
- name: 'scaleIn'
278+
type: Integer
279+
description: |
280+
The utilization triggering the scale-in operation in percent.
281+
- name: 'grantedMemoryThresholds'
282+
type: NestedObject
283+
description: |
284+
Utilization thresholds pertaining to amount of granted memory.
285+
properties:
286+
- name: 'scaleOut'
287+
type: Integer
288+
description: |
289+
The utilization triggering the scale-out operation in percent.
290+
- name: 'scaleIn'
291+
type: Integer
292+
description: |
293+
The utilization triggering the scale-in operation in percent.
294+
- name: 'consumedMemoryThresholds'
295+
type: NestedObject
296+
description: |
297+
Utilization thresholds pertaining to amount of consumed memory.
298+
properties:
299+
- name: 'scaleOut'
300+
type: Integer
301+
description: |
302+
The utilization triggering the scale-out operation in percent.
303+
- name: 'scaleIn'
304+
type: Integer
305+
description: |
306+
The utilization triggering the scale-in operation in percent.
307+
- name: 'storageThresholds'
308+
type: NestedObject
309+
description: |
310+
Utilization thresholds pertaining to amount of consumed storage.
311+
properties:
312+
- name: 'scaleOut'
313+
type: Integer
314+
description: |
315+
The utilization triggering the scale-out operation in percent.
316+
- name: 'scaleIn'
317+
type: Integer
318+
description: |
319+
The utilization triggering the scale-in operation in percent.
320+
- name: 'minClusterNodeCount'
321+
type: Integer
322+
description: |
323+
Minimum number of nodes of any type in a cluster.
324+
If not specified the default limits apply.
325+
- name: 'maxClusterNodeCount'
326+
type: Integer
327+
description: |
328+
Maximum number of nodes of any type in a cluster.
329+
If not specified the default limits apply.
330+
- name: 'coolDownPeriod'
331+
type: String
332+
description: |
333+
The minimum duration between consecutive autoscale operations.
334+
It starts once addition or removal of nodes is fully completed.
335+
Defaults to 30m if not specified.
336+
Cool down period must be in whole minutes (for example, 30m, 31m, 50m).
221337
- name: 'hcx'
222338
type: NestedObject
223339
description: |

mmv1/templates/terraform/examples/vmware_engine_private_cloud_full.tf.tmpl

+24
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,30 @@ resource "google_vmwareengine_private_cloud" "{{$.PrimaryResourceId}}" {
1414
node_count = 1
1515
custom_core_count = 32
1616
}
17+
autoscaling_settings {
18+
autoscaling_policies {
19+
autoscale_policy_id = "autoscaling-policy"
20+
node_type_id = "standard-72"
21+
scale_out_size = 1
22+
min_node_count = 3
23+
max_node_count = 8
24+
cpu_thresholds {
25+
scale_out = 80
26+
scale_in = 10
27+
}
28+
consumed_memory_thresholds {
29+
scale_out = 90
30+
scale_in = 10
31+
}
32+
storage_thresholds {
33+
scale_out = 80
34+
scale_in = 20
35+
}
36+
}
37+
min_cluster_node_count = 3
38+
max_cluster_node_count = 8
39+
cool_down_period = "1800s"
40+
}
1741
}
1842
deletion_delay_hours = 0
1943
send_deletion_delay_hours_if_zero = true

mmv1/templates/terraform/post_update/private_cloud.go.tmpl

+2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ clusterObj := make(map[string]interface{})
1515

1616
if v, ok := d.GetOkExists("management_cluster"); !tpgresource.IsEmptyValue(reflect.ValueOf(mgmtClusterProp)) && (ok || !reflect.DeepEqual(v, mgmtClusterProp)) {
1717
clusterObj["nodeTypeConfigs"] = mgmtMap["nodeTypeConfigs"]
18+
clusterObj["autoscalingSettings"] = mgmtMap["autoscalingSettings"]
1819
}
1920

2021
if d.HasChange("management_cluster") {
2122
clusterUpdateMask = append(clusterUpdateMask, "nodeTypeConfigs.*.nodeCount")
23+
clusterUpdateMask = append(clusterUpdateMask, "autoscalingSettings")
2224
}
2325

2426
clusterPatchUrl, err := transport_tpg.AddQueryParams(clusterUrl, map[string]string{"updateMask": strings.Join(clusterUpdateMask, ",")})

mmv1/third_party/terraform/services/vmwareengine/resource_vmwareengine_private_cloud_test.go

+95-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
13
package vmwareengine_test
24

35
import (
@@ -55,7 +57,27 @@ func TestAccVmwareenginePrivateCloud_vmwareEnginePrivateCloudUpdate(t *testing.T
5557
},
5658

5759
{
58-
Config: testVmwareenginePrivateCloudUpdateConfig(context),
60+
Config: testVmwareenginePrivateCloudUpdateNodeConfig(context),
61+
Check: resource.ComposeTestCheckFunc(
62+
acctest.CheckDataSourceStateMatchesResourceStateWithIgnores(
63+
"data.google_vmwareengine_private_cloud.ds",
64+
"google_vmwareengine_private_cloud.vmw-engine-pc",
65+
map[string]struct{}{
66+
"type": {},
67+
"deletion_delay_hours": {},
68+
"send_deletion_delay_hours_if_zero": {},
69+
}),
70+
),
71+
},
72+
{
73+
ResourceName: "google_vmwareengine_private_cloud.vmw-engine-pc",
74+
ImportState: true,
75+
ImportStateVerify: true,
76+
ImportStateVerifyIgnore: []string{"location", "name", "update_time", "type", "deletion_delay_hours", "send_deletion_delay_hours_if_zero"},
77+
},
78+
79+
{
80+
Config: testVmwareenginePrivateCloudUpdateAutoscaleConfig(context),
5981
Check: resource.ComposeTestCheckFunc(
6082
acctest.CheckDataSourceStateMatchesResourceStateWithIgnores(
6183
"data.google_vmwareengine_private_cloud.ds",
@@ -134,24 +156,28 @@ func testVmwareenginePrivateCloudCreateConfig(context map[string]interface{}) st
134156
return testVmwareenginePrivateCloudConfig(context, "sample description", "TIME_LIMITED", 1, 1) + testVmwareengineVcenterNSXCredentailsConfig(context)
135157
}
136158

137-
func testVmwareenginePrivateCloudUpdateConfig(context map[string]interface{}) string {
159+
func testVmwareenginePrivateCloudUpdateNodeConfig(context map[string]interface{}) string {
138160
return testVmwareenginePrivateCloudConfig(context, "sample updated description", "STANDARD", 3, 8) + testVmwareengineVcenterNSXCredentailsConfig(context)
139161
}
140162

163+
func testVmwareenginePrivateCloudUpdateAutoscaleConfig(context map[string]interface{}) string {
164+
return testVmwareenginePrivateCloudAutoscaleConfig(context, "sample updated description", "STANDARD", 3, 8) + testVmwareengineVcenterNSXCredentailsConfig(context)
165+
}
166+
141167
func testVmwareenginePrivateCloudDelayedDeleteConfig(context map[string]interface{}) string {
142168
return testVmwareenginePrivateCloudDeletedConfig(context)
143169
}
144170

145171
func testVmwareenginePrivateCloudUndeleteConfig(context map[string]interface{}) string {
146-
return testVmwareenginePrivateCloudConfig(context, "sample updated description", "STANDARD", 3, 0) + testVmwareengineVcenterNSXCredentailsConfig(context)
172+
return testVmwareenginePrivateCloudAutoscaleConfig(context, "sample updated description", "STANDARD", 3, 0) + testVmwareengineVcenterNSXCredentailsConfig(context)
147173
}
148174

149175
func testVmwareengineSubnetImportConfig(context map[string]interface{}) string {
150-
return testVmwareenginePrivateCloudConfig(context, "sample updated description", "STANDARD", 3, 0) + testVmwareengineSubnetConfig(context, "192.168.1.0/26")
176+
return testVmwareenginePrivateCloudAutoscaleConfig(context, "sample updated description", "STANDARD", 3, 0) + testVmwareengineSubnetConfig(context, "192.168.1.0/26")
151177
}
152178

153179
func testVmwareengineSubnetUpdateConfig(context map[string]interface{}) string {
154-
return testVmwareenginePrivateCloudConfig(context, "sample updated description", "STANDARD", 3, 0) + testVmwareengineSubnetConfig(context, "192.168.2.0/26")
180+
return testVmwareenginePrivateCloudAutoscaleConfig(context, "sample updated description", "STANDARD", 3, 0) + testVmwareengineSubnetConfig(context, "192.168.2.0/26")
155181
}
156182

157183
func testVmwareenginePrivateCloudConfig(context map[string]interface{}, description, pcType string, nodeCount, delayHours int) string {
@@ -198,6 +224,70 @@ data "google_vmwareengine_private_cloud" "ds" {
198224
`, context)
199225
}
200226

227+
func testVmwareenginePrivateCloudAutoscaleConfig(context map[string]interface{}, description, pcType string, nodeCount, delayHours int) string {
228+
context["node_count"] = nodeCount
229+
context["delay_hrs"] = delayHours
230+
context["description"] = description
231+
context["type"] = pcType
232+
return acctest.Nprintf(`
233+
resource "google_vmwareengine_network" "vmw-engine-nw" {
234+
name = "tf-test-pc-nw-%{random_suffix}"
235+
location = "global"
236+
type = "STANDARD"
237+
description = "PC network description."
238+
}
239+
240+
resource "google_vmwareengine_private_cloud" "vmw-engine-pc" {
241+
location = "%{region}-b"
242+
name = "tf-test-sample-pc%{random_suffix}"
243+
description = "%{description}"
244+
type = "%{type}"
245+
deletion_delay_hours = "%{delay_hrs}"
246+
send_deletion_delay_hours_if_zero = true
247+
network_config {
248+
management_cidr = "192.168.0.0/24"
249+
vmware_engine_network = google_vmwareengine_network.vmw-engine-nw.id
250+
}
251+
management_cluster {
252+
cluster_id = "tf-test-sample-mgmt-cluster-custom-core-count%{random_suffix}"
253+
node_type_configs {
254+
node_type_id = "standard-72"
255+
node_count = "%{node_count}"
256+
custom_core_count = 32
257+
}
258+
autoscaling_settings {
259+
autoscaling_policies {
260+
autoscale_policy_id = "autoscaling-policy"
261+
node_type_id = "standard-72"
262+
scale_out_size = 1
263+
min_node_count = 3
264+
max_node_count = 8
265+
cpu_thresholds {
266+
scale_out = 80
267+
scale_in = 10
268+
}
269+
storage_thresholds {
270+
scale_out = 80
271+
scale_in = 20
272+
}
273+
}
274+
min_cluster_node_count = 3
275+
max_cluster_node_count = 8
276+
cool_down_period = "1800s"
277+
}
278+
}
279+
}
280+
281+
data "google_vmwareengine_private_cloud" "ds" {
282+
location = "%{region}-b"
283+
name = "tf-test-sample-pc%{random_suffix}"
284+
depends_on = [
285+
google_vmwareengine_private_cloud.vmw-engine-pc,
286+
]
287+
}
288+
`, context)
289+
}
290+
201291
func testVmwareenginePrivateCloudDeletedConfig(context map[string]interface{}) string {
202292
return acctest.Nprintf(`
203293
resource "google_vmwareengine_network" "vmw-engine-nw" {

0 commit comments

Comments
 (0)