-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.tf
62 lines (52 loc) · 1.41 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
# Security Groups
resource "aws_security_group" "this" {
count = var.enabled ? 1 : 0
name = local.name
description = "Security Group for Cloud OpenVPN+Bastion EC2 Instance (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" {
count = var.enabled ? 1 : 0
ami = join("", data.aws_ami.ubuntu_20_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[0].id
])
disable_api_termination = true
associate_public_ip_address = false
lifecycle {
ignore_changes = all
}
user_data = data.template_file.ec2_user_data.rendered
tags = {
Terraform = "true"
Env = var.env
Name = local.name
}
}