-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathec2.tf
75 lines (58 loc) · 1.41 KB
/
ec2.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
66
67
68
69
70
71
72
73
74
75
data "aws_ami" "main" {
most_recent = true
owners = ["amazon"]
filter {
name = "owner-alias"
values = ["amazon"]
}
filter {
name = "architecture"
values = [var.architecture]
}
filter {
name = "root-device-type"
values = ["ebs"]
}
filter {
name = "name"
values = ["al2023-ami-2023.*"]
}
}
resource "aws_launch_template" "main" {
name = var.name
image_id = data.aws_ami.main.id
instance_type = var.instance_type
block_device_mappings {
device_name = "/dev/xvda"
ebs {
volume_size = var.ebs_root_volume_size
volume_type = "gp3"
}
}
iam_instance_profile {
name = aws_iam_instance_profile.main.name
}
user_data = module.amz-tailscale-client.rendered
network_interfaces {
description = "${var.name} ephemeral network interface"
subnet_id = var.subnet_id
#checkov:skip=CKV_AWS_88:Public IP required for direct tailscale connections
associate_public_ip_address = true
security_groups = [aws_security_group.main.id]
}
dynamic "tag_specifications" {
for_each = ["instance", "network-interface", "volume"]
content {
resource_type = tag_specifications.value
tags = merge(var.tags, {
Name = var.name
})
}
}
# Enforce IMDSv2
metadata_options {
http_endpoint = "enabled"
http_tokens = "required"
}
tags = var.tags
}