Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add var.enabled to toggle on/off #54

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
resource "aws_security_group" "bastion" {
count = "${var.enabled}"
name = "${var.name}"
vpc_id = "${var.vpc_id}"
description = "Bastion security group (only SSH inbound access is allowed)"
Expand All @@ -9,6 +10,7 @@ resource "aws_security_group" "bastion" {
}

resource "aws_security_group_rule" "ssh_ingress" {
count = "${var.enabled}"
type = "ingress"
from_port = "22"
to_port = "22"
Expand All @@ -19,16 +21,17 @@ resource "aws_security_group_rule" "ssh_ingress" {
}

resource "aws_security_group_rule" "ssh_sg_ingress" {
count = "${length(var.allowed_security_groups)}"
count = "${length(var.allowed_security_groups) * var.enabled}"
type = "ingress"
from_port = "22"
to_port = "22"
protocol = "tcp"
source_security_group_id = "${element(var.allowed_security_groups, count.index)}"
source_security_group_id = "${length(var.allowed_security_groups) > 0 ? element(concat(var.allowed_security_groups, list("")), count.index) : ""}"
security_group_id = "${aws_security_group.bastion.id}"
}

resource "aws_security_group_rule" "bastion_all_egress" {
count = "${var.enabled}"
type = "egress"
from_port = "0"
to_port = "65535"
Expand Down Expand Up @@ -59,6 +62,8 @@ data "template_file" "user_data" {
}

//resource "aws_instance" "bastion" {
// count = "${var.enabled}"

// ami = "${var.ami}"
// instance_type = "${var.instance_type}"
// iam_instance_profile = "${var.iam_instance_profile}"
Expand All @@ -74,6 +79,7 @@ data "template_file" "user_data" {
//}

resource "aws_launch_configuration" "bastion" {
count = "${var.enabled}"
name_prefix = "${var.name}-"
image_id = "${var.ami}"
instance_type = "${var.instance_type}"
Expand All @@ -98,7 +104,8 @@ resource "aws_launch_configuration" "bastion" {
}

resource "aws_autoscaling_group" "bastion" {
name = "${var.apply_changes_immediately ? aws_launch_configuration.bastion.name : var.name}"
count = "${var.enabled}"
name = "${var.apply_changes_immediately ? aws_launch_configuration.bastion.name : var.name}"

vpc_zone_identifier = [
"${var.subnet_ids}",
Expand Down
4 changes: 2 additions & 2 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ output "ssh_user" {
}

output "security_group_id" {
value = "${aws_security_group.bastion.id}"
value = "${element(concat(aws_security_group.bastion.*.id, list("")), 0)}"
}

output "asg_id" {
value = "${aws_autoscaling_group.bastion.id}"
value = "${element(concat(aws_autoscaling_group.bastion.*.id, list("")), 0)}"
}
5 changes: 5 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,8 @@ variable "apply_changes_immediately" {
description = "Whether to apply the changes at once and recreate auto-scaling group"
default = false
}

variable "enabled" {
default = true
description = "Whether to create bastion or not."
}