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