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	"time"
14)
15
16// Creates an EBS volume that can be attached to an instance in the same
17// Availability Zone. You can create a new empty volume or restore a volume from an
18// EBS snapshot. Any Amazon Web Services Marketplace product codes from the
19// snapshot are propagated to the volume. You can create encrypted volumes.
20// Encrypted volumes must be attached to instances that support Amazon EBS
21// encryption. Volumes that are created from encrypted snapshots are also
22// automatically encrypted. For more information, see Amazon EBS encryption
23// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSEncryption.html) in the
24// Amazon Elastic Compute Cloud User Guide. You can tag your volumes during
25// creation. For more information, see Tag your Amazon EC2 resources
26// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html) in the
27// Amazon Elastic Compute Cloud User Guide. For more information, see Create an
28// Amazon EBS volume
29// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-creating-volume.html)
30// in the Amazon Elastic Compute Cloud User Guide.
31func (c *Client) CreateVolume(ctx context.Context, params *CreateVolumeInput, optFns ...func(*Options)) (*CreateVolumeOutput, error) {
32	if params == nil {
33		params = &CreateVolumeInput{}
34	}
35
36	result, metadata, err := c.invokeOperation(ctx, "CreateVolume", params, optFns, c.addOperationCreateVolumeMiddlewares)
37	if err != nil {
38		return nil, err
39	}
40
41	out := result.(*CreateVolumeOutput)
42	out.ResultMetadata = metadata
43	return out, nil
44}
45
46type CreateVolumeInput struct {
47
48	// The Availability Zone in which to create the volume.
49	//
50	// This member is required.
51	AvailabilityZone *string
52
53	// Unique, case-sensitive identifier that you provide to ensure the idempotency of
54	// the request. For more information, see Ensure Idempotency
55	// (https://docs.aws.amazon.com/AWSEC2/latest/APIReference/Run_Instance_Idempotency.html).
56	ClientToken *string
57
58	// Checks whether you have the required permissions for the action, without
59	// actually making the request, and provides an error response. If you have the
60	// required permissions, the error response is DryRunOperation. Otherwise, it is
61	// UnauthorizedOperation.
62	DryRun *bool
63
64	// Indicates whether the volume should be encrypted. The effect of setting the
65	// encryption state to true depends on the volume origin (new or from a snapshot),
66	// starting encryption state, ownership, and whether encryption by default is
67	// enabled. For more information, see Encryption by default
68	// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSEncryption.html#encryption-by-default)
69	// in the Amazon Elastic Compute Cloud User Guide. Encrypted Amazon EBS volumes
70	// must be attached to instances that support Amazon EBS encryption. For more
71	// information, see Supported instance types
72	// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSEncryption.html#EBSEncryption_supported_instances).
73	Encrypted *bool
74
75	// The number of I/O operations per second (IOPS). For gp3, io1, and io2 volumes,
76	// this represents the number of IOPS that are provisioned for the volume. For gp2
77	// volumes, this represents the baseline performance of the volume and the rate at
78	// which the volume accumulates I/O credits for bursting. The following are the
79	// supported values for each volume type:
80	//
81	// * gp3: 3,000-16,000 IOPS
82	//
83	// * io1:
84	// 100-64,000 IOPS
85	//
86	// * io2: 100-64,000 IOPS
87	//
88	// io1 and io2 volumes support up to
89	// 64,000 IOPS only on Instances built on the Nitro System
90	// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html#ec2-nitro-instances).
91	// Other instance families support performance up to 32,000 IOPS. This parameter is
92	// required for io1 and io2 volumes. The default for gp3 volumes is 3,000 IOPS.
93	// This parameter is not supported for gp2, st1, sc1, or standard volumes.
94	Iops *int32
95
96	// The identifier of the Key Management Service (KMS) KMS key to use for Amazon EBS
97	// encryption. If this parameter is not specified, your KMS key for Amazon EBS is
98	// used. If KmsKeyId is specified, the encrypted state must be true. You can
99	// specify the KMS key using any of the following:
100	//
101	// * Key ID. For example,
102	// 1234abcd-12ab-34cd-56ef-1234567890ab.
103	//
104	// * Key alias. For example,
105	// alias/ExampleAlias.
106	//
107	// * Key ARN. For example,
108	// arn:aws:kms:us-east-1:012345678910:key/1234abcd-12ab-34cd-56ef-1234567890ab.
109	//
110	// *
111	// Alias ARN. For example,
112	// arn:aws:kms:us-east-1:012345678910:alias/ExampleAlias.
113	//
114	// Amazon Web Services
115	// authenticates the KMS key asynchronously. Therefore, if you specify an ID,
116	// alias, or ARN that is not valid, the action can appear to complete, but
117	// eventually fails.
118	KmsKeyId *string
119
120	// Indicates whether to enable Amazon EBS Multi-Attach. If you enable Multi-Attach,
121	// you can attach the volume to up to 16 Instances built on the Nitro System
122	// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html#ec2-nitro-instances)
123	// in the same Availability Zone. This parameter is supported with io1 and io2
124	// volumes only. For more information, see  Amazon EBS Multi-Attach
125	// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-volumes-multi.html) in
126	// the Amazon Elastic Compute Cloud User Guide.
127	MultiAttachEnabled *bool
128
129	// The Amazon Resource Name (ARN) of the Outpost.
130	OutpostArn *string
131
132	// The size of the volume, in GiBs. You must specify either a snapshot ID or a
133	// volume size. If you specify a snapshot, the default is the snapshot size. You
134	// can specify a volume size that is equal to or larger than the snapshot size. The
135	// following are the supported volumes sizes for each volume type:
136	//
137	// * gp2 and gp3:
138	// 1-16,384
139	//
140	// * io1 and io2: 4-16,384
141	//
142	// * st1 and sc1: 125-16,384
143	//
144	// * standard:
145	// 1-1,024
146	Size *int32
147
148	// The snapshot from which to create the volume. You must specify either a snapshot
149	// ID or a volume size.
150	SnapshotId *string
151
152	// The tags to apply to the volume during creation.
153	TagSpecifications []types.TagSpecification
154
155	// The throughput to provision for a volume, with a maximum of 1,000 MiB/s. This
156	// parameter is valid only for gp3 volumes. Valid Range: Minimum value of 125.
157	// Maximum value of 1000.
158	Throughput *int32
159
160	// The volume type. This parameter can be one of the following values:
161	//
162	// * General
163	// Purpose SSD: gp2 | gp3
164	//
165	// * Provisioned IOPS SSD: io1 | io2
166	//
167	// * Throughput
168	// Optimized HDD: st1
169	//
170	// * Cold HDD: sc1
171	//
172	// * Magnetic: standard
173	//
174	// For more information,
175	// see Amazon EBS volume types
176	// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSVolumeTypes.html) in the
177	// Amazon Elastic Compute Cloud User Guide. Default: gp2
178	VolumeType types.VolumeType
179
180	noSmithyDocumentSerde
181}
182
183// Describes a volume.
184type CreateVolumeOutput struct {
185
186	// Information about the volume attachments.
187	Attachments []types.VolumeAttachment
188
189	// The Availability Zone for the volume.
190	AvailabilityZone *string
191
192	// The time stamp when volume creation was initiated.
193	CreateTime *time.Time
194
195	// Indicates whether the volume is encrypted.
196	Encrypted *bool
197
198	// Indicates whether the volume was created using fast snapshot restore.
199	FastRestored *bool
200
201	// The number of I/O operations per second (IOPS). For gp3, io1, and io2 volumes,
202	// this represents the number of IOPS that are provisioned for the volume. For gp2
203	// volumes, this represents the baseline performance of the volume and the rate at
204	// which the volume accumulates I/O credits for bursting.
205	Iops *int32
206
207	// The Amazon Resource Name (ARN) of the Key Management Service (KMS) KMS key that
208	// was used to protect the volume encryption key for the volume.
209	KmsKeyId *string
210
211	// Indicates whether Amazon EBS Multi-Attach is enabled.
212	MultiAttachEnabled *bool
213
214	// The Amazon Resource Name (ARN) of the Outpost.
215	OutpostArn *string
216
217	// The size of the volume, in GiBs.
218	Size *int32
219
220	// The snapshot from which the volume was created, if applicable.
221	SnapshotId *string
222
223	// The volume state.
224	State types.VolumeState
225
226	// Any tags assigned to the volume.
227	Tags []types.Tag
228
229	// The throughput that the volume supports, in MiB/s.
230	Throughput *int32
231
232	// The ID of the volume.
233	VolumeId *string
234
235	// The volume type.
236	VolumeType types.VolumeType
237
238	// Metadata pertaining to the operation's result.
239	ResultMetadata middleware.Metadata
240
241	noSmithyDocumentSerde
242}
243
244func (c *Client) addOperationCreateVolumeMiddlewares(stack *middleware.Stack, options Options) (err error) {
245	err = stack.Serialize.Add(&awsEc2query_serializeOpCreateVolume{}, middleware.After)
246	if err != nil {
247		return err
248	}
249	err = stack.Deserialize.Add(&awsEc2query_deserializeOpCreateVolume{}, middleware.After)
250	if err != nil {
251		return err
252	}
253	if err = addSetLoggerMiddleware(stack, options); err != nil {
254		return err
255	}
256	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
257		return err
258	}
259	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
260		return err
261	}
262	if err = addResolveEndpointMiddleware(stack, options); err != nil {
263		return err
264	}
265	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
266		return err
267	}
268	if err = addRetryMiddlewares(stack, options); err != nil {
269		return err
270	}
271	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
272		return err
273	}
274	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
275		return err
276	}
277	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
278		return err
279	}
280	if err = addClientUserAgent(stack); err != nil {
281		return err
282	}
283	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
284		return err
285	}
286	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
287		return err
288	}
289	if err = addIdempotencyToken_opCreateVolumeMiddleware(stack, options); err != nil {
290		return err
291	}
292	if err = addOpCreateVolumeValidationMiddleware(stack); err != nil {
293		return err
294	}
295	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCreateVolume(options.Region), middleware.Before); err != nil {
296		return err
297	}
298	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
299		return err
300	}
301	if err = addResponseErrorMiddleware(stack); err != nil {
302		return err
303	}
304	if err = addRequestResponseLogging(stack, options); err != nil {
305		return err
306	}
307	return nil
308}
309
310type idempotencyToken_initializeOpCreateVolume struct {
311	tokenProvider IdempotencyTokenProvider
312}
313
314func (*idempotencyToken_initializeOpCreateVolume) ID() string {
315	return "OperationIdempotencyTokenAutoFill"
316}
317
318func (m *idempotencyToken_initializeOpCreateVolume) HandleInitialize(ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler) (
319	out middleware.InitializeOutput, metadata middleware.Metadata, err error,
320) {
321	if m.tokenProvider == nil {
322		return next.HandleInitialize(ctx, in)
323	}
324
325	input, ok := in.Parameters.(*CreateVolumeInput)
326	if !ok {
327		return out, metadata, fmt.Errorf("expected middleware input to be of type *CreateVolumeInput ")
328	}
329
330	if input.ClientToken == nil {
331		t, err := m.tokenProvider.GetIdempotencyToken()
332		if err != nil {
333			return out, metadata, err
334		}
335		input.ClientToken = &t
336	}
337	return next.HandleInitialize(ctx, in)
338}
339func addIdempotencyToken_opCreateVolumeMiddleware(stack *middleware.Stack, cfg Options) error {
340	return stack.Initialize.Add(&idempotencyToken_initializeOpCreateVolume{tokenProvider: cfg.IdempotencyTokenProvider}, middleware.Before)
341}
342
343func newServiceMetadataMiddleware_opCreateVolume(region string) *awsmiddleware.RegisterServiceMetadata {
344	return &awsmiddleware.RegisterServiceMetadata{
345		Region:        region,
346		ServiceID:     ServiceID,
347		SigningName:   "ec2",
348		OperationName: "CreateVolume",
349	}
350}
351