Skip to content

Commit 3641196

Browse files
committed
Beginning tidy up of documentation and vars/output
1 parent 8f912a1 commit 3641196

File tree

2 files changed

+41
-36
lines changed

2 files changed

+41
-36
lines changed

README.md

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
11

2-
# Rules Terraform Modules | Creates Security Group | Adds Rules
2+
# Create Security Group Rules | Terraform Module
33

4-
This security-group module **adds ingress and egress rules** to **either the default or a new** security group within a given VPC.
4+
Refactor to use this module and avoid **hundreds of lines of very similar security group** terraform definitions.
55

6-
## Simple Module Usage Example
6+
## Usage
77

8-
To use this module simply declare it like below supplying it with a mandatory VPC id. If you omit **in_ingress** a default ssh rule is created. A default **all traffic egress rule** is also created but you can override this behaviour if you so wish.
8+
You specify every ingress rule you need in just one line with words like **ssh**, https, **sftp**, rabbitmq, kube-controller and **openvpn**. If you omit in_egress then the ubiquitous "all-traffic" is assumed.
99

10-
module security_group_module
10+
The most common usage is to specify the VPC ID and the ingress (inbound) rules To use this module simply declare it like below supplying it with a mandatory VPC id. If you omit **in_ingress** a default ssh rule is created. A default **all traffic egress rule** is also created but you can override this behaviour if you so wish.
11+
12+
13+
module security_groups
1114
{
12-
source = "rules"
13-
in_vpc_id = "${module.vpc.vpc_id}"
14-
in_ingress = [ "ssh", "http", "https" ]
15+
source = "github.com/devops-ip/terraform-aws-security-groups"
16+
in_ingress = [ "ssh", "http", "https" ]
17+
in_vpc_id = "${module.vpc.vpc_id}"
1518
}
1619

20+
resource aws_instance ec2-instance
21+
{
22+
ami = "${var.ubuntu-amis[ "${data.aws_region.with.name}" ]}"
23+
instance_type = "t2.micro"
24+
25+
vpc_security_group_ids = "${module.security_groups.out_security_group_ids}"
26+
}
27+
28+
29+
1730
This module defines two **list outputs** called **out_default_security_group_ids** and **out_new_security_group_ids**. Use the first after creating rules against the VPC's default security group and the second after a new security group is created (see variable in_use_default).
1831

1932
vpc_security_group_ids = [ "${module.security_group_module.out_default_security_group_ids}" ]
@@ -37,6 +50,8 @@ The security group's input variables are vital to achieving the desired behaviou
3750
This security group module is simple but flexible as it needs to cater to many different tastes. Now follows a number of **overloading** facilities to craft your security group's behaviour.
3851

3952
### Specify the Creation of a Security Group
53+
This security-group module **adds ingress and egress rules** to **either the default or a new** security group within a given VPC.
54+
4055

4156
Passing **false** to the **in_use_default** flag causes the **creation of a security group**.
4257

security.groups-vars.tf

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -71,44 +71,34 @@ variable in_use_default
7171
}
7272

7373

74-
### ############################ ###
75-
### [[variable]] in_ecosystem_id ###
76-
### ############################ ###
74+
### ################################# ###
75+
### [[output]] out_security_group_ids ###
76+
### ################################# ###
7777

78-
variable in_ecosystem_id
78+
output out_security_group_ids
7979
{
80-
description = "Identifier binding all infrastructure components created for this ecosystem instance."
80+
description = "One element list with ID of either the default security group or the new one."
81+
value = [ "${ var.in_use_default ? aws_default_security_group.default.id : aws_security_group.new.id }" ]
8182
}
8283

8384

84-
### ############################ ###
85-
### [[variable]] in_history_note ###
86-
### ############################ ###
85+
### ################################ ###
86+
### [[output]] out_security_group_id ###
87+
### ################################ ###
8788

88-
variable in_history_note
89+
output out_security_group_id
8990
{
90-
description = "Note describing the whys and wherefores of this creation."
91+
description = "The string ID of either the default security group or the just created new one."
92+
value = "${ var.in_use_default ? aws_default_security_group.default.id : aws_security_group.new.id }"
9193
}
9294

9395

94-
### ######################################### ###
95-
### [[output]] out_default_security_group_ids ###
96-
### ######################################### ###
96+
### ######################### ###
97+
### [[variable]] in_ecosystem ###
98+
### ######################### ###
9799

98-
output out_default_security_group_ids
100+
variable in_ecosystem
99101
{
100-
description = "If in_use_default is true this output variable will be set."
101-
# ---@----@--> value = "${aws_default_security_group.default.*.id}"
102-
value = "${aws_default_security_group.default.id}"
102+
description = "The name of the class of ecosystem being built like kubernetes-cluster or elasticsearch-db."
103+
default = "eco-system"
103104
}
104-
105-
106-
# ---@----@-->### ############################# ###
107-
# ---@----@-->### [[output]] out_new_security_group_ids ###
108-
# ---@----@-->### ############################# ###
109-
# ---@----@-->output "out_new_security_group_ids"
110-
# ---@----@-->{
111-
# ---@----@--> description = "If in_use_default is false this output variable will be set."
112-
# ---@----@--> value = "${aws_security_group.sgroup-new.*.id}"
113-
# ---@----@-->}
114-

0 commit comments

Comments
 (0)