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 specified attribute of the specified instance. You can specify only
15// one attribute at a time. Note: Using this action to change the security groups
16// associated with an elastic network interface (ENI) attached to an instance in a
17// VPC can result in an error if the instance has more than one ENI. To change the
18// security groups associated with an ENI attached to an instance that has multiple
19// ENIs, we recommend that you use the ModifyNetworkInterfaceAttribute action. To
20// modify some attributes, the instance must be stopped. For more information, see
21// Modifying attributes of a stopped instance
22// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_ChangingAttributesWhileInstanceStopped.html)
23// in the Amazon EC2 User Guide.
24func (c *Client) ModifyInstanceAttribute(ctx context.Context, params *ModifyInstanceAttributeInput, optFns ...func(*Options)) (*ModifyInstanceAttributeOutput, error) {
25	if params == nil {
26		params = &ModifyInstanceAttributeInput{}
27	}
28
29	result, metadata, err := c.invokeOperation(ctx, "ModifyInstanceAttribute", params, optFns, addOperationModifyInstanceAttributeMiddlewares)
30	if err != nil {
31		return nil, err
32	}
33
34	out := result.(*ModifyInstanceAttributeOutput)
35	out.ResultMetadata = metadata
36	return out, nil
37}
38
39type ModifyInstanceAttributeInput struct {
40
41	// The ID of the instance.
42	//
43	// This member is required.
44	InstanceId *string
45
46	// The name of the attribute.
47	Attribute types.InstanceAttributeName
48
49	// Modifies the DeleteOnTermination attribute for volumes that are currently
50	// attached. The volume must be owned by the caller. If no value is specified for
51	// DeleteOnTermination, the default is true and the volume is deleted when the
52	// instance is terminated. To add instance store volumes to an Amazon EBS-backed
53	// instance, you must add them when you launch the instance. For more information,
54	// see Updating the block device mapping when launching an instance
55	// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/block-device-mapping-concepts.html#Using_OverridingAMIBDM)
56	// in the Amazon EC2 User Guide.
57	BlockDeviceMappings []types.InstanceBlockDeviceMappingSpecification
58
59	// If the value is true, you can't terminate the instance using the Amazon EC2
60	// console, CLI, or API; otherwise, you can. You cannot use this parameter for Spot
61	// Instances.
62	DisableApiTermination *types.AttributeBooleanValue
63
64	// Checks whether you have the required permissions for the action, without
65	// actually making the request, and provides an error response. If you have the
66	// required permissions, the error response is DryRunOperation. Otherwise, it is
67	// UnauthorizedOperation.
68	DryRun bool
69
70	// Specifies whether the instance is optimized for Amazon EBS I/O. This
71	// optimization provides dedicated throughput to Amazon EBS and an optimized
72	// configuration stack to provide optimal EBS I/O performance. This optimization
73	// isn't available with all instance types. Additional usage charges apply when
74	// using an EBS Optimized instance.
75	EbsOptimized *types.AttributeBooleanValue
76
77	// Set to true to enable enhanced networking with ENA for the instance. This option
78	// is supported only for HVM instances. Specifying this option with a PV instance
79	// can make it unreachable.
80	EnaSupport *types.AttributeBooleanValue
81
82	// [EC2-VPC] Changes the security groups of the instance. You must specify at least
83	// one security group, even if it's just the default security group for the VPC.
84	// You must specify the security group ID, not the security group name.
85	Groups []string
86
87	// Specifies whether an instance stops or terminates when you initiate shutdown
88	// from the instance (using the operating system command for system shutdown).
89	InstanceInitiatedShutdownBehavior *types.AttributeValue
90
91	// Changes the instance type to the specified value. For more information, see
92	// Instance types
93	// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html) in the
94	// Amazon EC2 User Guide. If the instance type is not valid, the error returned is
95	// InvalidInstanceAttributeValue.
96	InstanceType *types.AttributeValue
97
98	// Changes the instance's kernel to the specified value. We recommend that you use
99	// PV-GRUB instead of kernels and RAM disks. For more information, see PV-GRUB
100	// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/UserProvidedKernels.html).
101	Kernel *types.AttributeValue
102
103	// Changes the instance's RAM disk to the specified value. We recommend that you
104	// use PV-GRUB instead of kernels and RAM disks. For more information, see PV-GRUB
105	// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/UserProvidedKernels.html).
106	Ramdisk *types.AttributeValue
107
108	// Specifies whether source/destination checking is enabled. A value of true means
109	// that checking is enabled, and false means that checking is disabled. This value
110	// must be false for a NAT instance to perform NAT.
111	SourceDestCheck *types.AttributeBooleanValue
112
113	// Set to simple to enable enhanced networking with the Intel 82599 Virtual
114	// Function interface for the instance. There is no way to disable enhanced
115	// networking with the Intel 82599 Virtual Function interface at this time. This
116	// option is supported only for HVM instances. Specifying this option with a PV
117	// instance can make it unreachable.
118	SriovNetSupport *types.AttributeValue
119
120	// Changes the instance's user data to the specified value. If you are using an AWS
121	// SDK or command line tool, base64-encoding is performed for you, and you can load
122	// the text from a file. Otherwise, you must provide base64-encoded text.
123	UserData *types.BlobAttributeValue
124
125	// A new value for the attribute. Use only with the kernel, ramdisk, userData,
126	// disableApiTermination, or instanceInitiatedShutdownBehavior attribute.
127	Value *string
128}
129
130type ModifyInstanceAttributeOutput struct {
131	// Metadata pertaining to the operation's result.
132	ResultMetadata middleware.Metadata
133}
134
135func addOperationModifyInstanceAttributeMiddlewares(stack *middleware.Stack, options Options) (err error) {
136	err = stack.Serialize.Add(&awsEc2query_serializeOpModifyInstanceAttribute{}, middleware.After)
137	if err != nil {
138		return err
139	}
140	err = stack.Deserialize.Add(&awsEc2query_deserializeOpModifyInstanceAttribute{}, middleware.After)
141	if err != nil {
142		return err
143	}
144	if err = addSetLoggerMiddleware(stack, options); err != nil {
145		return err
146	}
147	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
148		return err
149	}
150	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
151		return err
152	}
153	if err = addResolveEndpointMiddleware(stack, options); err != nil {
154		return err
155	}
156	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
157		return err
158	}
159	if err = addRetryMiddlewares(stack, options); err != nil {
160		return err
161	}
162	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
163		return err
164	}
165	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
166		return err
167	}
168	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
169		return err
170	}
171	if err = addClientUserAgent(stack); err != nil {
172		return err
173	}
174	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
175		return err
176	}
177	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
178		return err
179	}
180	if err = addOpModifyInstanceAttributeValidationMiddleware(stack); err != nil {
181		return err
182	}
183	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opModifyInstanceAttribute(options.Region), middleware.Before); err != nil {
184		return err
185	}
186	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
187		return err
188	}
189	if err = addResponseErrorMiddleware(stack); err != nil {
190		return err
191	}
192	if err = addRequestResponseLogging(stack, options); err != nil {
193		return err
194	}
195	return nil
196}
197
198func newServiceMetadataMiddleware_opModifyInstanceAttribute(region string) *awsmiddleware.RegisterServiceMetadata {
199	return &awsmiddleware.RegisterServiceMetadata{
200		Region:        region,
201		ServiceID:     ServiceID,
202		SigningName:   "ec2",
203		OperationName: "ModifyInstanceAttribute",
204	}
205}
206