1 // Code generated by smithy-go-codegen DO NOT EDIT.
2 3 package lightsail
4 5 import (
6 "context"
7 "fmt"
8 awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
9 "github.com/aws/aws-sdk-go-v2/service/lightsail/types"
10 "github.com/aws/smithy-go/middleware"
11 smithyhttp "github.com/aws/smithy-go/transport/http"
12 )
13 14 // Creates a block storage disk from a manual or automatic snapshot of a disk. The
15 // resulting disk can be attached to an Amazon Lightsail instance in the same
16 // Availability Zone ( us-east-2a ).
17 //
18 // The create disk from snapshot operation supports tag-based access control via
19 // request tags and resource tags applied to the resource identified by disk
20 // snapshot name . For more information, see the [Amazon Lightsail Developer Guide].
21 //
22 // [Amazon Lightsail Developer Guide]: https://docs.aws.amazon.com/lightsail/latest/userguide/amazon-lightsail-controlling-access-using-tags
23 func (c *Client) CreateDiskFromSnapshot(ctx context.Context, params *CreateDiskFromSnapshotInput, optFns ...func(*Options)) (*CreateDiskFromSnapshotOutput, error) {
24 if params == nil {
25 params = &CreateDiskFromSnapshotInput{}
26 }
27 28 result, metadata, err := c.invokeOperation(ctx, "CreateDiskFromSnapshot", params, optFns, c.addOperationCreateDiskFromSnapshotMiddlewares)
29 if err != nil {
30 return nil, err
31 }
32 33 out := result.(*CreateDiskFromSnapshotOutput)
34 out.ResultMetadata = metadata
35 return out, nil
36 }
37 38 type CreateDiskFromSnapshotInput struct {
39 40 // The Availability Zone where you want to create the disk ( us-east-2a ). Choose
41 // the same Availability Zone as the Lightsail instance where you want to create
42 // the disk.
43 //
44 // Use the GetRegions operation to list the Availability Zones where Lightsail is
45 // currently available.
46 //
47 // This member is required.
48 AvailabilityZone *string
49 50 // The unique Lightsail disk name ( my-disk ).
51 //
52 // This member is required.
53 DiskName *string
54 55 // The size of the disk in GB ( 32 ).
56 //
57 // This member is required.
58 SizeInGb *int32
59 60 // An array of objects that represent the add-ons to enable for the new disk.
61 AddOns []types.AddOnRequest
62 63 // The name of the disk snapshot ( my-snapshot ) from which to create the new
64 // storage disk.
65 //
66 // Constraint:
67 //
68 // - This parameter cannot be defined together with the source disk name
69 // parameter. The disk snapshot name and source disk name parameters are mutually
70 // exclusive.
71 DiskSnapshotName *string
72 73 // The date of the automatic snapshot to use for the new disk. Use the get auto
74 // snapshots operation to identify the dates of the available automatic snapshots.
75 //
76 // Constraints:
77 //
78 // - Must be specified in YYYY-MM-DD format.
79 //
80 // - This parameter cannot be defined together with the use latest restorable
81 // auto snapshot parameter. The restore date and use latest restorable auto
82 // snapshot parameters are mutually exclusive.
83 //
84 // - Define this parameter only when creating a new disk from an automatic
85 // snapshot. For more information, see the [Amazon Lightsail Developer Guide].
86 //
87 // [Amazon Lightsail Developer Guide]: https://docs.aws.amazon.com/lightsail/latest/userguide/amazon-lightsail-configuring-automatic-snapshots
88 RestoreDate *string
89 90 // The name of the source disk from which the source automatic snapshot was
91 // created.
92 //
93 // Constraints:
94 //
95 // - This parameter cannot be defined together with the disk snapshot name
96 // parameter. The source disk name and disk snapshot name parameters are mutually
97 // exclusive.
98 //
99 // - Define this parameter only when creating a new disk from an automatic
100 // snapshot. For more information, see the [Amazon Lightsail Developer Guide].
101 //
102 // [Amazon Lightsail Developer Guide]: https://docs.aws.amazon.com/lightsail/latest/userguide/amazon-lightsail-configuring-automatic-snapshots
103 SourceDiskName *string
104 105 // The tag keys and optional values to add to the resource during create.
106 //
107 // Use the TagResource action to tag a resource after it's created.
108 Tags []types.Tag
109 110 // A Boolean value to indicate whether to use the latest available automatic
111 // snapshot.
112 //
113 // Constraints:
114 //
115 // - This parameter cannot be defined together with the restore date parameter.
116 // The use latest restorable auto snapshot and restore date parameters are
117 // mutually exclusive.
118 //
119 // - Define this parameter only when creating a new disk from an automatic
120 // snapshot. For more information, see the [Amazon Lightsail Developer Guide].
121 //
122 // [Amazon Lightsail Developer Guide]: https://docs.aws.amazon.com/lightsail/latest/userguide/amazon-lightsail-configuring-automatic-snapshots
123 UseLatestRestorableAutoSnapshot *bool
124 125 noSmithyDocumentSerde
126 }
127 128 type CreateDiskFromSnapshotOutput struct {
129 130 // An array of objects that describe the result of the action, such as the status
131 // of the request, the timestamp of the request, and the resources affected by the
132 // request.
133 Operations []types.Operation
134 135 // Metadata pertaining to the operation's result.
136 ResultMetadata middleware.Metadata
137 138 noSmithyDocumentSerde
139 }
140 141 func (c *Client) addOperationCreateDiskFromSnapshotMiddlewares(stack *middleware.Stack, options Options) (err error) {
142 if err := stack.Serialize.Add(&setOperationInputMiddleware{}, middleware.After); err != nil {
143 return err
144 }
145 err = stack.Serialize.Add(&awsAwsjson11_serializeOpCreateDiskFromSnapshot{}, middleware.After)
146 if err != nil {
147 return err
148 }
149 err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpCreateDiskFromSnapshot{}, middleware.After)
150 if err != nil {
151 return err
152 }
153 if err := addProtocolFinalizerMiddlewares(stack, options, "CreateDiskFromSnapshot"); err != nil {
154 return fmt.Errorf("add protocol finalizers: %v", err)
155 }
156 157 if err = addlegacyEndpointContextSetter(stack, options); err != nil {
158 return err
159 }
160 if err = addSetLoggerMiddleware(stack, options); err != nil {
161 return err
162 }
163 if err = addClientRequestID(stack); err != nil {
164 return err
165 }
166 if err = addComputeContentLength(stack); err != nil {
167 return err
168 }
169 if err = addResolveEndpointMiddleware(stack, options); err != nil {
170 return err
171 }
172 if err = addComputePayloadSHA256(stack); err != nil {
173 return err
174 }
175 if err = addRetry(stack, options); err != nil {
176 return err
177 }
178 if err = addRawResponseToMetadata(stack); err != nil {
179 return err
180 }
181 if err = addRecordResponseTiming(stack); err != nil {
182 return err
183 }
184 if err = addSpanRetryLoop(stack, options); err != nil {
185 return err
186 }
187 if err = addClientUserAgent(stack, options); err != nil {
188 return err
189 }
190 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
191 return err
192 }
193 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
194 return err
195 }
196 if err = addSetLegacyContextSigningOptionsMiddleware(stack); err != nil {
197 return err
198 }
199 if err = addTimeOffsetBuild(stack, c); err != nil {
200 return err
201 }
202 if err = addUserAgentRetryMode(stack, options); err != nil {
203 return err
204 }
205 if err = addCredentialSource(stack, options); err != nil {
206 return err
207 }
208 if err = addOpCreateDiskFromSnapshotValidationMiddleware(stack); err != nil {
209 return err
210 }
211 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCreateDiskFromSnapshot(options.Region), middleware.Before); err != nil {
212 return err
213 }
214 if err = addRecursionDetection(stack); err != nil {
215 return err
216 }
217 if err = addRequestIDRetrieverMiddleware(stack); err != nil {
218 return err
219 }
220 if err = addResponseErrorMiddleware(stack); err != nil {
221 return err
222 }
223 if err = addRequestResponseLogging(stack, options); err != nil {
224 return err
225 }
226 if err = addDisableHTTPSMiddleware(stack, options); err != nil {
227 return err
228 }
229 if err = addInterceptBeforeRetryLoop(stack, options); err != nil {
230 return err
231 }
232 if err = addInterceptAttempt(stack, options); err != nil {
233 return err
234 }
235 if err = addInterceptors(stack, options); err != nil {
236 return err
237 }
238 return nil
239 }
240 241 func newServiceMetadataMiddleware_opCreateDiskFromSnapshot(region string) *awsmiddleware.RegisterServiceMetadata {
242 return &awsmiddleware.RegisterServiceMetadata{
243 Region: region,
244 ServiceID: ServiceID,
245 OperationName: "CreateDiskFromSnapshot",
246 }
247 }
248