Skip to content

Commit 2d2351e

Browse files
committed
Add 'TestAccOpsWorksCustomLayer_loadBasedAutoScaling'.
1 parent 150868c commit 2d2351e

File tree

2 files changed

+119
-10
lines changed

2 files changed

+119
-10
lines changed

internal/service/opsworks/custom_layer_test.go

+110
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ func TestAccOpsWorksCustomLayer_basic(t *testing.T) {
5252
resource.TestCheckResourceAttr(resourceName, "elastic_load_balancer", ""),
5353
resource.TestCheckResourceAttr(resourceName, "instance_shutdown_timeout", "300"),
5454
resource.TestCheckResourceAttr(resourceName, "install_updates_on_boot", "true"),
55+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.#", "1"),
56+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.enable", "false"),
5557
resource.TestCheckResourceAttr(resourceName, "name", rName),
5658
resource.TestCheckResourceAttr(resourceName, "short_name", "tf-ops-acc-custom-layer"),
5759
resource.TestCheckResourceAttr(resourceName, "system_packages.#", "2"),
@@ -226,6 +228,76 @@ func TestAccOpsWorksCustomLayer_cloudWatch(t *testing.T) {
226228
})
227229
}
228230

231+
func TestAccOpsWorksCustomLayer_loadBasedAutoScaling(t *testing.T) {
232+
var v opsworks.Layer
233+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
234+
resourceName := "aws_opsworks_custom_layer.test"
235+
236+
resource.ParallelTest(t, resource.TestCase{
237+
PreCheck: func() { acctest.PreCheck(t); acctest.PreCheckPartitionHasService(opsworks.EndpointsID, t) },
238+
ErrorCheck: acctest.ErrorCheck(t, opsworks.EndpointsID),
239+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
240+
CheckDestroy: testAccCheckCustomLayerDestroy,
241+
Steps: []resource.TestStep{
242+
{
243+
Config: testAccCustomLayerConfig_loadBasedAutoScaling(rName, true),
244+
Check: resource.ComposeAggregateTestCheckFunc(
245+
testAccCheckLayerExists(resourceName, &v),
246+
resource.TestCheckResourceAttr(resourceName, "name", rName),
247+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.#", "1"),
248+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.downscaling.#", "1"),
249+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.downscaling.0.alarms.#", "0"),
250+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.downscaling.0.cpu_threshold", "20"),
251+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.downscaling.0.ignore_metrics_time", "15"),
252+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.downscaling.0.instance_count", "2"),
253+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.downscaling.0.load_threshold", "5"),
254+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.downscaling.0.memory_threshold", "20"),
255+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.downscaling.0.thresholds_wait_time", "30"),
256+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.enable", "true"),
257+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.upscaling.#", "1"),
258+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.upscaling.0.alarms.#", "0"),
259+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.upscaling.0.cpu_threshold", "80"),
260+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.upscaling.0.ignore_metrics_time", "15"),
261+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.upscaling.0.instance_count", "3"),
262+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.upscaling.0.load_threshold", "10"),
263+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.upscaling.0.memory_threshold", "80"),
264+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.upscaling.0.thresholds_wait_time", "35"),
265+
),
266+
},
267+
{
268+
ResourceName: resourceName,
269+
ImportState: true,
270+
ImportStateVerify: true,
271+
},
272+
{
273+
Config: testAccCustomLayerConfig_loadBasedAutoScaling(rName, false),
274+
Check: resource.ComposeAggregateTestCheckFunc(
275+
testAccCheckLayerExists(resourceName, &v),
276+
resource.TestCheckResourceAttr(resourceName, "name", rName),
277+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.#", "1"),
278+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.downscaling.#", "1"),
279+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.downscaling.0.alarms.#", "0"),
280+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.downscaling.0.cpu_threshold", "20"),
281+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.downscaling.0.ignore_metrics_time", "15"),
282+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.downscaling.0.instance_count", "2"),
283+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.downscaling.0.load_threshold", "5"),
284+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.downscaling.0.memory_threshold", "20"),
285+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.downscaling.0.thresholds_wait_time", "30"),
286+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.enable", "false"),
287+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.upscaling.#", "1"),
288+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.upscaling.0.alarms.#", "0"),
289+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.upscaling.0.cpu_threshold", "80"),
290+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.upscaling.0.ignore_metrics_time", "15"),
291+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.upscaling.0.instance_count", "3"),
292+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.upscaling.0.load_threshold", "10"),
293+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.upscaling.0.memory_threshold", "80"),
294+
resource.TestCheckResourceAttr(resourceName, "load_based_auto_scaling.0.upscaling.0.thresholds_wait_time", "35"),
295+
),
296+
},
297+
},
298+
})
299+
}
300+
229301
func testAccCheckCustomLayerDestroy(s *terraform.State) error {
230302
return testAccCheckLayerDestroy("aws_opsworks_custom_layer", s)
231303
}
@@ -383,3 +455,41 @@ resource "aws_opsworks_custom_layer" "test" {
383455
}
384456
`, rName))
385457
}
458+
459+
func testAccCustomLayerConfig_loadBasedAutoScaling(rName string, enable bool) string {
460+
return acctest.ConfigCompose(testAccLayerConfig_base(rName), fmt.Sprintf(`
461+
resource "aws_opsworks_custom_layer" "test" {
462+
stack_id = aws_opsworks_stack.test.id
463+
name = %[1]q
464+
short_name = "tf-ops-acc-custom-layer"
465+
auto_assign_public_ips = true
466+
467+
custom_security_group_ids = aws_security_group.test[*].id
468+
469+
drain_elb_on_shutdown = true
470+
instance_shutdown_timeout = 300
471+
472+
load_based_auto_scaling {
473+
enable = %[2]t
474+
475+
downscaling {
476+
cpu_threshold = 20
477+
ignore_metrics_time = 15
478+
instance_count = 2
479+
load_threshold = 5
480+
memory_threshold = 20
481+
thresholds_wait_time = 30
482+
}
483+
484+
upscaling {
485+
cpu_threshold = 80
486+
ignore_metrics_time = 15
487+
instance_count = 3
488+
load_threshold = 10
489+
memory_threshold = 80
490+
thresholds_wait_time = 35
491+
}
492+
}
493+
}
494+
`, rName, enable))
495+
}

internal/service/opsworks/layers.go

+9-10
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,14 @@ func (lt *opsworksLayerType) resourceSchema() *schema.Resource {
286286
"load_based_auto_scaling": {
287287
Type: schema.TypeList,
288288
Optional: true,
289+
Computed: true,
289290
MaxItems: 1,
290291
Elem: &schema.Resource{
291292
Schema: map[string]*schema.Schema{
292293
"downscaling": {
293294
Type: schema.TypeList,
294295
Optional: true,
296+
Computed: true,
295297
MaxItems: 1,
296298
Elem: &schema.Resource{
297299
Schema: map[string]*schema.Schema{
@@ -304,12 +306,12 @@ func (lt *opsworksLayerType) resourceSchema() *schema.Resource {
304306
"cpu_threshold": {
305307
Type: schema.TypeFloat,
306308
Optional: true,
307-
Default: -1,
309+
Default: 30.0,
308310
},
309311
"ignore_metrics_time": {
310312
Type: schema.TypeInt,
311313
Optional: true,
312-
Default: 1,
314+
Default: 10,
313315
ValidateFunc: validation.IntBetween(1, 100),
314316
},
315317
"instance_count": {
@@ -320,17 +322,15 @@ func (lt *opsworksLayerType) resourceSchema() *schema.Resource {
320322
"load_threshold": {
321323
Type: schema.TypeFloat,
322324
Optional: true,
323-
Default: -1,
324325
},
325326
"memory_threshold": {
326327
Type: schema.TypeFloat,
327328
Optional: true,
328-
Default: -1,
329329
},
330330
"thresholds_wait_time": {
331331
Type: schema.TypeInt,
332332
Optional: true,
333-
Default: 1,
333+
Default: 10,
334334
ValidateFunc: validation.IntBetween(1, 100),
335335
},
336336
},
@@ -343,6 +343,7 @@ func (lt *opsworksLayerType) resourceSchema() *schema.Resource {
343343
"upscaling": {
344344
Type: schema.TypeList,
345345
Optional: true,
346+
Computed: true,
346347
MaxItems: 1,
347348
Elem: &schema.Resource{
348349
Schema: map[string]*schema.Schema{
@@ -355,12 +356,12 @@ func (lt *opsworksLayerType) resourceSchema() *schema.Resource {
355356
"cpu_threshold": {
356357
Type: schema.TypeFloat,
357358
Optional: true,
358-
Default: -1,
359+
Default: 80.0,
359360
},
360361
"ignore_metrics_time": {
361362
Type: schema.TypeInt,
362363
Optional: true,
363-
Default: 1,
364+
Default: 5,
364365
ValidateFunc: validation.IntBetween(1, 100),
365366
},
366367
"instance_count": {
@@ -371,17 +372,15 @@ func (lt *opsworksLayerType) resourceSchema() *schema.Resource {
371372
"load_threshold": {
372373
Type: schema.TypeFloat,
373374
Optional: true,
374-
Default: -1,
375375
},
376376
"memory_threshold": {
377377
Type: schema.TypeFloat,
378378
Optional: true,
379-
Default: -1,
380379
},
381380
"thresholds_wait_time": {
382381
Type: schema.TypeInt,
383382
Optional: true,
384-
Default: 1,
383+
Default: 5,
385384
ValidateFunc: validation.IntBetween(1, 100),
386385
},
387386
},

0 commit comments

Comments
 (0)