Skip to content

Commit 8dd5b0f

Browse files
committed
Add support to specify CIDR from where ssh is allowed on bastion host
1 parent a742732 commit 8dd5b0f

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

modules/bastion/main.tf

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ resource "aws_security_group" "bastion" {
1212
from_port = 22
1313
to_port = 22
1414

15-
cidr_blocks = [
16-
"0.0.0.0/0",
17-
]
15+
cidr_blocks = "${var.allow_ssh_cidrs}"
1816
}
1917

2018
egress {
@@ -46,11 +44,11 @@ data "template_file" "user_data" {
4644
}
4745

4846
resource "aws_launch_configuration" "bastion" {
49-
name_prefix = "${var.name}"
50-
image_id = "${var.ami}"
51-
instance_type = "${var.instance_type}"
52-
key_name = "${var.keypair}"
53-
user_data = "${data.template_file.user_data.rendered}"
47+
name_prefix = "${var.name}"
48+
image_id = "${var.ami}"
49+
instance_type = "${var.instance_type}"
50+
key_name = "${var.keypair}"
51+
user_data = "${data.template_file.user_data.rendered}"
5452
associate_public_ip_address = "${var.associate_public_ip_address}"
5553

5654
security_groups = [

modules/bastion/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ variable "associate_public_ip_address" {
5656
default = true
5757
}
5858

59+
variable "allow_ssh_cidrs" {
60+
description = "List Cidrs from where ssh is to be allowed for bastion host. Default is anywhere"
61+
type = "list"
62+
default = ["0.0.0.0/0"]
63+
}
64+
5965
variable "eip" {
6066
default = ""
6167
}

modules/network.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ variable "bastion_host_keypair" {
6565
default = "bastion-host"
6666
}
6767

68+
variable "bastion_host_allow_ssh_cidrs" {
69+
description = "List Cidrs from where ssh is to be allowed for bastion host. Default is anywhere"
70+
type = "list"
71+
default = ["0.0.0.0/0"]
72+
}
73+
6874
variable "bastion_host_ami_id" {
6975
description = "AMI ID from which the bastian host instance will be created."
7076
default = ""
@@ -164,6 +170,7 @@ module "bastion-host" {
164170
source = "./bastion"
165171
instance_type = "t2.nano"
166172
keypair = "${var.bastion_host_keypair}"
173+
allow_ssh_cidrs = "${var.bastion_host_allow_ssh_cidrs}"
167174
ami = "${var.bastion_host_ami_id}"
168175
region = "${var.aws_region}"
169176
s3_bucket_uri = "s3://${var.config_bucket_name}/keypairs"

0 commit comments

Comments
 (0)