-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstances.tf
77 lines (66 loc) · 2.38 KB
/
instances.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
76
77
# ----------------------------------------------------
# Instances
# ----------------------------------------------------
# --------------------------
# AMI - Amazon Linux 2
# --------------------------
data "aws_ami" "amazon_linux_2" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = ["amzn2-ami-hvm-*-x86_64-ebs"]
}
}
resource "aws_network_interface" "awsvpn_gw_eni" {
subnet_id = local.subnet_id
security_groups = [aws_security_group.awsvpn_gw_eni_security_group.id]
source_dest_check = false
tags = merge(local.global_tags)
}
resource "aws_eip" "awsvpn_gw_eni_eip" {
vpc = true
network_interface = aws_network_interface.awsvpn_gw_eni.id
lifecycle {
prevent_destroy = true
}
tags = merge(local.global_tags,
map("Name", "${var.environment}-awsvpn-GW"))
}
resource "aws_network_interface" "awsvpn_nat_eni" {
subnet_id = local.subnet_id
security_groups = [aws_security_group.awsvpn_nat_eni_security_group.id]
source_dest_check = false
tags = merge(local.global_tags)
}
resource "aws_eip" "awsvpn_nat_eni_eip" {
vpc = true
network_interface = aws_network_interface.awsvpn_nat_eni.id
lifecycle {
prevent_destroy = true
}
tags = merge(local.global_tags,
map("Name", "${var.environment}-awsvpn-NAT"))
}
resource "aws_instance" "awsvpn" {
count = var.enable_awsvpn ? 2 : 0
ami = data.aws_ami.amazon_linux_2.id
instance_type = var.awsvpn_instance_type
key_name = var.environment
vpc_security_group_ids = [aws_security_group.awsvpn_instance_security_group.id]
subnet_id = local.public_subnets[0]
associate_public_ip_address = true
source_dest_check = false
iam_instance_profile = aws_iam_instance_profile.awsvpn_profile.name
root_block_device {
volume_type = "gp2"
volume_size = 50
delete_on_termination = "true"
}
user_data = data.template_cloudinit_config.awsvpn_user_data[count.index].rendered
depends_on = [aws_s3_bucket_object.ipsec_updown_netkey]
tags = merge(
local.global_tags,
map("Name", "${var.environment}-awsvpn-${count.index + 1}",
"KeepalivedRole", var.keepalivedrole[count.index]))
}