Skip to content

Resource: awsEcsCapacityProvider

Provides an ECS cluster capacity provider. More information can be found on the ECS Developer Guide.

\~> NOTE: Associating an ECS Capacity Provider to an Auto Scaling Group will automatically add the amazonEcsManaged tag to the Auto Scaling Group. This tag should be included in the awsAutoscalingGroup resource configuration to prevent Terraform from removing it in subsequent executions as well as ensuring the amazonEcsManaged tag is propagated to all EC2 Instances in the Auto Scaling Group if minSize is above 0 on creation. Any EC2 Instances in the Auto Scaling Group without this tag must be manually be updated, otherwise they may cause unexpected scaling behavior and metrics.

Example Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const awsAutoscalingGroupTest = new aws.autoscalingGroup.AutoscalingGroup(
  this,
  "test",
  {
    tag: [
      {
        key: "AmazonECSManaged",
        propagateAtLaunch: true,
        value: true,
      },
    ],
  }
);
const awsEcsCapacityProviderTest =
  new aws.ecsCapacityProvider.EcsCapacityProvider(this, "test_1", {
    autoScalingGroupProvider: {
      autoScalingGroupArn: awsAutoscalingGroupTest.arn,
      managedScaling: {
        maximumScalingStepSize: 1000,
        minimumScalingStepSize: 1,
        status: "ENABLED",
        targetCapacity: 10,
      },
      managedTerminationProtection: "ENABLED",
    },
    name: "test",
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsEcsCapacityProviderTest.overrideLogicalId("test");

Argument Reference

The following arguments are supported:

  • autoScalingGroupProvider - (Required) Configuration block for the provider for the ECS auto scaling group. Detailed below.
  • name - (Required) Name of the capacity provider.
  • tags - (Optional) Key-value map of resource tags. If configured with a provider defaultTags configuration block present, tags with matching keys will overwrite those defined at the provider-level.

autoScalingGroupProvider

  • autoScalingGroupArn - (Required) - ARN of the associated auto scaling group.
  • managedScaling - (Optional) - Configuration block defining the parameters of the auto scaling. Detailed below.
  • managedTerminationProtection - (Optional) - Enables or disables container-aware termination of instances in the auto scaling group when scale-in happens. Valid values are enabled and disabled.

managedScaling

  • instanceWarmupPeriod - (Optional) 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.
  • maximumScalingStepSize - (Optional) Maximum step adjustment size. A number between 1 and 10,000.
  • minimumScalingStepSize - (Optional) 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.
  • targetCapacity - (Optional) Target utilization for the capacity provider. A number between 1 and 100.

Attributes Reference

In addition to all arguments above, the following attributes are exported:

  • arn - ARN that identifies the capacity provider.
  • id - ARN that identifies the capacity provider.
  • tagsAll - Map of tags assigned to the resource, including those inherited from the provider defaultTags configuration block.

Import

ECS Capacity Providers can be imported using the name, e.g.,

$ terraform import aws_ecs_capacity_provider.example example