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

feat: new aws_ecs_clusters datasource #40638

Merged
merged 3 commits into from
Dec 23, 2024

Conversation

taufort
Copy link
Contributor

@taufort taufort commented Dec 19, 2024

Description

This datasource aims at getting all ECS clusters ARNs associated with an AWS account. It can be useful to get ECS clusters in case you don't know their names (in that case, the existing datasource aws_ecs_cluster won't be much help - see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ecs_cluster).

I was trying to set up centralized VPC flow logs in an AWS organization to send all flow logs to one common S3 bucket. On some AWS accounts in this organization, ECS clusters may exist or not. In case ECS clusters exist, I wanted to have ECS flow logs fields sent to the bucket (the ECS fields can be found here: https://docs.aws.amazon.com/vpc/latest/userguide/flow-log-records.html#flow-logs-fields). But to have those ECS fields in the flow logs, at least one ECS cluster must exist on the AWS account, else the Flow log cannot be created.

So, I came up with a workaround using a null_resource and a local-exec provisioner (using AWS CLI commands in it to get the list of ECS Clusters in the account) in order to be able to switch between 2 VPC flow logs format in case an ECS cluster exists on an AWS account. This way, I'm able to have ECS fields added in the flow log with the same code base as when no ECS cluster exists on the AWS account.

This new datasource will help me get rid of this workaround which is clearly not ideal.

Relations

I did not find a ticket related to the creation of this datasource.

Output from Acceptance Testing

make testacc TESTS=TestAccECSClustersDataSource_basic PKG=ecs
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.23.3 test ./internal/service/ecs/... -v -count 1 -parallel 20 -run='TestAccECSClustersDataSource_basic'  -timeout 360m
2024/12/19 17:56:58 Initializing Terraform AWS Provider...
=== RUN   TestAccECSClustersDataSource_basic
=== PAUSE TestAccECSClustersDataSource_basic
=== CONT  TestAccECSClustersDataSource_basic
--- PASS: TestAccECSClustersDataSource_basic (28.33s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/ecs        28.566s

@taufort taufort requested a review from a team as a code owner December 19, 2024 18:20
Copy link

Community Note

Voting for Prioritization

  • Please vote on this pull request by adding a 👍 reaction to the original post to help the community and maintainers prioritize this pull request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

For Submitters

  • Review the contribution guide relating to the type of change you are making to ensure all of the necessary steps have been taken.
  • For new resources and data sources, use skaff to generate scaffolding with comments detailing common expectations.
  • Whether or not the branch has been rebased will not impact prioritization, but doing so is always a welcome surprise.

@github-actions github-actions bot added documentation Introduces or discusses updates to documentation. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. service/ecs Issues and PRs that pertain to the ecs service. generators Relates to code generators. needs-triage Waiting for first response or review from a maintainer. labels Dec 19, 2024
@taufort taufort force-pushed the f-aws_ecs_clusters branch 3 times, most recently from eb20081 to 915cb14 Compare December 20, 2024 09:06
This datasource aims at getting all ECS clusters ARNs associated with an account.
@ewbankkit ewbankkit added new-data-source Introduces a new data source. and removed needs-triage Waiting for first response or review from a maintainer. labels Dec 23, 2024
@ewbankkit ewbankkit self-assigned this Dec 23, 2024
Copy link
Contributor

@ewbankkit ewbankkit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀.

% make testacc TESTARGS='-run=TestAccECSClustersDataSource_' PKG=ecs
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.23.3 test ./internal/service/ecs/... -v -count 1 -parallel 20  -run=TestAccECSClustersDataSource_ -timeout 360m
2024/12/23 12:14:32 Initializing Terraform AWS Provider...
=== RUN   TestAccECSClustersDataSource_basic
=== PAUSE TestAccECSClustersDataSource_basic
=== CONT  TestAccECSClustersDataSource_basic
--- PASS: TestAccECSClustersDataSource_basic (22.21s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/ecs	27.765s

@github-actions github-actions bot added the prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. label Dec 23, 2024
Copy link
Contributor

@nam054 nam054 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

@ewbankkit
Copy link
Contributor

@taufort Thanks for the contribution 🎉 👏.

@ewbankkit ewbankkit merged commit ce8bc78 into hashicorp:main Dec 23, 2024
48 checks passed
@github-actions github-actions bot added this to the v5.83.0 milestone Dec 23, 2024
@taufort taufort deleted the f-aws_ecs_clusters branch December 27, 2024 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Introduces or discusses updates to documentation. generators Relates to code generators. new-data-source Introduces a new data source. prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. service/ecs Issues and PRs that pertain to the ecs service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants