1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package ec2
4
5import (
6	"context"
7	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
8	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
9	"github.com/aws/smithy-go/middleware"
10	smithyhttp "github.com/aws/smithy-go/transport/http"
11)
12
13// Associates an Elastic IP address, or carrier IP address (for instances that are
14// in subnets in Wavelength Zones) with an instance or a network interface. Before
15// you can use an Elastic IP address, you must allocate it to your account. An
16// Elastic IP address is for use in either the EC2-Classic platform or in a VPC.
17// For more information, see Elastic IP Addresses
18// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/elastic-ip-addresses-eip.html)
19// in the Amazon Elastic Compute Cloud User Guide. [EC2-Classic, VPC in an
20// EC2-VPC-only account] If the Elastic IP address is already associated with a
21// different instance, it is disassociated from that instance and associated with
22// the specified instance. If you associate an Elastic IP address with an instance
23// that has an existing Elastic IP address, the existing address is disassociated
24// from the instance, but remains allocated to your account. [VPC in an EC2-Classic
25// account] If you don't specify a private IP address, the Elastic IP address is
26// associated with the primary IP address. If the Elastic IP address is already
27// associated with a different instance or a network interface, you get an error
28// unless you allow reassociation. You cannot associate an Elastic IP address with
29// an instance or network interface that has an existing Elastic IP address.
30// [Subnets in Wavelength Zones] You can associate an IP address from the
31// telecommunication carrier to the instance or network interface. You cannot
32// associate an Elastic IP address with an interface in a different network border
33// group. This is an idempotent operation. If you perform the operation more than
34// once, Amazon EC2 doesn't return an error, and you may be charged for each time
35// the Elastic IP address is remapped to the same instance. For more information,
36// see the Elastic IP Addresses section of Amazon EC2 Pricing
37// (http://aws.amazon.com/ec2/pricing/).
38func (c *Client) AssociateAddress(ctx context.Context, params *AssociateAddressInput, optFns ...func(*Options)) (*AssociateAddressOutput, error) {
39	if params == nil {
40		params = &AssociateAddressInput{}
41	}
42
43	result, metadata, err := c.invokeOperation(ctx, "AssociateAddress", params, optFns, addOperationAssociateAddressMiddlewares)
44	if err != nil {
45		return nil, err
46	}
47
48	out := result.(*AssociateAddressOutput)
49	out.ResultMetadata = metadata
50	return out, nil
51}
52
53type AssociateAddressInput struct {
54
55	// [EC2-VPC] The allocation ID. This is required for EC2-VPC.
56	AllocationId *string
57
58	// [EC2-VPC] For a VPC in an EC2-Classic account, specify true to allow an Elastic
59	// IP address that is already associated with an instance or network interface to
60	// be reassociated with the specified instance or network interface. Otherwise, the
61	// operation fails. In a VPC in an EC2-VPC-only account, reassociation is
62	// automatic, therefore you can specify false to ensure the operation fails if the
63	// Elastic IP address is already associated with another resource.
64	AllowReassociation bool
65
66	// Checks whether you have the required permissions for the action, without
67	// actually making the request, and provides an error response. If you have the
68	// required permissions, the error response is DryRunOperation. Otherwise, it is
69	// UnauthorizedOperation.
70	DryRun bool
71
72	// The ID of the instance. This is required for EC2-Classic. For EC2-VPC, you can
73	// specify either the instance ID or the network interface ID, but not both. The
74	// operation fails if you specify an instance ID unless exactly one network
75	// interface is attached.
76	InstanceId *string
77
78	// [EC2-VPC] The ID of the network interface. If the instance has more than one
79	// network interface, you must specify a network interface ID. For EC2-VPC, you can
80	// specify either the instance ID or the network interface ID, but not both.
81	NetworkInterfaceId *string
82
83	// [EC2-VPC] The primary or secondary private IP address to associate with the
84	// Elastic IP address. If no private IP address is specified, the Elastic IP
85	// address is associated with the primary private IP address.
86	PrivateIpAddress *string
87
88	// The Elastic IP address to associate with the instance. This is required for
89	// EC2-Classic.
90	PublicIp *string
91}
92
93type AssociateAddressOutput struct {
94
95	// [EC2-VPC] The ID that represents the association of the Elastic IP address with
96	// an instance.
97	AssociationId *string
98
99	// Metadata pertaining to the operation's result.
100	ResultMetadata middleware.Metadata
101}
102
103func addOperationAssociateAddressMiddlewares(stack *middleware.Stack, options Options) (err error) {
104	err = stack.Serialize.Add(&awsEc2query_serializeOpAssociateAddress{}, middleware.After)
105	if err != nil {
106		return err
107	}
108	err = stack.Deserialize.Add(&awsEc2query_deserializeOpAssociateAddress{}, middleware.After)
109	if err != nil {
110		return err
111	}
112	if err = addSetLoggerMiddleware(stack, options); err != nil {
113		return err
114	}
115	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
116		return err
117	}
118	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
119		return err
120	}
121	if err = addResolveEndpointMiddleware(stack, options); err != nil {
122		return err
123	}
124	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
125		return err
126	}
127	if err = addRetryMiddlewares(stack, options); err != nil {
128		return err
129	}
130	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
131		return err
132	}
133	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
134		return err
135	}
136	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
137		return err
138	}
139	if err = addClientUserAgent(stack); err != nil {
140		return err
141	}
142	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
143		return err
144	}
145	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
146		return err
147	}
148	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opAssociateAddress(options.Region), middleware.Before); err != nil {
149		return err
150	}
151	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
152		return err
153	}
154	if err = addResponseErrorMiddleware(stack); err != nil {
155		return err
156	}
157	if err = addRequestResponseLogging(stack, options); err != nil {
158		return err
159	}
160	return nil
161}
162
163func newServiceMetadataMiddleware_opAssociateAddress(region string) *awsmiddleware.RegisterServiceMetadata {
164	return &awsmiddleware.RegisterServiceMetadata{
165		Region:        region,
166		ServiceID:     ServiceID,
167		SigningName:   "ec2",
168		OperationName: "AssociateAddress",
169	}
170}
171