Skip to content

🤖🤖🤖 d/aws_dx_connections: New data source - #49151

Open
BenjaminSaintCyr wants to merge 3 commits into
hashicorp:mainfrom
BenjaminSaintCyr:f-aws_dx_connections
Open

🤖🤖🤖 d/aws_dx_connections: New data source#49151
BenjaminSaintCyr wants to merge 3 commits into
hashicorp:mainfrom
BenjaminSaintCyr:f-aws_dx_connections

Conversation

@BenjaminSaintCyr

@BenjaminSaintCyr BenjaminSaintCyr commented Jul 28, 2026

Copy link
Copy Markdown

Rollback Plan

If a change needs to be reverted, we will publish an updated version of the library.

Changes to Security Controls

No. This PR adds a read-only data source only. It requires no IAM permissions beyond directconnect:DescribeConnections, which the existing aws_dx_connection data source already needs.

Description

Adds a new plural data source aws_dx_connections that returns every Direct Connect connection in the Region. The singular aws_dx_connection data source requires knowing a connection name up front and errors unless exactly one matches, so there is currently no way to enumerate connections.

  • Returns connections, a list of objects each carrying arn, aws_device, bandwidth, id, location, name, owner_account_id, partner_name, provider_name, state, tags, and vlan_id.
  • Takes no arguments: DescribeConnections has no server-side filter (its input accepts only a single connection ID), so callers filter in configuration with a for/for_each expression.
  • Makes findConnections paginate, which affects two pre-existing callers. DescribeConnections is not modelled as paginated in the SDK but does return a nextToken, and the previous implementation read only the first page. This also fixes silent truncation past 100 connections for the aws_dx_connection data source and resource — a behaviour change beyond the scope the title implies, called out here rather than left in the diff.
  • Exposes no synthetic top-level id, per the data-source naming guidance; each element carries its own id (the connection ID). A unit test pins this so it cannot regress.
  • aws_device is populated from the API's awsDeviceV2 field, since awsDevice is deprecated and empty in practice. The model field is named AwsDeviceV2 so AutoFlex binds the correct one, while the public attribute name stays aws_device to match the singular data source.
  • An empty result flattens to an empty list rather than null, so connections stays usable in for_each without try/coalesce. Likewise an untagged connection flattens tags to an empty map rather than null.
  • Uses terraform-plugin-framework + aws-sdk-go-v2, with AutoFlex (fwflex.Flatten) for the per-item conversion and framework.DataSourceComputedListOfObjectAttribute for the nested schema.

Relations

Closes #40032

References

Output from Acceptance Testing

Run in us-west-2 with AWS_ALTERNATE_REGION=us-east-1, since the _empty and _region tests call acctest.PreCheckMultipleRegion(t, 2). The tests create and destroy real connections; they need no cross-connect or physical hardware, and a connection left in requested state accrues no port-hours.

% make testacc TESTS=TestAccDirectConnectConnectionsDataSource PKG=directconnect

--- PASS: TestAccDirectConnectConnectionsDataSource_empty (19.47s)
--- PASS: TestAccDirectConnectConnectionsDataSource_tags (24.84s)
--- PASS: TestAccDirectConnectConnectionsDataSource_basic (25.55s)
--- PASS: TestAccDirectConnectConnectionsDataSource_region (25.59s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/directconnect      33.768s

Unit tests additionally cover pagination across page boundaries, the element-attribute contract, and the empty-list/empty-map flattening, with no credentials required:

% go test ./internal/service/directconnect/ -run 'TestConnectionsDataSource|TestFindConnections' -count=1 -v

--- PASS: TestConnectionsDataSourceSchema_noSyntheticID (0.00s)
--- PASS: TestFindConnectionsNoMatchIsNotAnError (0.00s)
--- PASS: TestFindConnectionsFilterSpansPages (0.00s)
--- PASS: TestFindConnectionsPaginates (0.00s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/directconnect      9.817s

golangci-lint is clean across all five .ci/.golangci*.yml configs, semgrep is clean for the constants, naming and code-quality configs, providerlint is clean, swissshepherd reports All checks passed. for both documentation pages, and go generate ./internal/service/directconnect/ reproduces the generated files byte-for-byte.


AI Usage Disclosure

This pull request was prepared with assistance from an AI agent — specifically, a custom agent running inside Claude Code. The agent was configured for this repository (branching conventions, make gen awareness, no manual edits to _gen.go, smarterr patterns, AutoFlex, Framework patterns, acceptance-test scaffolding) and used for code generation, test authoring, and documentation. Every line has been reviewed by the human contributor, who has verified the code compiles and understands each design decision. Per the project's AI Usage Policy, "🤖🤖🤖" is included in the PR title.

Adds a plural data source returning every Direct Connect connection in the
Region, for the common case of iterating connections without knowing their
names up front.

Also makes findConnections paginate. It is shared by the aws_dx_connection
data source and resource, so this fixes silent truncation past 100
connections for those two as well.

Closes hashicorp#40032
@BenjaminSaintCyr
BenjaminSaintCyr requested a review from a team as a code owner July 28, 2026 16:57
@dosubot dosubot Bot added the new-data-source Introduces a new data source. label Jul 28, 2026
@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

✅ Thank you for correcting the previously detected issues! The maintainers appreciate your efforts to make the review process as smooth as possible.

@github-actions

Copy link
Copy Markdown
Contributor

Community Guidelines

This comment is added to every new Pull Request to provide quick reference to how the Terraform AWS Provider is maintained. Please review the information below, and thank you for contributing to the community that keeps the provider thriving! 🚀

Voting for Prioritization

  • Please vote on this Pull Request by adding a 👍 reaction to the original post to help the community and maintainers prioritize it.
  • Please see our prioritization guide for additional information on how the maintainers handle prioritization.
  • Please do not leave +1 or other comments that do not add relevant new information or questions; they generate extra noise for others following the Pull Request and do not help prioritize the request.

Pull Request Authors

  • Review the contribution guide relating to the type of change you are making to ensure all of the necessary steps have been taken.
  • 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 needs-triage Waiting for first response or review from a maintainer. documentation Introduces or discusses updates to documentation. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. service/directconnect Issues and PRs that pertain to the directconnect service. generators Relates to code generators. size/XL Managed by automation to categorize the size of a PR. labels Jul 28, 2026
@BenjaminSaintCyr BenjaminSaintCyr changed the title d/aws_dx_connections: New data source 🤖🤖🤖 d/aws_dx_connections: New data source Jul 28, 2026
Use names.Attr* and acctest.Ct* constants for attribute-name literals,
extract the unit-test fixture Regions into lintignore:AWSAT003 constants,
rename TestFlattenConnectionsTagsIgnoreAWS, and mark flattenConnections
nosemgrep with the reason AutoFlex cannot cover the ARN and tags fields.
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. needs-triage Waiting for first response or review from a maintainer. new-data-source Introduces a new data source. service/directconnect Issues and PRs that pertain to the directconnect service. size/XL Managed by automation to categorize the size of a PR. 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.

[New Data Source]: aws_dx_connections

1 participant