-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlaunch_template.tf
More file actions
86 lines (75 loc) · 2.16 KB
/
launch_template.tf
File metadata and controls
86 lines (75 loc) · 2.16 KB
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
locals {
common_tags = merge(
{
Name = var.name
},
var.tags,
)
}
resource "aws_launch_template" "nat_launch_template" {
count = length(var.availability_zones)
name = "${var.name}-${var.availability_zones[count.index]}-launch-template"
instance_type = var.instance_type
image_id = local.effective_ami_id
iam_instance_profile {
arn = aws_iam_instance_profile.nat_instance_profile.arn
}
block_device_mappings {
device_name = "/dev/xvda"
ebs {
volume_size = var.block_device_size
volume_type = "gp3"
iops = var.block_device_iops
throughput = var.block_device_throughput
encrypted = var.encrypt_root_volume
}
}
dynamic "instance_market_options" {
for_each = var.market_type == "spot" ? [1] : []
content {
market_type = "spot"
spot_options {
spot_instance_type = "one-time"
instance_interruption_behavior = "terminate"
}
}
}
metadata_options {
http_endpoint = "enabled"
http_tokens = "required"
}
network_interfaces {
network_interface_id = aws_network_interface.nat_public_network_interface[count.index].id
device_index = 0
delete_on_termination = false
}
network_interfaces {
device_index = 1
network_interface_id = aws_network_interface.nat_private_network_interface[count.index].id
delete_on_termination = false
}
tag_specifications {
resource_type = "instance"
tags = merge(
local.common_tags,
{
(var.nat_tag_key) = var.nat_tag_value,
Name = "${var.name}-${var.availability_zones[count.index]}-nat-instance"
},
)
}
description = "Launch template for NAT instance ${var.name} in ${var.availability_zones[count.index]}"
tags = merge(
{
AvailabilityZone = var.availability_zones[count.index],
VpcId = var.vpc_id,
},
local.common_tags,
)
lifecycle {
precondition {
condition = local.effective_ami_id != null
error_message = "Set ami_id or configure a resolvable AMI source with ami_owner_account and ami_name_pattern."
}
}
}