Skip to content

Commit

Permalink
Merge pull request #31231 from hashicorp/replace-pr24005
Browse files Browse the repository at this point in the history
r/aws_ecs_capacity_provider: Allow an `instance_warmup_period` of `0`
  • Loading branch information
ewbankkit authored May 5, 2023
2 parents 81d6986 + 6142973 commit 8dbfe7e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .changelog/24005.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_ecs_capacity_provider: Allow an `instance_warmup_period` of `0` in the `auto_scaling_group_provider.managed_scaling` configuration block
```
24 changes: 12 additions & 12 deletions internal/service/ecs/capacity_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func ResourceCapacityProvider() *schema.Resource {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ValidateFunc: validation.IntBetween(1, 10000),
ValidateFunc: validation.IntBetween(0, 10000),
},
"maximum_scaling_step_size": {
Type: schema.TypeInt,
Expand Down Expand Up @@ -317,24 +317,24 @@ func expandManagedScaling(configured interface{}) *ecs.ManagedScaling {
return nil
}

p := configured.([]interface{})[0].(map[string]interface{})
tfMap := configured.([]interface{})[0].(map[string]interface{})

managedScaling := ecs.ManagedScaling{}

if val, ok := p["instance_warmup_period"].(int); ok && val != 0 {
managedScaling.InstanceWarmupPeriod = aws.Int64(int64(val))
if v, ok := tfMap["instance_warmup_period"].(int); ok {
managedScaling.InstanceWarmupPeriod = aws.Int64(int64(v))
}
if val, ok := p["maximum_scaling_step_size"].(int); ok && val != 0 {
managedScaling.MaximumScalingStepSize = aws.Int64(int64(val))
if v, ok := tfMap["maximum_scaling_step_size"].(int); ok && v != 0 {
managedScaling.MaximumScalingStepSize = aws.Int64(int64(v))
}
if val, ok := p["minimum_scaling_step_size"].(int); ok && val != 0 {
managedScaling.MinimumScalingStepSize = aws.Int64(int64(val))
if v, ok := tfMap["minimum_scaling_step_size"].(int); ok && v != 0 {
managedScaling.MinimumScalingStepSize = aws.Int64(int64(v))
}
if val, ok := p["status"].(string); ok && len(val) > 0 {
managedScaling.Status = aws.String(val)
if v, ok := tfMap["status"].(string); ok && len(v) > 0 {
managedScaling.Status = aws.String(v)
}
if val, ok := p["target_capacity"].(int); ok && val != 0 {
managedScaling.TargetCapacity = aws.Int64(int64(val))
if v, ok := tfMap["target_capacity"].(int); ok && v != 0 {
managedScaling.TargetCapacity = aws.Int64(int64(v))
}

return &managedScaling
Expand Down
24 changes: 22 additions & 2 deletions internal/service/ecs/capacity_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,20 @@ func TestAccECSCapacityProvider_managedScaling(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "auto_scaling_group_provider.0.managed_scaling.0.target_capacity", "100"),
),
},
{
Config: testAccCapacityProviderConfig_managedScaling(rName, ecs.ManagedScalingStatusEnabled, 0, 100, 10, 100),
Check: resource.ComposeTestCheckFunc(
testAccCheckCapacityProviderExists(ctx, resourceName, &provider),
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", "0"),
resource.TestCheckResourceAttr(resourceName, "auto_scaling_group_provider.0.managed_scaling.0.minimum_scaling_step_size", "10"),
resource.TestCheckResourceAttr(resourceName, "auto_scaling_group_provider.0.managed_scaling.0.maximum_scaling_step_size", "100"),
resource.TestCheckResourceAttr(resourceName, "auto_scaling_group_provider.0.managed_scaling.0.status", "ENABLED"),
resource.TestCheckResourceAttr(resourceName, "auto_scaling_group_provider.0.managed_scaling.0.target_capacity", "100"),
),
},
},
})
}
Expand Down Expand Up @@ -284,11 +298,17 @@ resource "aws_autoscaling_group" "test" {
id = aws_launch_template.test.id
}
tags = [{
tag {
key = "Name"
value = %[1]q
propagate_at_launch = true
}]
}
lifecycle {
ignore_changes = [
tag,
]
}
}
`, rName))
}
Expand Down

0 comments on commit 8dbfe7e

Please sign in to comment.