-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.tf
65 lines (55 loc) · 1.49 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
# Security Groups
resource "aws_security_group" "this" {
name = local.name
description = "Security Group for Bastion + Cloud OpenVPN EC2 connector"
vpc_id = var.vpc_id
ingress {
description = "Allow all ingress traffic"
protocol = -1
from_port = 0
to_port = 0
cidr_blocks = var.allowed_cidr_blocks
}
egress {
description = "Allow all egress traffic"
protocol = -1
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Terraform = "true"
Env = var.env
Name = local.name
}
lifecycle {
create_before_destroy = true
}
}
# EC2
resource "aws_instance" "this" {
ami = join("", data.aws_ami.ubuntu_22_04.*.id)
instance_type = var.instance_type
iam_instance_profile = aws_iam_instance_profile.this.name
subnet_id = var.private_subnets[0]
key_name = var.ec2_key_pair_name
vpc_security_group_ids = concat(var.ext_security_groups, [
aws_security_group.this.id
])
associate_public_ip_address = var.public_ip_enabled
lifecycle {
ignore_changes = [user_data, key_name]
}
user_data = var.vpn_enabled ? templatefile("${path.module}/ec2_user_data.sh.tftpl",
{
openvpn_token = var.openvpn_token
}
) : null
tags = {
Terraform = "true"
Env = var.env
Name = local.name
OpenVpn = var.vpn_enabled ? "enabled" : "disabled"
Bastion = var.bastion_enabled ? "enabled" : "disabled"
}
}