Skip to content

Commit b923ef0

Browse files
authored
Merge pull request #2 from cubicleio/master
Fix some issues
2 parents 4a01d84 + fdabd0b commit b923ef0

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

main.tf

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ resource "aws_security_group" "bastion_host_security_group" {
2525
to_port = 22
2626
cidr_blocks = "${var.cidrs}"
2727
}
28+
egress {
29+
from_port = 443
30+
to_port = 443
31+
protocol = "TCP"
32+
cidr_blocks = ["0.0.0.0/0"]
33+
}
2834
tags = "${merge(var.tags)}"
2935
}
3036

@@ -38,6 +44,7 @@ resource "aws_security_group" "private_instances_security_group" {
3844
security_groups = [
3945
"${aws_security_group.bastion_host_security_group.id}"]
4046
}
47+
4148
tags = "${merge(var.tags)}"
4249
}
4350

@@ -75,17 +82,17 @@ resource "aws_iam_role_policy" "bastion_host_role_policy" {
7582
"s3:PutObject",
7683
"s3:PutObjectAcl"
7784
],
78-
"Resource": "arn:aws:s3:::$${var.bucket_name}/logs/*"
85+
"Resource": "arn:aws:s3:::${var.bucket_name}/logs/*"
7986
},
8087
{
8188
"Effect": "Allow",
8289
"Action": "s3:GetObject",
83-
"Resource": "arn:aws:s3:::$${var.bucket_name}/public-keys/*"
90+
"Resource": "arn:aws:s3:::${var.bucket_name}/public-keys/*"
8491
},
8592
{
8693
"Effect": "Allow",
8794
"Action": "s3:ListBucket",
88-
"Resource": "arn:aws:s3:::$${var.bucket_name}",
95+
"Resource": "arn:aws:s3:::${var.bucket_name}",
8996
"Condition": {
9097
"StringEquals": {
9198
"s3:prefix": "public-keys/"
@@ -123,8 +130,8 @@ resource "aws_lb_target_group" "bastion_lb_target_group" {
123130
health_check {
124131
port = "traffic-port"
125132
protocol = "TCP"
126-
healthy_threshold = 2
127-
unhealthy_threshold = 2
133+
healthy_threshold = "${var.bastion_instance_count}"
134+
unhealthy_threshold = "${var.bastion_instance_count}"
128135
}
129136
tags = "${merge(var.tags)}"
130137
}
@@ -146,7 +153,7 @@ resource "aws_iam_instance_profile" "bastion_host_profile" {
146153

147154
resource "aws_launch_configuration" "bastion_launch_configuration" {
148155
image_id = "${lookup(var.bastion_amis, var.region)}"
149-
instance_type = "t2.micro"
156+
instance_type = "t2.nano"
150157
associate_public_ip_address = true
151158
enable_monitoring = true
152159
iam_instance_profile = "${aws_iam_instance_profile.bastion_host_profile.name}"
@@ -155,20 +162,26 @@ resource "aws_launch_configuration" "bastion_launch_configuration" {
155162
"${aws_security_group.bastion_host_security_group.id}"
156163
]
157164
user_data = "${data.template_file.user_data.rendered}"
165+
lifecycle {
166+
create_before_destroy = true
167+
}
158168
}
159169

160170
resource "aws_autoscaling_group" "bastion_auto_scaling_group" {
161171
launch_configuration = "${aws_launch_configuration.bastion_launch_configuration.name}"
162-
max_size = 2
163-
min_size = 2
164-
desired_capacity = 2
172+
max_size = "${var.bastion_instance_count}"
173+
min_size = "${var.bastion_instance_count}"
174+
desired_capacity = "${var.bastion_instance_count}"
165175
vpc_zone_identifier = [
166-
"${var.auto_scaling_group_subnets}"
176+
"${var.auto_scalling_group_subnets}"
167177
]
168178
default_cooldown = 180
169179
health_check_grace_period = 180
170180
health_check_type = "EC2"
171181
target_group_arns = [
172182
"${aws_lb_target_group.bastion_lb_target_group.arn}"
173183
]
184+
lifecycle {
185+
create_before_destroy = true
186+
}
174187
}

user_data.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ LOG_FILE="/var/log/bastion/users_changelog.txt"
109109
# The function returns the user name from the public key file name.
110110
# Example: public-keys/sshuser.pub => sshuser
111111
get_user_name () {
112-
echo "$1" | sed -e 's/.*\\///g' | sed -e 's/\\.pub//g'
112+
echo "$1" | sed -e "s/.*\\///g" | sed -e "s/\\.pub//g"
113113
}
114114
115115
# For each public key available in the S3 bucket

variables.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,8 @@ variable "bastion_amis" {
6262
"ap-southeast-2" = "ami-0c95b86f"
6363
"sa-east-1" = "ami-fb890097"
6464
}
65-
}
65+
}
66+
67+
variable "bastion_instance_count" {
68+
default = 1
69+
}

0 commit comments

Comments
 (0)