-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.tf
65 lines (57 loc) · 2.33 KB
/
main.tf
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
data "aws_region" "current" {}
locals {
region = data.aws_region.current.name
update_component = var.update ? (var.platform == "Linux" ? ["arn:aws:imagebuilder:${local.region}:aws:component/update-linux/x.x.x"] : ["arn:aws:imagebuilder:${local.region}:aws:component/update-windows/x.x.x"]) : []
component_arns = concat(local.update_component, var.component_arns)
}
resource "aws_imagebuilder_image_recipe" "this" {
name = var.name
version = var.recipe_version
description = var.description
parent_image = var.parent_image
user_data_base64 = var.user_data_base64
working_directory = var.working_directory
systems_manager_agent {
uninstall_after_build = var.systems_manager_agent_uninstall_after_build
}
tags = merge(
var.tags,
{
"Name" = var.name
}
)
dynamic "block_device_mapping" {
for_each = var.block_device_mappings
content {
device_name = lookup(block_device_mapping.value, "device_name", null)
no_device = lookup(block_device_mapping.value, "no_device", null)
virtual_name = lookup(block_device_mapping.value, "virtual_name", null)
dynamic "ebs" {
for_each = length(lookup(block_device_mapping.value, "ebs", {})) == 0 ? [] : [lookup(block_device_mapping.value, "ebs", {})]
content {
delete_on_termination = lookup(ebs.value, "delete_on_termination", null)
encrypted = lookup(ebs.value, "encrypted", null)
iops = lookup(ebs.value, "iops", null)
kms_key_id = lookup(ebs.value, "kms_key_id", null)
snapshot_id = lookup(ebs.value, "snapshot_id", null)
throughput = lookup(ebs.value, "throughput", null)
volume_size = lookup(ebs.value, "volume_size", null)
volume_type = lookup(ebs.value, "volume_type", null)
}
}
}
}
dynamic "component" {
for_each = local.component_arns
content {
component_arn = component.value
dynamic "parameter" {
for_each = length(lookup(var.component_parameters, component.value, [])) == 0 ? [] : lookup(var.component_parameters, component.value, [])
content {
name = lookup(parameter.value, "name", null)
value = lookup(parameter.value, "value", null)
}
}
}
}
}