Skip to content

Commit ed5446c

Browse files
committed
Address reviewer comments
1 parent 43f8150 commit ed5446c

File tree

5 files changed

+35
-33
lines changed

5 files changed

+35
-33
lines changed

examples/complete/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module "new_security_group" {
1717
source = "../.."
1818

1919
vpc_id = module.vpc.vpc_id
20-
open_egress_enabled = true
20+
allow_all_egress = true
2121
rule_matrix = {
2222
# Allow ingress on ports 22 and 80 from created security grup, existing security group, and CIDR "10.0.0.0/8"
2323
source_security_group_ids = [aws_security_group.existing.id]

examples/complete/outputs.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
output "new_sg_id" {
1+
output "created_sg_id" {
22
description = "The new one Security Group ID"
33
value = module.new_security_group.id
44
}
55

6-
output "new_sg_arn" {
6+
output "created_sg_arn" {
77
description = "The new one Security Group ARN"
88
value = module.new_security_group.arn
99
}
1010

11-
output "new_sg_name" {
11+
output "created_sg_name" {
1212
description = "The new one Security Group Name"
1313
value = module.new_security_group.name
1414
}
1515

16-
output "new_sg_details" {
16+
output "created_sg_details" {
1717
description = "Details about the security group created"
1818
value = module.new_security_group.security_group_details
1919
}
2020

21-
output "new_sg_rules" {
22-
description = "Details about all the security group rules created for the existing security group"
21+
output "created_sg_rules" {
22+
description = "Details about all the security group rules created for the created security group"
2323
value = module.new_security_group.rules
2424
}
2525

main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ locals {
99
security_group_id = local.enabled ? (
1010
# Use coalesce() here to hack an error message into the output
1111
var.create_security_group ? local.created_security_group.id : coalesce(var.existing_security_group_id,
12-
"use_existing_security_group is true, but no ID supplied ")
12+
"`create_security_group` is false, but no ID was supplied ")
1313
) : null
1414

1515
rules = local.enabled && var.rules != null ? {
@@ -118,7 +118,7 @@ resource "aws_security_group_rule" "cidr" {
118118

119119

120120
resource "aws_security_group_rule" "egress" {
121-
count = local.enabled && var.open_egress_enabled ? 1 : 0
121+
count = local.enabled && var.allow_all_egress ? 1 : 0
122122

123123
security_group_id = local.security_group_id
124124
type = "egress"

test/src/examples_complete_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ func TestExamplesComplete(t *testing.T) {
4040
// Run `terraform output` to get the value of an output variable
4141

4242
// Verify that outputs are valid when `security_group_enabled=true`
43-
newSgID := terraform.Output(t, terraformOptions, "new_sg_id")
44-
newSgARN := terraform.Output(t, terraformOptions, "new_sg_arn")
45-
newSgName := terraform.Output(t, terraformOptions, "new_sg_name")
43+
newSgID := terraform.Output(t, terraformOptions, "created_sg_id")
44+
newSgARN := terraform.Output(t, terraformOptions, "created_sg_arn")
45+
newSgName := terraform.Output(t, terraformOptions, "created_sg_name")
4646

4747
assert.Contains(t, newSgID, "sg-", "SG ID should contains substring 'sg-'")
4848
assert.Contains(t, newSgARN, "arn:aws:ec2", "SG ID should contains substring 'arn:aws:ec2'")

variables.tf

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -55,38 +55,40 @@ variable "rules" {
5555
EOT
5656
}
5757

58-
variable "open_egress_enabled" {
58+
variable "allow_all_egress" {
5959
type = bool
6060
default = false
6161
description = <<-EOT
62-
A convenience. Add to the rules in `var.rules` a rule that allows all egress.
62+
A convenience that adds to the rules in `var.rules` a rule that allows all egress.
6363
If this is false and `var.rules` does not specify any egress rules, then
6464
no egress will be allowed.
6565
EOT
6666
}
6767

6868
variable "rule_matrix" {
69+
# rule_matrix is independent of the `rules` input.
70+
# Only the rules specified in the `rule_matrix` object are applied to the subjects.
71+
# Schema:
72+
# {
73+
# # these top level lists define all the subjects to which rule_matrix rules will be applied
74+
# source_security_group_ids = list of source security group IDs to apply all rules to
75+
# cidr_blocks = list of ipv4 CIDR blocks to apply all rules to
76+
# ipv6_cidr_blocks= list of ipv6 CIDR blocks to apply all rules to
77+
# prefix_list_ids = list of prefix list IDs to apply all rules to
78+
# self = # set "true" to apply the rules to the created or existing security group
79+
#
80+
# # each rule in the rules list will be applied to every subject defined above
81+
# rules = [{
82+
# type = "egress"
83+
# from_port = 0
84+
# to_port = 65535
85+
# protocol = "all"
86+
# description = "Allow full egress"
87+
# }]
88+
6989
type = any
7090
default = { rules = [] }
7191
description = <<-EOT
72-
A convenience. Apply the same list of rules to all the provided security groups and CIDRs and self.
73-
Type is object as specified in the default, but keys are optional except for `rules`.
74-
The `rules` list is a list of maps that are fully compatible with the `aws_security_group_rule` resource,
75-
but any keys already at the top level will be ignored. Rules keys listed in the default are required, except for `description`.
76-
All elements of the list must have the same set of keys and each key must have a consistent value type.
77-
Example:
78-
{
79-
source_security_group_ids = []
80-
cidr_blocks= []
81-
ipv6_cidr_blocks= []
82-
prefix_list_ids = []
83-
self = true
84-
rules = [{
85-
type = "egress"
86-
from_port = 0
87-
to_port = 65535
88-
protocol = "all"
89-
description = "Allow full egress"
90-
}]
92+
A convenient way to apply the same set of rules to a set of subjects. See README for details.
9193
EOT
9294
}

0 commit comments

Comments
 (0)