@@ -52,6 +52,8 @@ func TestAccOpsWorksCustomLayer_basic(t *testing.T) {
52
52
resource .TestCheckResourceAttr (resourceName , "elastic_load_balancer" , "" ),
53
53
resource .TestCheckResourceAttr (resourceName , "instance_shutdown_timeout" , "300" ),
54
54
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" ),
55
57
resource .TestCheckResourceAttr (resourceName , "name" , rName ),
56
58
resource .TestCheckResourceAttr (resourceName , "short_name" , "tf-ops-acc-custom-layer" ),
57
59
resource .TestCheckResourceAttr (resourceName , "system_packages.#" , "2" ),
@@ -226,6 +228,76 @@ func TestAccOpsWorksCustomLayer_cloudWatch(t *testing.T) {
226
228
})
227
229
}
228
230
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
+
229
301
func testAccCheckCustomLayerDestroy (s * terraform.State ) error {
230
302
return testAccCheckLayerDestroy ("aws_opsworks_custom_layer" , s )
231
303
}
@@ -383,3 +455,41 @@ resource "aws_opsworks_custom_layer" "test" {
383
455
}
384
456
` , rName ))
385
457
}
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
+ }
0 commit comments