Skip to content

Commit

Permalink
Add support to specify CIDR from where ssh is allowed on bastion host
Browse files Browse the repository at this point in the history
  • Loading branch information
hazim1093 committed Aug 29, 2017
1 parent a742732 commit 8dd5b0f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
14 changes: 6 additions & 8 deletions modules/bastion/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ resource "aws_security_group" "bastion" {
from_port = 22
to_port = 22

cidr_blocks = [
"0.0.0.0/0",
]
cidr_blocks = "${var.allow_ssh_cidrs}"
}

egress {
Expand Down Expand Up @@ -46,11 +44,11 @@ data "template_file" "user_data" {
}

resource "aws_launch_configuration" "bastion" {
name_prefix = "${var.name}"
image_id = "${var.ami}"
instance_type = "${var.instance_type}"
key_name = "${var.keypair}"
user_data = "${data.template_file.user_data.rendered}"
name_prefix = "${var.name}"
image_id = "${var.ami}"
instance_type = "${var.instance_type}"
key_name = "${var.keypair}"
user_data = "${data.template_file.user_data.rendered}"
associate_public_ip_address = "${var.associate_public_ip_address}"

security_groups = [
Expand Down
6 changes: 6 additions & 0 deletions modules/bastion/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ variable "associate_public_ip_address" {
default = true
}

variable "allow_ssh_cidrs" {
description = "List Cidrs from where ssh is to be allowed for bastion host. Default is anywhere"
type = "list"
default = ["0.0.0.0/0"]
}

variable "eip" {
default = ""
}
7 changes: 7 additions & 0 deletions modules/network.tf
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ variable "bastion_host_keypair" {
default = "bastion-host"
}

variable "bastion_host_allow_ssh_cidrs" {
description = "List Cidrs from where ssh is to be allowed for bastion host. Default is anywhere"
type = "list"
default = ["0.0.0.0/0"]
}

variable "bastion_host_ami_id" {
description = "AMI ID from which the bastian host instance will be created."
default = ""
Expand Down Expand Up @@ -164,6 +170,7 @@ module "bastion-host" {
source = "./bastion"
instance_type = "t2.nano"
keypair = "${var.bastion_host_keypair}"
allow_ssh_cidrs = "${var.bastion_host_allow_ssh_cidrs}"
ami = "${var.bastion_host_ami_id}"
region = "${var.aws_region}"
s3_bucket_uri = "s3://${var.config_bucket_name}/keypairs"
Expand Down

0 comments on commit 8dd5b0f

Please sign in to comment.