Open eandresr opened 9 months ago
Voting for Prioritization
Volunteering to Work on This Issue
Hello,
I think it would need something like the following in the internal/service/directconnect/gateway_association.go --> func resourceGatewayAssociationRead
// ########### START OF NEW ATTACHMENT PART OBTAINER ##############
if output.AssociatedGateway.Type == "transitGateway" {
directConnectGatewayID := d.Get("dx_gateway_id").(string)
attachmentConn := meta.(*conns.AWSClient).EC2Conn(ctx)
var transitGatewayAttach []*ec2.TransitGatewayAttachment
inputAttachment := &ec2.DescribeTransitGatewayAttachmentsInput{
Filters: BuildAttributeFilterList(map[string]string{
"resource-type": ec2.TransitGatewayAttachmentResourceTypeDirectConnectGateway,
"resource-id": directConnectGatewayID
}),
}
err := attachmentConn.DescribeTransitGatewayAttachmentsPagesWithContext(ctx, inputAttachment, func(page *ec2.DescribeTransitGatewayAttachmentsOutput, lastPage bool) bool {
if page == nil {
return !lastPage
}
for _, v := range page.TransitGatewayAttachments {
if v != nil {
transitGatewayAttach = append(output, v)
}
}
return !lastPage
})
if tfawserr.ErrCodeEquals(err, errCodeInvalidTransitGatewayAttachmentIDNotFound) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: input,
}
}
if err != nil {
return nil, err
}
d.Set("dx_gateway_attachment_id", transitGatewayAttach[0])
} else {
d.Set("dx_gateway_attachment_id", nil)
}
// ########### END OF NEW ATTACHMENT PART OBTAINER ##############
And the following in the Schema
"dx_gateway_attachment_id": {
Type: schema.TypeString,
Computed: true,
},
Description
Hello,
As data source with aws_ec2_transit_gateway_dx_gateway_attachment fails when referencing to an resouce created in the same workspace (even with depends_on), it would be great to have the tgw-attach-id output in the resource aws_dx_gateway_association as the Transit Gateway Attachment is created automatically and you also have to wait till the association (it takes a lot of time, so 1 or 2 minutes more are not important). This way you can avoid several error and re-plan/apply in TF
I know it is not common because DxC is not as extended as for example VPN, but it is used in big Enterprises where errors in plans are not welcome. Thank you.
Affected Resource(s) and/or Data Source(s)
aws_dx_gateway_association
Potential Terraform Configuration
No response
References
No response
Would you like to implement a fix?
None