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

New Datasource: aws_ec2_transit_gateway_attachments (plural) #25745

Closed
mkielar opened this issue Jul 8, 2022 · 4 comments · Fixed by #29644
Closed

New Datasource: aws_ec2_transit_gateway_attachments (plural) #25745

mkielar opened this issue Jul 8, 2022 · 4 comments · Fixed by #29644
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/transitgateway Issues and PRs that pertain to the transitgateway service.
Milestone

Comments

@mkielar
Copy link
Contributor

mkielar commented Jul 8, 2022

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • 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
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

AWS provides the DescribeTransitGatewayAttachments API Call, which returns all existing Transit Gateway Attachments, regardless of their type. This datasource could replace existing aws_ec2_transit_gateway_vpc_attachments introduced in #11880, and be implemented instead of #25744 and #25743, as it's, simply speaking, more generic and handles all use cases.

New or Affected Resource(s)

  • aws_ec2_transit_gateway_attachments

Potential Terraform Configuration

data "aws_ec2_transit_gateway_attachments" "attachments" {
  filter {
    name = "state"
    values = [
      "available"
    ]
  }
  filter {
    name = "transit-gateway-id"
    values = [
      var.tgw_id
    ]
  }
}

The new datasource would then expose all attributes as described in TransitGatewayAttachment, including the resourceType which is the discriminator for VPC / VPN / Peering / etc. attachments.

References

@mkielar mkielar added the enhancement Requests to existing resources that expand the functionality or scope. label Jul 8, 2022
@github-actions github-actions bot added needs-triage Waiting for first response or review from a maintainer. service/transitgateway Issues and PRs that pertain to the transitgateway service. labels Jul 8, 2022
@justinretzolk justinretzolk removed the needs-triage Waiting for first response or review from a maintainer. label Jul 8, 2022
@crawforde
Copy link

crawforde commented Jul 29, 2022

This is critically needed, as AWS does not offer the same filter options on some of its other describe endpoints. For example, I am not able to look up a peering attachment by the ID of the requesting transit gateway resource when I use the endpoint that describes peering attachments, but I can look up attachments by this filter using the more generic API endpoint. This is necessary for certain cross-account, cross-region peering scenarios, which I currently am unable to automate with terraform. Having this endpoint available would create viable workarounds for issues like this one: #24677

@bodgit
Copy link
Contributor

bodgit commented Sep 6, 2022

Just came looking for this as it turns out all of the current Transit Gateway attachment data sources are all singular and error if there's no results (or more than one).

My use case is having a Transit Gateway associated with a Direct Connect Gateway in another account using an association proposal. When that is accepted in the peer account, the attachment automatically appears in this account so I need to be able to do something like:

resource "aws_dx_gateway_association_proposal" "example" {
  dx_gateway_id               = var.dx_gateway_id
  dx_gateway_owner_account_id = var.dx_gateway_owner_account_id
  associated_gateway_id       = module.tgw.ec2_transit_gateway_id
}

# Association should then be accepted in the peer account which will create the attachment in this account

data "aws_ec2_transit_gateway_attachments" "example" {
  filter {
    name   = "transit-gateway-id"
    values = [module.tgw.ec2_transit_gateway_id]
  }

  filter {
    name   = "resource-type"
    values = ["direct-connect-gateway"]
  }

  filter {
    name   = "resource-id"
    values = [var.dx_gateway_id]
  }

  filter {
    name   = "state"
    values = ["available"]
  }
}

# Create association/propagation resources using the attachment IDs...

resource "aws_ec2_transit_gateway_route_table_association" "example" {
  for_each = data.aws_ec2_transit_gateway_attachments.example...
  ...
}

resource "aws_ec2_transit_gateway_route_table_propagation" "dxg" {
  for_each = data.aws_ec2_transit_gateway_attachments.example...
  ...
}

Using the existing data source(s), until the association is accepted Terraform errors in this account as there's no matching attachment present. Current workaround is to gate the route table association/propagation resources with a count on an attachment ID variable but I'd like to use a data source.

@github-actions
Copy link

github-actions bot commented Apr 7, 2023

This functionality has been released in v4.62.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

github-actions bot commented May 8, 2023

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/transitgateway Issues and PRs that pertain to the transitgateway service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants