Skip to content

Commit caaf9e3

Browse files
committed
upgrading the security group module to handle tags in a simple and succinct manner
1 parent 7952959 commit caaf9e3

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

security.group-main.tf

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11

22
locals {
33

4-
ResourceTags = {
5-
Weekday = "Thursday"
6-
Millenia = "21st"
7-
Season = "Summer"
4+
security_group_tags = {
5+
Name = "security-group-${ var.in_ecosystem_name }-${ var.in_tag_timestamp }"
6+
Desc = "New security group for ${ var.in_ecosystem_name } ${ var.in_tag_description }"
87
}
98

109
}
@@ -18,22 +17,10 @@ locals {
1817
*/
1918
resource aws_security_group new {
2019

21-
vpc_id = "${ var.in_vpc_id }"
20+
vpc_id = var.in_vpc_id
2221
name = "security-group-${ var.in_ecosystem_name }-${ var.in_tag_timestamp }-n"
2322
description = "This new security group ${ var.in_tag_description }"
24-
25-
26-
tags = local.ResourceTags
27-
28-
/*
29-
tags = {
30-
31-
Name = "security-group-${ var.in_ecosystem_name }-${ var.in_tag_timestamp }"
32-
Class = "${ var.in_ecosystem_name }"
33-
Instance = "${ var.in_ecosystem_name }-${ var.in_tag_timestamp }"
34-
Desc = "New security group for ${ var.in_ecosystem_name } ${ var.in_tag_description }"
35-
}
36-
*/
23+
tags = merge( local.security_group_tags, var.in_mandatory_tags )
3724

3825
}
3926

@@ -69,12 +56,11 @@ resource aws_security_group_rule ingress {
6956
*/
7057
resource aws_security_group_rule egress {
7158

72-
count = "${length(var.in_egress)}"
73-
74-
security_group_id = "${ aws_security_group.new.id }"
59+
count = length( var.in_egress )
60+
security_group_id = aws_security_group.new.id
7561

7662
type = "egress"
77-
cidr_blocks = "${var.in_egress_cidr_blocks}"
63+
cidr_blocks = var.in_egress_cidr_blocks
7864
description = element( var.rules[ var.in_egress[ count.index ] ], 3 )
7965

8066
from_port = element( var.rules[ var.in_egress[ count.index ] ], 0 )

security.group-variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ variable in_egress_cidr_blocks {
6161
}
6262

6363

64+
### ############################## ###
65+
### [[variable]] in_mandatory_tags ###
66+
### ############################## ###
67+
68+
variable in_mandatory_tags {
69+
70+
description = "Optional tags unless your organization mandates a tag set to be placed on this resource."
71+
type = "map"
72+
default = { }
73+
}
74+
75+
6476
### ################# ###
6577
### in_ecosystem_name ###
6678
### ################# ###

0 commit comments

Comments
 (0)