1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package ec2
4
5import (
6	"context"
7	"fmt"
8	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
9	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
10	"github.com/aws/aws-sdk-go-v2/service/ec2/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Describes one or more attachments between resources and transit gateways. By
16// default, all attachments are described. Alternatively, you can filter the
17// results by attachment ID, attachment state, resource ID, or resource owner.
18func (c *Client) DescribeTransitGatewayAttachments(ctx context.Context, params *DescribeTransitGatewayAttachmentsInput, optFns ...func(*Options)) (*DescribeTransitGatewayAttachmentsOutput, error) {
19	if params == nil {
20		params = &DescribeTransitGatewayAttachmentsInput{}
21	}
22
23	result, metadata, err := c.invokeOperation(ctx, "DescribeTransitGatewayAttachments", params, optFns, addOperationDescribeTransitGatewayAttachmentsMiddlewares)
24	if err != nil {
25		return nil, err
26	}
27
28	out := result.(*DescribeTransitGatewayAttachmentsOutput)
29	out.ResultMetadata = metadata
30	return out, nil
31}
32
33type DescribeTransitGatewayAttachmentsInput struct {
34
35	// Checks whether you have the required permissions for the action, without
36	// actually making the request, and provides an error response. If you have the
37	// required permissions, the error response is DryRunOperation. Otherwise, it is
38	// UnauthorizedOperation.
39	DryRun bool
40
41	// One or more filters. The possible values are:
42	//
43	// * association.state - The state
44	// of the association (associating | associated | disassociating).
45	//
46	// *
47	// association.transit-gateway-route-table-id - The ID of the route table for the
48	// transit gateway.
49	//
50	// * resource-id - The ID of the resource.
51	//
52	// * resource-owner-id -
53	// The ID of the AWS account that owns the resource.
54	//
55	// * resource-type - The
56	// resource type. Valid values are vpc | vpn | direct-connect-gateway | peering |
57	// connect.
58	//
59	// * state - The state of the attachment. Valid values are available |
60	// deleted | deleting | failed | failing | initiatingRequest | modifying |
61	// pendingAcceptance | pending | rollingBack | rejected | rejecting.
62	//
63	// *
64	// transit-gateway-attachment-id - The ID of the attachment.
65	//
66	// * transit-gateway-id
67	// - The ID of the transit gateway.
68	//
69	// * transit-gateway-owner-id - The ID of the AWS
70	// account that owns the transit gateway.
71	Filters []types.Filter
72
73	// The maximum number of results to return with a single call. To retrieve the
74	// remaining results, make another call with the returned nextToken value.
75	MaxResults int32
76
77	// The token for the next page of results.
78	NextToken *string
79
80	// The IDs of the attachments.
81	TransitGatewayAttachmentIds []string
82}
83
84type DescribeTransitGatewayAttachmentsOutput struct {
85
86	// The token to use to retrieve the next page of results. This value is null when
87	// there are no more results to return.
88	NextToken *string
89
90	// Information about the attachments.
91	TransitGatewayAttachments []types.TransitGatewayAttachment
92
93	// Metadata pertaining to the operation's result.
94	ResultMetadata middleware.Metadata
95}
96
97func addOperationDescribeTransitGatewayAttachmentsMiddlewares(stack *middleware.Stack, options Options) (err error) {
98	err = stack.Serialize.Add(&awsEc2query_serializeOpDescribeTransitGatewayAttachments{}, middleware.After)
99	if err != nil {
100		return err
101	}
102	err = stack.Deserialize.Add(&awsEc2query_deserializeOpDescribeTransitGatewayAttachments{}, middleware.After)
103	if err != nil {
104		return err
105	}
106	if err = addSetLoggerMiddleware(stack, options); err != nil {
107		return err
108	}
109	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
110		return err
111	}
112	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
113		return err
114	}
115	if err = addResolveEndpointMiddleware(stack, options); err != nil {
116		return err
117	}
118	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
119		return err
120	}
121	if err = addRetryMiddlewares(stack, options); err != nil {
122		return err
123	}
124	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
125		return err
126	}
127	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
128		return err
129	}
130	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
131		return err
132	}
133	if err = addClientUserAgent(stack); err != nil {
134		return err
135	}
136	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
137		return err
138	}
139	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
140		return err
141	}
142	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDescribeTransitGatewayAttachments(options.Region), middleware.Before); err != nil {
143		return err
144	}
145	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
146		return err
147	}
148	if err = addResponseErrorMiddleware(stack); err != nil {
149		return err
150	}
151	if err = addRequestResponseLogging(stack, options); err != nil {
152		return err
153	}
154	return nil
155}
156
157// DescribeTransitGatewayAttachmentsAPIClient is a client that implements the
158// DescribeTransitGatewayAttachments operation.
159type DescribeTransitGatewayAttachmentsAPIClient interface {
160	DescribeTransitGatewayAttachments(context.Context, *DescribeTransitGatewayAttachmentsInput, ...func(*Options)) (*DescribeTransitGatewayAttachmentsOutput, error)
161}
162
163var _ DescribeTransitGatewayAttachmentsAPIClient = (*Client)(nil)
164
165// DescribeTransitGatewayAttachmentsPaginatorOptions is the paginator options for
166// DescribeTransitGatewayAttachments
167type DescribeTransitGatewayAttachmentsPaginatorOptions struct {
168	// The maximum number of results to return with a single call. To retrieve the
169	// remaining results, make another call with the returned nextToken value.
170	Limit int32
171
172	// Set to true if pagination should stop if the service returns a pagination token
173	// that matches the most recent token provided to the service.
174	StopOnDuplicateToken bool
175}
176
177// DescribeTransitGatewayAttachmentsPaginator is a paginator for
178// DescribeTransitGatewayAttachments
179type DescribeTransitGatewayAttachmentsPaginator struct {
180	options   DescribeTransitGatewayAttachmentsPaginatorOptions
181	client    DescribeTransitGatewayAttachmentsAPIClient
182	params    *DescribeTransitGatewayAttachmentsInput
183	nextToken *string
184	firstPage bool
185}
186
187// NewDescribeTransitGatewayAttachmentsPaginator returns a new
188// DescribeTransitGatewayAttachmentsPaginator
189func NewDescribeTransitGatewayAttachmentsPaginator(client DescribeTransitGatewayAttachmentsAPIClient, params *DescribeTransitGatewayAttachmentsInput, optFns ...func(*DescribeTransitGatewayAttachmentsPaginatorOptions)) *DescribeTransitGatewayAttachmentsPaginator {
190	options := DescribeTransitGatewayAttachmentsPaginatorOptions{}
191	if params.MaxResults != 0 {
192		options.Limit = params.MaxResults
193	}
194
195	for _, fn := range optFns {
196		fn(&options)
197	}
198
199	if params == nil {
200		params = &DescribeTransitGatewayAttachmentsInput{}
201	}
202
203	return &DescribeTransitGatewayAttachmentsPaginator{
204		options:   options,
205		client:    client,
206		params:    params,
207		firstPage: true,
208	}
209}
210
211// HasMorePages returns a boolean indicating whether more pages are available
212func (p *DescribeTransitGatewayAttachmentsPaginator) HasMorePages() bool {
213	return p.firstPage || p.nextToken != nil
214}
215
216// NextPage retrieves the next DescribeTransitGatewayAttachments page.
217func (p *DescribeTransitGatewayAttachmentsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*DescribeTransitGatewayAttachmentsOutput, error) {
218	if !p.HasMorePages() {
219		return nil, fmt.Errorf("no more pages available")
220	}
221
222	params := *p.params
223	params.NextToken = p.nextToken
224
225	params.MaxResults = p.options.Limit
226
227	result, err := p.client.DescribeTransitGatewayAttachments(ctx, &params, optFns...)
228	if err != nil {
229		return nil, err
230	}
231	p.firstPage = false
232
233	prevToken := p.nextToken
234	p.nextToken = result.NextToken
235
236	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
237		p.nextToken = nil
238	}
239
240	return result, nil
241}
242
243func newServiceMetadataMiddleware_opDescribeTransitGatewayAttachments(region string) *awsmiddleware.RegisterServiceMetadata {
244	return &awsmiddleware.RegisterServiceMetadata{
245		Region:        region,
246		ServiceID:     ServiceID,
247		SigningName:   "ec2",
248		OperationName: "DescribeTransitGatewayAttachments",
249	}
250}
251