forked from BitGo/terraform-aws-bastion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ec2.tf
44 lines (39 loc) · 1.15 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
// Tested in us-west-2
data "aws_ami" "flatcar" {
most_recent = true
owners = ["075585003325"]
filter {
name = "architecture"
values = ["x86_64"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
filter {
name = "name"
values = ["Flatcar-stable-*"]
}
}
locals {
data = jsonencode(jsondecode(templatefile("${path.module}/linux-config/machine.tpl", { allowed_users = var.allowed_users, ssh_port = var.ssh_port, aws_s3_bucket = aws_s3_bucket_website_configuration.ssh_public_keys.website_endpoint })))
}
// Just in case something goes wrong, the AMI ID for us-west-2 flatcar is 'ami-0bb54692374ac10a7'
// Source: https://docs.flatcar-linux.org/os/booting-on-ec2/
//
resource "aws_launch_template" "bastion" {
image_id = data.aws_ami.flatcar.image_id
instance_type = var.instance_type
user_data = base64encode(local.data)
key_name = var.key_name
monitoring {
enabled = true
}
network_interfaces {
security_groups = concat(
[aws_security_group.bastion.id],
var.additional_security_groups,
)
associate_public_ip_address = var.associate_public_ip_address
}
}