Skip to content

Commit a1400b7

Browse files
committed
security group rule creator taking shape
1 parent e2561e3 commit a1400b7

File tree

4 files changed

+164
-11
lines changed

4 files changed

+164
-11
lines changed

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
# Ignore the .terraform configuration folder which includes
3+
# a large cached binary that is divorced from the changeable
4+
# system binary.
5+
**/.terraform/*
6+
7+
# Ignore all files produced to hold and backup state which
8+
# includes terraform.tfstate and terraform.tfstate.backup
9+
*.tfstate
10+
*.tfstate.*
11+
12+
# When terraform crashes it can leave this file behind.
13+
crash.log

README.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11

22
# Create Security Group Rules | Terraform Module
33

4-
Refactor to use this module and avoid **hundreds of lines of very similar security group** terraform definitions.
4+
**Avoid hundreds of lines of similar security group definitions** by refactoring to use this security group and rule creation terraform module.
55

6-
## Usage
7-
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.
9-
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.
6+
You specify every ingress rule you need in just one line with words like **ssh**, https, **sftp**, rabbitmq, **kube-control-plane** or openvpn. If you omit in_egress the ubiquitous "all-traffic" is assumed.
117

8+
## Usage
129

13-
module security_groups
10+
module security_group
1411
{
15-
source = "github.com/devops-ip/terraform-aws-security-groups"
12+
source = "github.com/devops-ip/terraform-aws-security-group"
1613
in_ingress = [ "ssh", "http", "https" ]
1714
in_vpc_id = "${module.vpc.vpc_id}"
1815
}
@@ -22,14 +19,16 @@ You specify every ingress rule you need in just one line with words like **ssh**
2219
ami = "${var.ubuntu-amis[ "${data.aws_region.with.name}" ]}"
2320
instance_type = "t2.micro"
2421

25-
vpc_security_group_ids = "${module.security_groups.out_security_group_ids}"
22+
vpc_security_group_ids = "${module.security_group.out_security_group_ids}"
2623
}
2724

2825

26+
Output **out_security_group_ids** is a **list** whilst **out_security_group_id** is a **string**.
27+
28+
## [Examples and Tests](test-security.group)
2929

30-
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).
30+
**[This terraform module has runnable example integration tests](test-security.group)**. Read the instructions on how to clone the project and run the integration tests.
3131

32-
vpc_security_group_ids = [ "${module.security_group_module.out_default_security_group_ids}" ]
3332

3433
## Security Group Module Inputs
3534

test-security.group/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
# Test the AWS VPC Subnets Module
3+
4+
You can unit test the [[terraform-aws-vpc-subnets module]](https://github.com/devops-ip/terraform-aws-vpc-subnets) which **creates VPCs subnets in a round robin** manner.
5+
6+
$ git clone https://github.com/devops-ip/test-vpc-subnets.git
7+
$ cd test-vpc-subnets
8+
$ terraform init .
9+
$ terraform apply -auto-approve
10+
$ terraform destroy -auto-approve
11+
12+
## Unit Test Pre-Conditions
13+
14+
Check before you run the test that
15+
16+
- terraform and git are installed
17+
- you have created an AWS IAM user with VPC permissions
18+
- your [[AWS credentials have been installed]](https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/setup-credentials.html)
19+
- headroom exists for 10 more VPCs
20+
21+
## Extend the 5 VPC Limit
22+
23+
The default VPC limit is a pithy 5 and we need at least 10 to test all the functionality in this ubiquitous VPC/Subnet creation module.
24+
25+
On receiving your support ticket AWS automatically ups the VPC limit if you request 25 or less.
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
2+
### ################################################# ###
3+
### [[test-module]] testing terraform-aws-vpc-subnets ###
4+
### ################################################# ###
5+
6+
locals
7+
{
8+
ecosystem_id = "vs-unittest"
9+
}
10+
11+
module zero-param-test
12+
{
13+
source = "github.com/devops-ip/terraform-aws-vpc-subnets"
14+
}
15+
16+
module last-stable-release-test-0
17+
{
18+
source = "github.com/devops-ip/terraform-aws-vpc-subnets?ref=v0.1.0002"
19+
in_vpc_cidr = "10.234.56.0/24"
20+
in_ecosystem = "${local.ecosystem_id}-00"
21+
}
22+
23+
module vpc-subnets-test-1
24+
{
25+
source = "github.com/devops-ip/terraform-aws-vpc-subnets"
26+
version = "v0.1.0002"
27+
in_vpc_cidr = "10.234.0.0/16"
28+
in_ecosystem = "${local.ecosystem_id}-01"
29+
}
30+
31+
module vpc-subnets-test-2
32+
{
33+
source = "github.com/devops-ip/terraform-aws-vpc-subnets"
34+
version = "~> v0.1.0"
35+
in_vpc_cidr = "10.15.0.0/18"
36+
in_subnets_max = "4"
37+
in_ecosystem = "${local.ecosystem_id}-02"
38+
}
39+
40+
module vpc-subnets-test-3
41+
{
42+
source = "github.com/devops-ip/terraform-aws-vpc-subnets"
43+
in_vpc_cidr = "10.63.0.0/20"
44+
in_subnets_max = "6"
45+
in_ecosystem = "${local.ecosystem_id}-03"
46+
}
47+
48+
module vpc-subnets-test-4
49+
{
50+
source = "github.com/devops-ip/terraform-aws-vpc-subnets"
51+
in_vpc_cidr = "10.255.0.0/21"
52+
in_num_private_subnets = 8
53+
in_num_public_subnets = 7
54+
in_subnets_max = "7"
55+
in_ecosystem = "${local.ecosystem_id}-04"
56+
}
57+
58+
module vpc-subnets-test-5
59+
{
60+
source = "github.com/devops-ip/terraform-aws-vpc-subnets"
61+
in_vpc_cidr = "10.242.0.0/16"
62+
in_num_private_subnets = 0
63+
in_num_public_subnets = 0
64+
in_ecosystem = "${local.ecosystem_id}-05"
65+
}
66+
67+
module vpc-subnets-test-6
68+
{
69+
source = "github.com/devops-ip/terraform-aws-vpc-subnets"
70+
in_vpc_cidr = "10.243.0.0/16"
71+
in_num_private_subnets = 0
72+
in_ecosystem = "${local.ecosystem_id}-06"
73+
}
74+
75+
module vpc-subnets-test-7
76+
{
77+
source = ".."
78+
in_vpc_cidr = "10.244.0.0/16"
79+
in_num_public_subnets = 0
80+
in_ecosystem = "${local.ecosystem_id}-07"
81+
}
82+
83+
module vpc-subnets-test-8
84+
{
85+
source = ".."
86+
in_vpc_cidr = "10.245.0.0/16"
87+
in_num_private_subnets = 6
88+
in_num_public_subnets = 6
89+
in_ecosystem = "${local.ecosystem_id}-08"
90+
}
91+
92+
module vpc-subnets-test-9
93+
{
94+
source = ".."
95+
in_vpc_cidr = "10.31.0.0/22"
96+
in_num_private_subnets = 2
97+
in_num_public_subnets = 8
98+
in_subnets_max = "5"
99+
in_ecosystem = "${local.ecosystem_id}-09"
100+
}
101+
102+
output subnet_ids_1{ value = "${module.vpc-subnets-test-1.out_subnet_ids}" }
103+
output private_subnet_ids_1{ value = "${module.vpc-subnets-test-1.out_private_subnet_ids}" }
104+
output public_subnet_ids_1{ value = "${module.vpc-subnets-test-1.out_public_subnet_ids}" }
105+
106+
output subnet_ids_2{ value = "${module.vpc-subnets-test-6.out_subnet_ids}" }
107+
output private_subnet_ids_2{ value = "${module.vpc-subnets-test-6.out_private_subnet_ids}" }
108+
output public_subnet_ids_2{ value = "${module.vpc-subnets-test-6.out_public_subnet_ids}" }
109+
110+
output subnet_ids_3{ value = "${module.vpc-subnets-test-7.out_subnet_ids}" }
111+
output private_subnet_ids_3{ value = "${module.vpc-subnets-test-7.out_private_subnet_ids}" }
112+
output public_subnet_ids_3{ value = "${module.vpc-subnets-test-7.out_public_subnet_ids}" }
113+
114+
output subnet_ids_4{ value = "${module.vpc-subnets-test-9.out_subnet_ids}" }
115+
output private_subnet_ids_4{ value = "${module.vpc-subnets-test-9.out_private_subnet_ids}" }
116+
output public_subnet_ids_4{ value = "${module.vpc-subnets-test-9.out_public_subnet_ids}" }

0 commit comments

Comments
 (0)