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/aws-sdk-go-v2/service/ec2/types"
10	"github.com/aws/smithy-go/middleware"
11	smithyhttp "github.com/aws/smithy-go/transport/http"
12)
13
14// Modifies the placement attributes for a specified instance. You can do the
15// following:
16//
17// * Modify the affinity between an instance and a Dedicated Host
18// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/dedicated-hosts-overview.html).
19// When affinity is set to host and the instance is not associated with a specific
20// Dedicated Host, the next time the instance is launched, it is automatically
21// associated with the host on which it lands. If the instance is restarted or
22// rebooted, this relationship persists.
23//
24// * Change the Dedicated Host with which an
25// instance is associated.
26//
27// * Change the instance tenancy of an instance from host
28// to dedicated, or from dedicated to host.
29//
30// * Move an instance to or from a
31// placement group
32// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/placement-groups.html).
33//
34// At
35// least one attribute for affinity, host ID, tenancy, or placement group name must
36// be specified in the request. Affinity and tenancy can be modified in the same
37// request. To modify the host ID, tenancy, placement group, or partition for an
38// instance, the instance must be in the stopped state.
39func (c *Client) ModifyInstancePlacement(ctx context.Context, params *ModifyInstancePlacementInput, optFns ...func(*Options)) (*ModifyInstancePlacementOutput, error) {
40	if params == nil {
41		params = &ModifyInstancePlacementInput{}
42	}
43
44	result, metadata, err := c.invokeOperation(ctx, "ModifyInstancePlacement", params, optFns, addOperationModifyInstancePlacementMiddlewares)
45	if err != nil {
46		return nil, err
47	}
48
49	out := result.(*ModifyInstancePlacementOutput)
50	out.ResultMetadata = metadata
51	return out, nil
52}
53
54type ModifyInstancePlacementInput struct {
55
56	// The ID of the instance that you are modifying.
57	//
58	// This member is required.
59	InstanceId *string
60
61	// The affinity setting for the instance.
62	Affinity types.Affinity
63
64	// The name of the placement group in which to place the instance. For spread
65	// placement groups, the instance must have a tenancy of default. For cluster and
66	// partition placement groups, the instance must have a tenancy of default or
67	// dedicated. To remove an instance from a placement group, specify an empty string
68	// ("").
69	GroupName *string
70
71	// The ID of the Dedicated Host with which to associate the instance.
72	HostId *string
73
74	// The ARN of the host resource group in which to place the instance.
75	HostResourceGroupArn *string
76
77	// Reserved for future use.
78	PartitionNumber int32
79
80	// The tenancy for the instance.
81	Tenancy types.HostTenancy
82}
83
84type ModifyInstancePlacementOutput struct {
85
86	// Is true if the request succeeds, and an error otherwise.
87	Return bool
88
89	// Metadata pertaining to the operation's result.
90	ResultMetadata middleware.Metadata
91}
92
93func addOperationModifyInstancePlacementMiddlewares(stack *middleware.Stack, options Options) (err error) {
94	err = stack.Serialize.Add(&awsEc2query_serializeOpModifyInstancePlacement{}, middleware.After)
95	if err != nil {
96		return err
97	}
98	err = stack.Deserialize.Add(&awsEc2query_deserializeOpModifyInstancePlacement{}, middleware.After)
99	if err != nil {
100		return err
101	}
102	if err = addSetLoggerMiddleware(stack, options); err != nil {
103		return err
104	}
105	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
106		return err
107	}
108	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
109		return err
110	}
111	if err = addResolveEndpointMiddleware(stack, options); err != nil {
112		return err
113	}
114	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
115		return err
116	}
117	if err = addRetryMiddlewares(stack, options); err != nil {
118		return err
119	}
120	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
121		return err
122	}
123	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
124		return err
125	}
126	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
127		return err
128	}
129	if err = addClientUserAgent(stack); err != nil {
130		return err
131	}
132	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
133		return err
134	}
135	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
136		return err
137	}
138	if err = addOpModifyInstancePlacementValidationMiddleware(stack); err != nil {
139		return err
140	}
141	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opModifyInstancePlacement(options.Region), middleware.Before); err != nil {
142		return err
143	}
144	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
145		return err
146	}
147	if err = addResponseErrorMiddleware(stack); err != nil {
148		return err
149	}
150	if err = addRequestResponseLogging(stack, options); err != nil {
151		return err
152	}
153	return nil
154}
155
156func newServiceMetadataMiddleware_opModifyInstancePlacement(region string) *awsmiddleware.RegisterServiceMetadata {
157	return &awsmiddleware.RegisterServiceMetadata{
158		Region:        region,
159		ServiceID:     ServiceID,
160		SigningName:   "ec2",
161		OperationName: "ModifyInstancePlacement",
162	}
163}
164