Skip to content

Commit

Permalink
resource/aws_ecs_capacity_provider: Add support for instance warmup p…
Browse files Browse the repository at this point in the history
…eriod (#16941)

Reference: #16673

Output from acceptance testing in AWS Commercial:

```
--- PASS: TestAccAWSEcsCapacityProvider_basic (82.59s)
--- PASS: TestAccAWSEcsCapacityProvider_disappears (61.98s)
--- PASS: TestAccAWSEcsCapacityProvider_ManagedScaling (83.84s)
--- PASS: TestAccAWSEcsCapacityProvider_ManagedScalingPartial (60.27s)
--- PASS: TestAccAWSEcsCapacityProvider_Tags (100.69s)
```

Output from acceptance testing in AWS GovCloud (US):

```
--- PASS: TestAccAWSEcsCapacityProvider_basic (64.74s)
--- PASS: TestAccAWSEcsCapacityProvider_disappears (61.46s)
--- PASS: TestAccAWSEcsCapacityProvider_ManagedScaling (56.88s)
--- PASS: TestAccAWSEcsCapacityProvider_ManagedScalingPartial (56.82s)
--- PASS: TestAccAWSEcsCapacityProvider_Tags (126.82s)
```
  • Loading branch information
shuheiktgw authored Feb 18, 2021
1 parent b641c40 commit eee0824
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions aws/resource_aws_ecs_capacity_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ func resourceAwsEcsCapacityProvider() *schema.Resource {
ForceNew: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"instance_warmup_period": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: validation.IntBetween(1, 10000),
},
"maximum_scaling_step_size": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -248,6 +255,9 @@ func expandAutoScalingGroupProvider(configured interface{}) *ecs.AutoScalingGrou
ms := v[0].(map[string]interface{})
managedScaling := ecs.ManagedScaling{}

if val, ok := ms["instance_warmup_period"].(int); ok && val != 0 {
managedScaling.InstanceWarmupPeriod = aws.Int64(int64(val))
}
if val, ok := ms["maximum_scaling_step_size"].(int); ok && val != 0 {
managedScaling.MaximumScalingStepSize = aws.Int64(int64(val))
}
Expand Down Expand Up @@ -279,6 +289,7 @@ func flattenAutoScalingGroupProvider(provider *ecs.AutoScalingGroupProvider) []m

if provider.ManagedScaling != nil {
m := map[string]interface{}{
"instance_warmup_period": aws.Int64Value(provider.ManagedScaling.InstanceWarmupPeriod),
"maximum_scaling_step_size": aws.Int64Value(provider.ManagedScaling.MaximumScalingStepSize),
"minimum_scaling_step_size": aws.Int64Value(provider.ManagedScaling.MinimumScalingStepSize),
"status": aws.StringValue(provider.ManagedScaling.Status),
Expand Down
4 changes: 4 additions & 0 deletions aws/resource_aws_ecs_capacity_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func TestAccAWSEcsCapacityProvider_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
resource.TestCheckResourceAttrPair(resourceName, "auto_scaling_group_provider.0.auto_scaling_group_arn", "aws_autoscaling_group.test", "arn"),
resource.TestCheckResourceAttr(resourceName, "auto_scaling_group_provider.0.managed_termination_protection", "DISABLED"),
resource.TestCheckResourceAttr(resourceName, "auto_scaling_group_provider.0.managed_scaling.0.instance_warmup_period", "300"),
resource.TestCheckResourceAttr(resourceName, "auto_scaling_group_provider.0.managed_scaling.0.minimum_scaling_step_size", "1"),
resource.TestCheckResourceAttr(resourceName, "auto_scaling_group_provider.0.managed_scaling.0.maximum_scaling_step_size", "10000"),
resource.TestCheckResourceAttr(resourceName, "auto_scaling_group_provider.0.managed_scaling.0.status", "DISABLED"),
Expand Down Expand Up @@ -172,6 +173,7 @@ func TestAccAWSEcsCapacityProvider_ManagedScaling(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttrPair(resourceName, "auto_scaling_group_provider.0.auto_scaling_group_arn", "aws_autoscaling_group.test", "arn"),
resource.TestCheckResourceAttr(resourceName, "auto_scaling_group_provider.0.managed_termination_protection", "DISABLED"),
resource.TestCheckResourceAttr(resourceName, "auto_scaling_group_provider.0.managed_scaling.0.instance_warmup_period", "400"),
resource.TestCheckResourceAttr(resourceName, "auto_scaling_group_provider.0.managed_scaling.0.minimum_scaling_step_size", "2"),
resource.TestCheckResourceAttr(resourceName, "auto_scaling_group_provider.0.managed_scaling.0.maximum_scaling_step_size", "10"),
resource.TestCheckResourceAttr(resourceName, "auto_scaling_group_provider.0.managed_scaling.0.status", "ENABLED"),
Expand Down Expand Up @@ -205,6 +207,7 @@ func TestAccAWSEcsCapacityProvider_ManagedScalingPartial(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttrPair(resourceName, "auto_scaling_group_provider.0.auto_scaling_group_arn", "aws_autoscaling_group.test", "arn"),
resource.TestCheckResourceAttr(resourceName, "auto_scaling_group_provider.0.managed_termination_protection", "DISABLED"),
resource.TestCheckResourceAttr(resourceName, "auto_scaling_group_provider.0.managed_scaling.0.instance_warmup_period", "300"),
resource.TestCheckResourceAttr(resourceName, "auto_scaling_group_provider.0.managed_scaling.0.minimum_scaling_step_size", "2"),
resource.TestCheckResourceAttr(resourceName, "auto_scaling_group_provider.0.managed_scaling.0.maximum_scaling_step_size", "10000"),
resource.TestCheckResourceAttr(resourceName, "auto_scaling_group_provider.0.managed_scaling.0.status", "ENABLED"),
Expand Down Expand Up @@ -397,6 +400,7 @@ resource "aws_ecs_capacity_provider" "test" {
auto_scaling_group_arn = aws_autoscaling_group.test.arn
managed_scaling {
instance_warmup_period = 400
maximum_scaling_step_size = 10
minimum_scaling_step_size = 2
status = "ENABLED"
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/ecs_capacity_provider.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ The `auto_scaling_group_provider` block supports the following:

The `managed_scaling` block supports the following:

* `instance_warmup_period` - (Optional) The period of time, in seconds, after a newly launched Amazon EC2 instance can contribute to CloudWatch metrics for Auto Scaling group. If this parameter is omitted, the default value of 300 seconds is used.
* `maximum_scaling_step_size` - (Optional) The maximum step adjustment size. A number between 1 and 10,000.
* `minimum_scaling_step_size` - (Optional) The minimum step adjustment size. A number between 1 and 10,000.
* `status` - (Optional) Whether auto scaling is managed by ECS. Valid values are `ENABLED` and `DISABLED`.
Expand Down

0 comments on commit eee0824

Please sign in to comment.