Skip to content

Commit e1e5c5c

Browse files
committed
Almost there but not quite - change of direction coming.
1 parent a855a66 commit e1e5c5c

File tree

4 files changed

+35
-20
lines changed

4 files changed

+35
-20
lines changed

security.group-main.tf

+23-14
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
11

2+
### ####################### ###
3+
### [[data source]] aws_vpc ###
4+
### ####################### ###
5+
6+
data aws_vpc default
7+
{
8+
default = true
9+
}
10+
11+
212
### ####################################### ###
313
### [[resource]] aws_default_security_group ###
414
### ####################################### ###
515

616
resource aws_security_group new
717
{
8-
count = "${ var.in_use_default ? 1 : 0 }"
9-
18+
################################# count = "${ var.in_use_default ? 0 : 1 }"
19+
vpc_id = "${ length(var.in_vpc_id) == 0 ? data.aws_vpc.default.id : var.in_vpc_id }"
1020
name = "security-group-${ var.in_ecosystem }-${ module.ecosys.out_stamp }-n"
1121
description = "This new security group ${ module.ecosys.out_history_note }"
12-
vpc_id = "${var.in_vpc_id}"
1322

1423
tags
1524
{
16-
Name = "security-group-${ var.in_ecosystem }-${ module.ecosys.out_stamp }-n"
17-
Class = "${ var.in_ecosystem }"
25+
Name = "security-group-${ var.in_ecosystem }-${ module.ecosys.out_stamp }-n"
26+
Class = "${ var.in_ecosystem }"
1827
Instance = "${ var.in_ecosystem }-${ module.ecosys.out_stamp }"
19-
Desc = "Newly created security group for ${ var.in_ecosystem } ${ module.ecosys.out_history_note }"
28+
Desc = "Newly created security group for ${ var.in_ecosystem } ${ module.ecosys.out_history_note }"
2029
}
2130

2231
}
@@ -28,14 +37,15 @@ resource aws_security_group new
2837

2938
resource aws_default_security_group default
3039
{
31-
vpc_id = "${var.in_vpc_id}"
40+
########################### count = "${ var.in_use_default ? 1 : 0 }"
41+
vpc_id = "${ length(var.in_vpc_id) == 0 ? data.aws_vpc.default.id : var.in_vpc_id }"
3242

3343
tags
3444
{
35-
Name = "security-group-${ var.in_ecosystem }-${ module.ecosys.out_stamp }-d"
36-
Class = "${ var.in_ecosystem }"
45+
Name = "security-group-${ var.in_ecosystem }-${ module.ecosys.out_stamp }-d"
46+
Class = "${ var.in_ecosystem }"
3747
Instance = "${ var.in_ecosystem }-${ module.ecosys.out_stamp }"
38-
Desc = "The default security group in the VPC for ${ var.in_ecosystem } ${ module.ecosys.out_history_note }"
48+
Desc = "The default security group in vpc for ${ var.in_ecosystem } ${ module.ecosys.out_history_note }"
3949
}
4050

4151
}
@@ -49,8 +59,7 @@ resource aws_security_group_rule ingress
4959
{
5060
count = "${length(var.in_ingress)}"
5161

52-
# ---@----@--> security_group_id = "${var.in_use_default == true ? aws_default_security_group.default.id : aws_security_group.sgroup-new.id}"
53-
security_group_id = "${aws_default_security_group.default.id}"
62+
security_group_id = "${ var.in_use_default ? aws_default_security_group.default.id : aws_security_group.new.id }"
5463

5564
type = "ingress"
5665
cidr_blocks = ["${var.in_ingress_cidr_blocks}"]
@@ -61,6 +70,7 @@ resource aws_security_group_rule ingress
6170
protocol = "${element(var.rules[var.in_ingress[count.index]], 2)}"
6271
}
6372

73+
6474
### #################################### ###
6575
### [[resource]] aws_security_group_rule ###
6676
### #################################### ###
@@ -69,8 +79,7 @@ resource aws_security_group_rule egress
6979
{
7080
count = "${length(var.in_egress)}"
7181

72-
# ---@----@--> security_group_id = "${var.in_use_default == true ? aws_default_security_group.default.id : aws_security_group.sgroup-new.id}"
73-
security_group_id = "${aws_default_security_group.default.id}"
82+
security_group_id = "${ var.in_use_default ? aws_default_security_group.default.id : aws_security_group.new.id }"
7483

7584
type = "egress"
7685
cidr_blocks = ["${var.in_egress_cidr_blocks}"]

security.group-outputs.tf

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,22 @@
77
### [[output]] out_security_group_ids ###
88
### ################################# ###
99

10+
/*
1011
output out_security_group_ids
1112
{
1213
description = "One element list with ID of either the default security group or the new one."
1314
value = [ "${ var.in_use_default ? aws_default_security_group.default.*.id : aws_security_group.new.*.id }" ]
1415
}
15-
16+
*/
1617

1718
### ################################ ###
1819
### [[output]] out_security_group_id ###
1920
### ################################ ###
2021

22+
/*
2123
output out_security_group_id
2224
{
2325
description = "The string ID of either the default security group or the just created new one."
2426
value = "${ var.in_use_default ? aws_default_security_group.default.*.id : aws_security_group.new.*.id }"
2527
}
28+
*/

security.group-variables.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ variable in_egress
3333

3434
variable in_vpc_id
3535
{
36-
description = "ID of umbrella VPC the security group falls under - if not set the default VPC is used."
36+
description = "umbrella vpc the security group falls under which reverts to the default VPC if not set."
3737
default = ""
3838
}
3939

test-security.group/security.group-test.tf

+7-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module vpc-subnets
1717

1818
module zero-param-test
1919
{
20-
source = "github.com/devops-ip/terraform-aws-security-group"
20+
source = ".."
2121
}
2222

2323
/*
@@ -31,17 +31,18 @@ module last-stable-release-test-0
3131

3232
module security-group-test-1
3333
{
34-
source = "github.com/devops-ip/terraform-aws-security-group"
34+
source = ".."
3535
in_vpc_id = "${ module.vpc-subnets.out_vpc_id }"
3636
in_use_default = "true"
3737
in_ecosystem = "${ local.ecosystem_id }-01"
3838
}
3939

4040
module security-group-test-2
4141
{
42-
source = "github.com/devops-ip/terraform-aws-security-group"
42+
source = ".."
4343
in_vpc_id = "${ module.vpc-subnets.out_vpc_id }"
44-
in_use_default = "false"
44+
in_use_default = "true"
45+
##################### in_use_default = "false"
4546
in_ecosystem = "${ local.ecosystem_id }-02"
4647
}
4748

@@ -119,9 +120,11 @@ module vpc-subnets-test-9
119120
120121
*/
121122

123+
/*
122124
output subnet_ids_1{ value = "${module.vpc-subnets.out_subnet_ids}" }
123125
output private_subnet_ids_1{ value = "${module.vpc-subnets.out_private_subnet_ids}" }
124126
output public_subnet_ids_1{ value = "${module.vpc-subnets.out_public_subnet_ids}" }
125127
126128
output security_group_id_1 { value = "${module.security-group-test-1.out_security_group_id}" }
127129
output security_group_ids_1{ value = "${module.security-group-test-1.out_security_group_ids}" }
130+
*/

0 commit comments

Comments
 (0)