-
Notifications
You must be signed in to change notification settings - Fork 0
/
describe_ec2_instances.fp
62 lines (52 loc) · 1.95 KB
/
describe_ec2_instances.fp
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
pipeline "describe_ec2_instances" {
title = "Describe EC2 Instances"
description = "Describes the specified instances or all instances."
param "cred" {
type = string
description = local.cred_param_description
default = "default"
}
param "region" {
type = string
description = local.region_param_description
}
param "instance_ids" {
type = list(string)
description = "The instance IDs."
optional = true
}
param "instance_type" {
type = string
description = "The type of instance (for example, t2.micro)."
optional = true
}
param "ebs_optimized" {
type = bool
description = "A Boolean that indicates whether the instance is optimized for Amazon EBS I/O."
optional = true
}
param "tags" {
type = map(string)
description = "One or more tags. If specified, only those instances that match the tags are returned."
optional = true
}
step "container" "describe_ec2_instances" {
image = "public.ecr.aws/aws-cli/aws-cli"
cmd = concat(
["ec2", "describe-instances"],
try(length(param.instance_ids), 0) > 0 ? concat(["--instance-ids"], param.instance_ids) : [],
param.instance_type != null ? ["--filters", "Name=instance-type,Values=${param.instance_type}"] : [],
param.ebs_optimized != null ? ["--filters", "Name=ebs-optimized,Values=${param.ebs_optimized}"] : [],
param.tags != null ? flatten([
["--filters"],
[for k, v in param.tags : concat(["Name=tag:${k},Values=${v}"])]
]) : []
)
env = merge(credential.aws[param.cred].env, { AWS_REGION = param.region })
}
# Transform the reservation list of instance lists into a single list of instances for output.
output "instances" {
description = "Information about one or more EC2 instances."
value = flatten(jsondecode(step.container.describe_ec2_instances.stdout).Reservations.*.Instances)
}
}