-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.tf
117 lines (95 loc) · 2.68 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
data "aws_availability_zones" "all" {}
data "aws_ami" "amazon_linux_2" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = ["amzn2-ami-ecs-hvm-*-arm64-ebs"]
}
}
resource "aws_key_pair" "bastion" {
key_name = "bastion-${var.component}-${var.deployment_identifier}"
public_key = file(var.ssh_public_key_path)
}
resource "aws_launch_configuration" "bastion" {
name_prefix = "${var.component}-${var.deployment_identifier}"
image_id = coalesce(var.ami, data.aws_ami.amazon_linux_2.id)
instance_type = local.instance_type
key_name = aws_key_pair.bastion.key_name
associate_public_ip_address = local.associate_public_ip_address
security_groups = [
aws_security_group.allow_ssh_to_bastion.id
]
lifecycle {
create_before_destroy = true
}
}
resource "aws_autoscaling_group" "bastion" {
name = "${var.component}-${var.deployment_identifier}"
vpc_zone_identifier = coalescelist(var.subnet_ids, data.aws_availability_zones.all.names)
launch_configuration = aws_launch_configuration.bastion.name
load_balancers = var.load_balancer_names
min_size = local.minimum_instances
max_size = local.maximum_instances
desired_capacity = local.desired_instances
tag {
key = "Name"
value = "bastion-${var.component}-${var.deployment_identifier}"
propagate_at_launch = true
}
tag {
key = "Component"
value = var.component
propagate_at_launch = true
}
tag {
key = "DeploymentIdentifier"
value = var.deployment_identifier
propagate_at_launch = true
}
tag {
key = "Role"
value = "bastion"
propagate_at_launch = true
}
}
resource "aws_security_group" "allow_ssh_to_bastion" {
name = "allow-ssh-to-bastion-${var.component}-${var.deployment_identifier}"
vpc_id = var.vpc_id
tags = {
Name = "allow-ssh-to-bastion-${var.component}-${var.deployment_identifier}"
Component = var.component
DeploymentIdentifier = var.deployment_identifier
Role = "bastion"
}
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = var.allowed_cidrs
}
egress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = var.egress_cidrs
}
}
resource "aws_security_group" "allow_ssh_from_bastion" {
name = "allow-ssh-from-bastion-${var.component}-${var.deployment_identifier}"
vpc_id = var.vpc_id
tags = {
Name = "allow-ssh-from-bastion-${var.component}-${var.deployment_identifier}"
Component = var.component
DeploymentIdentifier = var.deployment_identifier
Role = "bastion"
}
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
security_groups = [
aws_security_group.allow_ssh_to_bastion.id
]
}
}