hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.77k stars 9.13k forks source link

aws_ecs_cluster: Update data source to export attribute for defaultCapacityProviderStrategy #26533

Open ericdahl opened 2 years ago

ericdahl commented 2 years ago

Community Note

Description

Update the existing Data Source aws_ecs_cluster to also export an attribute for the defaultCapacityProviderStrategy, which is available via the DescribeClusters API

Use Case - when migrating ECS Clusters to use AWS Capacity Providers feature, we need to also migrate our existing ECS Services on that cluster. (New ECS Services automatically get this default strategy, but existing ones do not). In our case, our cluster resources are defined in different CI/CD pipelines than the ECS Services. If we could have Services query for any default strategy then use that, it would help with the migration process.

A workaround would be to use an External data source with AWS CLI commands to obtain this info, or to write out this metadata to TF state for querying via terraform_remote_state lookups.

New or Affected Resource(s)

Potential Terraform Configuration


data "aws_ecs_cluster" "example" {
  cluster_name = "example"
}

resource "aws_ecs_service" "myservice" {
  ...
  # better alternative implementation would be to use a dynamic block to loop through each of the items in the array. This is simplified
    capacity_provider_strategy {
      capacity_provider = data.aws_ecs_cluster.example.default_capacity_provider_strategy[0].capacity_provider
      weight            = data.aws_ecs_cluster.example.default_capacity_provider_strategy[0].weight
      base              = data.aws_ecs_cluster.example.default_capacity_provider_strategy[0].base
  } 
}

References

pazderak commented 9 months ago

:+1: