/
getAmi.go
468 lines (415 loc) · 19 KB
/
getAmi.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
// Code generated by the Pulumi Terraform Bridge (tfgen) Tool DO NOT EDIT.
// *** WARNING: Do not edit by hand unless you're certain you know what you are doing! ***
package ec2
import (
"context"
"reflect"
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/internal"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
// Use this data source to get the ID of a registered AMI for use in other
// resources.
//
// ## Example Usage
//
// <!--Start PulumiCodeChooser -->
// ```go
// package main
//
// import (
//
// "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2"
// "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
//
// )
//
// func main() {
// pulumi.Run(func(ctx *pulumi.Context) error {
// _, err := ec2.LookupAmi(ctx, &ec2.LookupAmiArgs{
// ExecutableUsers: []string{
// "self",
// },
// MostRecent: pulumi.BoolRef(true),
// NameRegex: pulumi.StringRef("^myami-\\d{3}"),
// Owners: []string{
// "self",
// },
// Filters: []ec2.GetAmiFilter{
// {
// Name: "name",
// Values: []string{
// "myami-*",
// },
// },
// {
// Name: "root-device-type",
// Values: []string{
// "ebs",
// },
// },
// {
// Name: "virtualization-type",
// Values: []string{
// "hvm",
// },
// },
// },
// }, nil)
// if err != nil {
// return err
// }
// return nil
// })
// }
//
// ```
// <!--End PulumiCodeChooser -->
func LookupAmi(ctx *pulumi.Context, args *LookupAmiArgs, opts ...pulumi.InvokeOption) (*LookupAmiResult, error) {
opts = internal.PkgInvokeDefaultOpts(opts)
var rv LookupAmiResult
err := ctx.Invoke("aws:ec2/getAmi:getAmi", args, &rv, opts...)
if err != nil {
return nil, err
}
return &rv, nil
}
// A collection of arguments for invoking getAmi.
type LookupAmiArgs struct {
// Limit search to users with *explicit* launch permission on
// the image. Valid items are the numeric account ID or `self`.
ExecutableUsers []string `pulumi:"executableUsers"`
// One or more name/value pairs to filter off of. There are
// several valid keys, for a full reference, check out
// [describe-images in the AWS CLI reference][1].
Filters []GetAmiFilter `pulumi:"filters"`
// If true, all deprecated AMIs are included in the response. If false, no deprecated AMIs are included in the response. If no value is specified, the default value is false.
IncludeDeprecated *bool `pulumi:"includeDeprecated"`
// If more than one result is returned, use the most
// recent AMI.
MostRecent *bool `pulumi:"mostRecent"`
// Regex string to apply to the AMI list returned
// by AWS. This allows more advanced filtering not supported from the AWS API. This
// filtering is done locally on what AWS returns, and could have a performance
// impact if the result is large. Combine this with other
// options to narrow down the list AWS returns.
//
// > **NOTE:** If more or less than a single match is returned by the search,
// this call will fail. Ensure that your search is specific enough to return
// a single AMI ID only, or use `mostRecent` to choose the most recent one. If
// you want to match multiple AMIs, use the `ec2.getAmiIds` data source instead.
NameRegex *string `pulumi:"nameRegex"`
// List of AMI owners to limit search. Valid values: an AWS account ID, `self` (the current account), or an AWS owner alias (e.g., `amazon`, `aws-marketplace`, `microsoft`).
Owners []string `pulumi:"owners"`
// Any tags assigned to the image.
// * `tags.#.key` - Key name of the tag.
// * `tags.#.value` - Value of the tag.
Tags map[string]string `pulumi:"tags"`
}
// A collection of values returned by getAmi.
type LookupAmiResult struct {
// OS architecture of the AMI (ie: `i386` or `x8664`).
Architecture string `pulumi:"architecture"`
// ARN of the AMI.
Arn string `pulumi:"arn"`
// Set of objects with block device mappings of the AMI.
BlockDeviceMappings []GetAmiBlockDeviceMapping `pulumi:"blockDeviceMappings"`
// Boot mode of the image.
BootMode string `pulumi:"bootMode"`
// Date and time the image was created.
CreationDate string `pulumi:"creationDate"`
// Date and time when the image will be deprecated.
DeprecationTime string `pulumi:"deprecationTime"`
// Description of the AMI that was provided during image
// creation.
Description string `pulumi:"description"`
// Whether enhanced networking with ENA is enabled.
EnaSupport bool `pulumi:"enaSupport"`
ExecutableUsers []string `pulumi:"executableUsers"`
Filters []GetAmiFilter `pulumi:"filters"`
// Hypervisor type of the image.
Hypervisor string `pulumi:"hypervisor"`
// The provider-assigned unique ID for this managed resource.
Id string `pulumi:"id"`
// ID of the AMI. Should be the same as the resource `id`.
ImageId string `pulumi:"imageId"`
// Location of the AMI.
ImageLocation string `pulumi:"imageLocation"`
// AWS account alias (for example, `amazon`, `self`) or
// the AWS account ID of the AMI owner.
ImageOwnerAlias string `pulumi:"imageOwnerAlias"`
// Type of image.
ImageType string `pulumi:"imageType"`
// Instance Metadata Service (IMDS) support mode for the image. Set to `v2.0` if instances ran from this image enforce IMDSv2.
ImdsSupport string `pulumi:"imdsSupport"`
IncludeDeprecated *bool `pulumi:"includeDeprecated"`
// Kernel associated with the image, if any. Only applicable
// for machine images.
KernelId string `pulumi:"kernelId"`
MostRecent *bool `pulumi:"mostRecent"`
// Name of the AMI that was provided during image creation.
Name string `pulumi:"name"`
NameRegex *string `pulumi:"nameRegex"`
// AWS account ID of the image owner.
OwnerId string `pulumi:"ownerId"`
Owners []string `pulumi:"owners"`
// Value is Windows for `Windows` AMIs; otherwise blank.
Platform string `pulumi:"platform"`
// Platform details associated with the billing code of the AMI.
PlatformDetails string `pulumi:"platformDetails"`
// Any product codes associated with the AMI.
// * `product_codes.#.product_code_id` - The product code.
// * `product_codes.#.product_code_type` - The type of product code.
ProductCodes []GetAmiProductCode `pulumi:"productCodes"`
// `true` if the image has public launch permissions.
Public bool `pulumi:"public"`
// RAM disk associated with the image, if any. Only applicable
// for machine images.
RamdiskId string `pulumi:"ramdiskId"`
// Device name of the root device.
RootDeviceName string `pulumi:"rootDeviceName"`
// Type of root device (ie: `ebs` or `instance-store`).
RootDeviceType string `pulumi:"rootDeviceType"`
// Snapshot id associated with the root device, if any
// (only applies to `ebs` root devices).
RootSnapshotId string `pulumi:"rootSnapshotId"`
// Whether enhanced networking is enabled.
SriovNetSupport string `pulumi:"sriovNetSupport"`
// Current state of the AMI. If the state is `available`, the image
// is successfully registered and can be used to launch an instance.
State string `pulumi:"state"`
// Describes a state change. Fields are `UNSET` if not available.
StateReason map[string]string `pulumi:"stateReason"`
// Any tags assigned to the image.
// * `tags.#.key` - Key name of the tag.
// * `tags.#.value` - Value of the tag.
Tags map[string]string `pulumi:"tags"`
// If the image is configured for NitroTPM support, the value is `v2.0`.
TpmSupport string `pulumi:"tpmSupport"`
// Operation of the Amazon EC2 instance and the billing code that is associated with the AMI.
UsageOperation string `pulumi:"usageOperation"`
// Type of virtualization of the AMI (ie: `hvm` or
// `paravirtual`).
VirtualizationType string `pulumi:"virtualizationType"`
}
func LookupAmiOutput(ctx *pulumi.Context, args LookupAmiOutputArgs, opts ...pulumi.InvokeOption) LookupAmiResultOutput {
return pulumi.ToOutputWithContext(context.Background(), args).
ApplyT(func(v interface{}) (LookupAmiResult, error) {
args := v.(LookupAmiArgs)
r, err := LookupAmi(ctx, &args, opts...)
var s LookupAmiResult
if r != nil {
s = *r
}
return s, err
}).(LookupAmiResultOutput)
}
// A collection of arguments for invoking getAmi.
type LookupAmiOutputArgs struct {
// Limit search to users with *explicit* launch permission on
// the image. Valid items are the numeric account ID or `self`.
ExecutableUsers pulumi.StringArrayInput `pulumi:"executableUsers"`
// One or more name/value pairs to filter off of. There are
// several valid keys, for a full reference, check out
// [describe-images in the AWS CLI reference][1].
Filters GetAmiFilterArrayInput `pulumi:"filters"`
// If true, all deprecated AMIs are included in the response. If false, no deprecated AMIs are included in the response. If no value is specified, the default value is false.
IncludeDeprecated pulumi.BoolPtrInput `pulumi:"includeDeprecated"`
// If more than one result is returned, use the most
// recent AMI.
MostRecent pulumi.BoolPtrInput `pulumi:"mostRecent"`
// Regex string to apply to the AMI list returned
// by AWS. This allows more advanced filtering not supported from the AWS API. This
// filtering is done locally on what AWS returns, and could have a performance
// impact if the result is large. Combine this with other
// options to narrow down the list AWS returns.
//
// > **NOTE:** If more or less than a single match is returned by the search,
// this call will fail. Ensure that your search is specific enough to return
// a single AMI ID only, or use `mostRecent` to choose the most recent one. If
// you want to match multiple AMIs, use the `ec2.getAmiIds` data source instead.
NameRegex pulumi.StringPtrInput `pulumi:"nameRegex"`
// List of AMI owners to limit search. Valid values: an AWS account ID, `self` (the current account), or an AWS owner alias (e.g., `amazon`, `aws-marketplace`, `microsoft`).
Owners pulumi.StringArrayInput `pulumi:"owners"`
// Any tags assigned to the image.
// * `tags.#.key` - Key name of the tag.
// * `tags.#.value` - Value of the tag.
Tags pulumi.StringMapInput `pulumi:"tags"`
}
func (LookupAmiOutputArgs) ElementType() reflect.Type {
return reflect.TypeOf((*LookupAmiArgs)(nil)).Elem()
}
// A collection of values returned by getAmi.
type LookupAmiResultOutput struct{ *pulumi.OutputState }
func (LookupAmiResultOutput) ElementType() reflect.Type {
return reflect.TypeOf((*LookupAmiResult)(nil)).Elem()
}
func (o LookupAmiResultOutput) ToLookupAmiResultOutput() LookupAmiResultOutput {
return o
}
func (o LookupAmiResultOutput) ToLookupAmiResultOutputWithContext(ctx context.Context) LookupAmiResultOutput {
return o
}
// OS architecture of the AMI (ie: `i386` or `x8664`).
func (o LookupAmiResultOutput) Architecture() pulumi.StringOutput {
return o.ApplyT(func(v LookupAmiResult) string { return v.Architecture }).(pulumi.StringOutput)
}
// ARN of the AMI.
func (o LookupAmiResultOutput) Arn() pulumi.StringOutput {
return o.ApplyT(func(v LookupAmiResult) string { return v.Arn }).(pulumi.StringOutput)
}
// Set of objects with block device mappings of the AMI.
func (o LookupAmiResultOutput) BlockDeviceMappings() GetAmiBlockDeviceMappingArrayOutput {
return o.ApplyT(func(v LookupAmiResult) []GetAmiBlockDeviceMapping { return v.BlockDeviceMappings }).(GetAmiBlockDeviceMappingArrayOutput)
}
// Boot mode of the image.
func (o LookupAmiResultOutput) BootMode() pulumi.StringOutput {
return o.ApplyT(func(v LookupAmiResult) string { return v.BootMode }).(pulumi.StringOutput)
}
// Date and time the image was created.
func (o LookupAmiResultOutput) CreationDate() pulumi.StringOutput {
return o.ApplyT(func(v LookupAmiResult) string { return v.CreationDate }).(pulumi.StringOutput)
}
// Date and time when the image will be deprecated.
func (o LookupAmiResultOutput) DeprecationTime() pulumi.StringOutput {
return o.ApplyT(func(v LookupAmiResult) string { return v.DeprecationTime }).(pulumi.StringOutput)
}
// Description of the AMI that was provided during image
// creation.
func (o LookupAmiResultOutput) Description() pulumi.StringOutput {
return o.ApplyT(func(v LookupAmiResult) string { return v.Description }).(pulumi.StringOutput)
}
// Whether enhanced networking with ENA is enabled.
func (o LookupAmiResultOutput) EnaSupport() pulumi.BoolOutput {
return o.ApplyT(func(v LookupAmiResult) bool { return v.EnaSupport }).(pulumi.BoolOutput)
}
func (o LookupAmiResultOutput) ExecutableUsers() pulumi.StringArrayOutput {
return o.ApplyT(func(v LookupAmiResult) []string { return v.ExecutableUsers }).(pulumi.StringArrayOutput)
}
func (o LookupAmiResultOutput) Filters() GetAmiFilterArrayOutput {
return o.ApplyT(func(v LookupAmiResult) []GetAmiFilter { return v.Filters }).(GetAmiFilterArrayOutput)
}
// Hypervisor type of the image.
func (o LookupAmiResultOutput) Hypervisor() pulumi.StringOutput {
return o.ApplyT(func(v LookupAmiResult) string { return v.Hypervisor }).(pulumi.StringOutput)
}
// The provider-assigned unique ID for this managed resource.
func (o LookupAmiResultOutput) Id() pulumi.StringOutput {
return o.ApplyT(func(v LookupAmiResult) string { return v.Id }).(pulumi.StringOutput)
}
// ID of the AMI. Should be the same as the resource `id`.
func (o LookupAmiResultOutput) ImageId() pulumi.StringOutput {
return o.ApplyT(func(v LookupAmiResult) string { return v.ImageId }).(pulumi.StringOutput)
}
// Location of the AMI.
func (o LookupAmiResultOutput) ImageLocation() pulumi.StringOutput {
return o.ApplyT(func(v LookupAmiResult) string { return v.ImageLocation }).(pulumi.StringOutput)
}
// AWS account alias (for example, `amazon`, `self`) or
// the AWS account ID of the AMI owner.
func (o LookupAmiResultOutput) ImageOwnerAlias() pulumi.StringOutput {
return o.ApplyT(func(v LookupAmiResult) string { return v.ImageOwnerAlias }).(pulumi.StringOutput)
}
// Type of image.
func (o LookupAmiResultOutput) ImageType() pulumi.StringOutput {
return o.ApplyT(func(v LookupAmiResult) string { return v.ImageType }).(pulumi.StringOutput)
}
// Instance Metadata Service (IMDS) support mode for the image. Set to `v2.0` if instances ran from this image enforce IMDSv2.
func (o LookupAmiResultOutput) ImdsSupport() pulumi.StringOutput {
return o.ApplyT(func(v LookupAmiResult) string { return v.ImdsSupport }).(pulumi.StringOutput)
}
func (o LookupAmiResultOutput) IncludeDeprecated() pulumi.BoolPtrOutput {
return o.ApplyT(func(v LookupAmiResult) *bool { return v.IncludeDeprecated }).(pulumi.BoolPtrOutput)
}
// Kernel associated with the image, if any. Only applicable
// for machine images.
func (o LookupAmiResultOutput) KernelId() pulumi.StringOutput {
return o.ApplyT(func(v LookupAmiResult) string { return v.KernelId }).(pulumi.StringOutput)
}
func (o LookupAmiResultOutput) MostRecent() pulumi.BoolPtrOutput {
return o.ApplyT(func(v LookupAmiResult) *bool { return v.MostRecent }).(pulumi.BoolPtrOutput)
}
// Name of the AMI that was provided during image creation.
func (o LookupAmiResultOutput) Name() pulumi.StringOutput {
return o.ApplyT(func(v LookupAmiResult) string { return v.Name }).(pulumi.StringOutput)
}
func (o LookupAmiResultOutput) NameRegex() pulumi.StringPtrOutput {
return o.ApplyT(func(v LookupAmiResult) *string { return v.NameRegex }).(pulumi.StringPtrOutput)
}
// AWS account ID of the image owner.
func (o LookupAmiResultOutput) OwnerId() pulumi.StringOutput {
return o.ApplyT(func(v LookupAmiResult) string { return v.OwnerId }).(pulumi.StringOutput)
}
func (o LookupAmiResultOutput) Owners() pulumi.StringArrayOutput {
return o.ApplyT(func(v LookupAmiResult) []string { return v.Owners }).(pulumi.StringArrayOutput)
}
// Value is Windows for `Windows` AMIs; otherwise blank.
func (o LookupAmiResultOutput) Platform() pulumi.StringOutput {
return o.ApplyT(func(v LookupAmiResult) string { return v.Platform }).(pulumi.StringOutput)
}
// Platform details associated with the billing code of the AMI.
func (o LookupAmiResultOutput) PlatformDetails() pulumi.StringOutput {
return o.ApplyT(func(v LookupAmiResult) string { return v.PlatformDetails }).(pulumi.StringOutput)
}
// Any product codes associated with the AMI.
// * `product_codes.#.product_code_id` - The product code.
// * `product_codes.#.product_code_type` - The type of product code.
func (o LookupAmiResultOutput) ProductCodes() GetAmiProductCodeArrayOutput {
return o.ApplyT(func(v LookupAmiResult) []GetAmiProductCode { return v.ProductCodes }).(GetAmiProductCodeArrayOutput)
}
// `true` if the image has public launch permissions.
func (o LookupAmiResultOutput) Public() pulumi.BoolOutput {
return o.ApplyT(func(v LookupAmiResult) bool { return v.Public }).(pulumi.BoolOutput)
}
// RAM disk associated with the image, if any. Only applicable
// for machine images.
func (o LookupAmiResultOutput) RamdiskId() pulumi.StringOutput {
return o.ApplyT(func(v LookupAmiResult) string { return v.RamdiskId }).(pulumi.StringOutput)
}
// Device name of the root device.
func (o LookupAmiResultOutput) RootDeviceName() pulumi.StringOutput {
return o.ApplyT(func(v LookupAmiResult) string { return v.RootDeviceName }).(pulumi.StringOutput)
}
// Type of root device (ie: `ebs` or `instance-store`).
func (o LookupAmiResultOutput) RootDeviceType() pulumi.StringOutput {
return o.ApplyT(func(v LookupAmiResult) string { return v.RootDeviceType }).(pulumi.StringOutput)
}
// Snapshot id associated with the root device, if any
// (only applies to `ebs` root devices).
func (o LookupAmiResultOutput) RootSnapshotId() pulumi.StringOutput {
return o.ApplyT(func(v LookupAmiResult) string { return v.RootSnapshotId }).(pulumi.StringOutput)
}
// Whether enhanced networking is enabled.
func (o LookupAmiResultOutput) SriovNetSupport() pulumi.StringOutput {
return o.ApplyT(func(v LookupAmiResult) string { return v.SriovNetSupport }).(pulumi.StringOutput)
}
// Current state of the AMI. If the state is `available`, the image
// is successfully registered and can be used to launch an instance.
func (o LookupAmiResultOutput) State() pulumi.StringOutput {
return o.ApplyT(func(v LookupAmiResult) string { return v.State }).(pulumi.StringOutput)
}
// Describes a state change. Fields are `UNSET` if not available.
func (o LookupAmiResultOutput) StateReason() pulumi.StringMapOutput {
return o.ApplyT(func(v LookupAmiResult) map[string]string { return v.StateReason }).(pulumi.StringMapOutput)
}
// Any tags assigned to the image.
// * `tags.#.key` - Key name of the tag.
// * `tags.#.value` - Value of the tag.
func (o LookupAmiResultOutput) Tags() pulumi.StringMapOutput {
return o.ApplyT(func(v LookupAmiResult) map[string]string { return v.Tags }).(pulumi.StringMapOutput)
}
// If the image is configured for NitroTPM support, the value is `v2.0`.
func (o LookupAmiResultOutput) TpmSupport() pulumi.StringOutput {
return o.ApplyT(func(v LookupAmiResult) string { return v.TpmSupport }).(pulumi.StringOutput)
}
// Operation of the Amazon EC2 instance and the billing code that is associated with the AMI.
func (o LookupAmiResultOutput) UsageOperation() pulumi.StringOutput {
return o.ApplyT(func(v LookupAmiResult) string { return v.UsageOperation }).(pulumi.StringOutput)
}
// Type of virtualization of the AMI (ie: `hvm` or
// `paravirtual`).
func (o LookupAmiResultOutput) VirtualizationType() pulumi.StringOutput {
return o.ApplyT(func(v LookupAmiResult) string { return v.VirtualizationType }).(pulumi.StringOutput)
}
func init() {
pulumi.RegisterOutputType(LookupAmiResultOutput{})
}