Skip to content

Commit a60fba5

Browse files
s2504sconst-bon
authored andcommitted
Make default security group optional (#9)
1 parent 4f5aaa5 commit a60fba5

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ resource "aws_iam_role" "default" {
3838
}
3939

4040
resource "aws_security_group" "default" {
41+
count = "${var.create_default_security_group}"
4142
name = "${module.label.id}"
4243
vpc_id = "${var.vpc_id}"
4344
description = "Instance default security group (only egress access is allowed)"
@@ -88,7 +89,7 @@ resource "aws_instance" "default" {
8889
user_data = "${data.template_file.user_data.rendered}"
8990

9091
vpc_security_group_ids = [
91-
"${compact(concat(list(aws_security_group.default.id), var.security_groups))}",
92+
"${compact(concat(list(var.create_default_security_group ? join("", aws_security_group.default.*.id) : ""), var.security_groups))}",
9293
]
9394

9495
iam_instance_profile = "${aws_iam_instance_profile.default.name}"

outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ output "ssh_key_pair" {
2222
value = "${var.ssh_key_pair}"
2323
}
2424

25-
output "security_group_id" {
26-
value = "${aws_security_group.default.id}"
25+
output "security_group_ids" {
26+
value = "${compact(concat(list(var.create_default_security_group ? join("", aws_security_group.default.*.id) : ""), var.security_groups))}"
2727
}
2828

2929
output "role" {

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ variable "vpc_id" {}
3636

3737
variable "security_groups" {
3838
type = "list"
39+
default = []
3940
}
4041

4142
variable "subnets" {
@@ -103,3 +104,8 @@ variable "metric_threshold" {
103104
variable "default_alarm_action" {
104105
default = "action/actions/AWS_EC2.InstanceId.Reboot/1.0"
105106
}
107+
108+
variable "create_default_security_group" {
109+
description = "Create default Security Group with Egress traffic allowed only"
110+
default = true
111+
}

0 commit comments

Comments
 (0)