Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/aws_ecs_capacity_provider: add manged_draining argument #35421

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/35421.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_ecs_capacity_provider: Add `auto_scaling_group_provider.managed_draining` argument
```
25 changes: 20 additions & 5 deletions internal/service/ecs/capacity_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ func ResourceCapacityProvider() *schema.Resource {
ForceNew: true,
ValidateFunc: verify.ValidARN,
},
"managed_draining": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice(ecs.ManagedDraining_Values(), false),
},
"managed_scaling": {
Type: schema.TypeList,
MaxItems: 1,
Expand Down Expand Up @@ -281,12 +287,16 @@ func expandAutoScalingGroupProviderCreate(configured interface{}) *ecs.AutoScali
arn := p["auto_scaling_group_arn"].(string)
prov.AutoScalingGroupArn = aws.String(arn)

if mtp := p["managed_termination_protection"].(string); len(mtp) > 0 {
prov.ManagedTerminationProtection = aws.String(mtp)
if mtp := p["managed_draining"].(string); len(mtp) > 0 {
prov.ManagedDraining = aws.String(mtp)
}

prov.ManagedScaling = expandManagedScaling(p["managed_scaling"])

if mtp := p["managed_termination_protection"].(string); len(mtp) > 0 {
prov.ManagedTerminationProtection = aws.String(mtp)
}

return &prov
}

Expand All @@ -302,12 +312,16 @@ func expandAutoScalingGroupProviderUpdate(configured interface{}) *ecs.AutoScali
prov := ecs.AutoScalingGroupProviderUpdate{}
p := configured.([]interface{})[0].(map[string]interface{})

if mtp := p["managed_termination_protection"].(string); len(mtp) > 0 {
prov.ManagedTerminationProtection = aws.String(mtp)
if mtp := p["managed_draining"].(string); len(mtp) > 0 {
prov.ManagedDraining = aws.String(mtp)
}

prov.ManagedScaling = expandManagedScaling(p["managed_scaling"])

if mtp := p["managed_termination_protection"].(string); len(mtp) > 0 {
prov.ManagedTerminationProtection = aws.String(mtp)
}

return &prov
}

Expand Down Expand Up @@ -350,8 +364,9 @@ func flattenAutoScalingGroupProvider(provider *ecs.AutoScalingGroupProvider) []m

p := map[string]interface{}{
"auto_scaling_group_arn": aws.StringValue(provider.AutoScalingGroupArn),
"managed_termination_protection": aws.StringValue(provider.ManagedTerminationProtection),
"managed_draining": aws.StringValue(provider.ManagedDraining),
"managed_scaling": []map[string]interface{}{},
"managed_termination_protection": aws.StringValue(provider.ManagedTerminationProtection),
}

if provider.ManagedScaling != nil {
Expand Down
32 changes: 19 additions & 13 deletions internal/service/ecs/capacity_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,22 @@ func TestAccECSCapacityProvider_basic(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccCapacityProviderConfig_basic(rName),
Check: resource.ComposeTestCheckFunc(
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckCapacityProviderExists(ctx, resourceName, &provider),
resource.TestCheckResourceAttr(resourceName, "name", rName),
acctest.CheckResourceAttrRegionalARN(resourceName, "id", "ecs", fmt.Sprintf("capacity-provider/%s", rName)),
resource.TestCheckResourceAttrPair(resourceName, "id", resourceName, "arn"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
resource.TestCheckResourceAttr(resourceName, "auto_scaling_group_provider.#", "1"),
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_draining", "ENABLED"),
resource.TestCheckResourceAttr(resourceName, "auto_scaling_group_provider.0.managed_scaling.#", "1"),
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"),
resource.TestCheckResourceAttr(resourceName, "auto_scaling_group_provider.0.managed_scaling.0.target_capacity", "100"),
resource.TestCheckResourceAttr(resourceName, "auto_scaling_group_provider.0.managed_termination_protection", "DISABLED"),
acctest.CheckResourceAttrRegionalARN(resourceName, "id", "ecs", fmt.Sprintf("capacity-provider/%s", rName)),
resource.TestCheckResourceAttrPair(resourceName, "id", resourceName, "arn"),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
),
},
{
Expand Down Expand Up @@ -97,14 +100,14 @@ func TestAccECSCapacityProvider_managedScaling(t *testing.T) {
Config: testAccCapacityProviderConfig_managedScaling(rName, ecs.ManagedScalingStatusEnabled, 300, 10, 1, 50),
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_draining", "ENABLED"),
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", "10"),
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", "50"),
resource.TestCheckResourceAttr(resourceName, "auto_scaling_group_provider.0.managed_termination_protection", "DISABLED"),
),
},
{
Expand All @@ -117,28 +120,28 @@ func TestAccECSCapacityProvider_managedScaling(t *testing.T) {
Config: testAccCapacityProviderConfig_managedScaling(rName, ecs.ManagedScalingStatusDisabled, 400, 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_draining", "ENABLED"),
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", "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", "DISABLED"),
resource.TestCheckResourceAttr(resourceName, "auto_scaling_group_provider.0.managed_scaling.0.target_capacity", "100"),
resource.TestCheckResourceAttr(resourceName, "auto_scaling_group_provider.0.managed_termination_protection", "DISABLED"),
),
},
{
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_draining", "ENABLED"),
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"),
resource.TestCheckResourceAttr(resourceName, "auto_scaling_group_provider.0.managed_termination_protection", "DISABLED"),
),
},
},
Expand All @@ -163,8 +166,9 @@ func TestAccECSCapacityProvider_managedScalingPartial(t *testing.T) {
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_draining", "DISABLED"),
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.instance_warmup_period", "0"),
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 @@ -356,6 +360,8 @@ resource "aws_ecs_capacity_provider" "test" {
auto_scaling_group_provider {
auto_scaling_group_arn = aws_autoscaling_group.test.arn

managed_draining = "DISABLED"

managed_scaling {
minimum_scaling_step_size = 2
status = "ENABLED"
Expand Down
2 changes: 1 addition & 1 deletion internal/service/ecs/cluster_capacity_providers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestAccECSClusterCapacityProviders_disappears(t *testing.T) {
Config: testAccClusterCapacityProvidersConfig_basic(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckClusterExists(ctx, "aws_ecs_cluster.test", &cluster),
acctest.CheckResourceDisappears(ctx, acctest.Provider, tfecs.ResourceCluster(), resourceName),
acctest.CheckResourceDisappears(ctx, acctest.Provider, tfecs.ResourceClusterCapacityProviders(), resourceName),
),
ExpectNonEmptyPlan: true,
},
Expand Down
7 changes: 0 additions & 7 deletions internal/service/ecs/task_definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,13 +607,6 @@ func TestAccECSTaskDefinition_DockerVolume_taskScoped(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "volume.#", "1"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateIdFunc: testAccTaskDefinitionImportStateIdFunc(resourceName),
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
},
},
})
}
Expand Down
5 changes: 2 additions & 3 deletions internal/service/events/target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1883,6 +1883,7 @@ resource "aws_ecs_capacity_provider" "test" {
auto_scaling_group_provider {
auto_scaling_group_arn = aws_autoscaling_group.test.arn
managed_termination_protection = "DISABLED"
managed_draining = "ENABLED"

managed_scaling {
maximum_scaling_step_size = 1
Expand Down Expand Up @@ -1919,7 +1920,6 @@ resource "aws_cloudwatch_event_target" "test" {
type = "spread"
field = "instanceId"
}

}
}

Expand Down Expand Up @@ -1954,6 +1954,7 @@ resource "aws_ecs_capacity_provider" "test" {
auto_scaling_group_provider {
auto_scaling_group_arn = aws_autoscaling_group.test.arn
managed_termination_protection = "DISABLED"
managed_draining = "ENABLED"

managed_scaling {
maximum_scaling_step_size = 1
Expand All @@ -1974,8 +1975,6 @@ resource "aws_ecs_cluster_capacity_providers" "test" {
weight = 100
}
}


`, rName))
}

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 @@ -53,6 +53,7 @@ This resource supports the following arguments:
### `auto_scaling_group_provider`

* `auto_scaling_group_arn` - (Required) - ARN of the associated auto scaling group.
* `managed_draining` - (Optional) - Enables or disables a graceful shutdown of instances without disturbing workloads. Valid values are `ENABLED` and `DISABLED`. The default value is `ENABLED` when a capacity provider is created.
* `managed_scaling` - (Optional) - Configuration block defining the parameters of the auto scaling. Detailed below.
* `managed_termination_protection` - (Optional) - Enables or disables container-aware termination of instances in the auto scaling group when scale-in happens. Valid values are `ENABLED` and `DISABLED`.

Expand Down
Loading