-
Notifications
You must be signed in to change notification settings - Fork 19
/
launch_template.tf
64 lines (54 loc) · 1.49 KB
/
launch_template.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
data "cloudinit_config" "config" {
gzip = false
base64_encode = true
part {
content_type = "text/x-shellscript"
content = <<EOT
#!/bin/bash
echo ECS_CLUSTER="${local.name}" >> /etc/ecs/ecs.config
echo ECS_ENABLE_CONTAINER_METADATA=true >> /etc/ecs/ecs.config
echo ECS_ENABLE_SPOT_INSTANCE_DRAINING=${tostring(var.spot)} >> /etc/ecs/ecs.config
EOT
}
dynamic "part" {
for_each = local.user_data
content {
content_type = "text/x-shellscript"
content = part.value
}
}
}
resource "aws_launch_template" "node" {
name_prefix = "ecs_node_"
image_id = local.ami_id
instance_type = keys(local.instance_types)[0]
vpc_security_group_ids = local.public ? [] : local.sg_ids
user_data = data.cloudinit_config.config.rendered
tags = local.tags
update_default_version = true
network_interfaces {
associate_public_ip_address = local.public
security_groups = local.sg_ids
}
iam_instance_profile {
name = aws_iam_instance_profile.ecs_node.name
}
dynamic "block_device_mappings" {
for_each = local.ebs_disks
content {
device_name = block_device_mappings.key
ebs {
volume_size = block_device_mappings.value
volume_type = "gp3"
}
}
}
tag_specifications {
resource_type = "instance"
tags = local.tags
}
tag_specifications {
resource_type = "volume"
tags = local.tags
}
}