Skip to content

Commit

Permalink
Merge pull request #32 from aidanmelen/v2.1.0
Browse files Browse the repository at this point in the history
V2.1.0
  • Loading branch information
aidanmelen authored Nov 30, 2022
2 parents 05382cf + f335d98 commit f520c1a
Show file tree
Hide file tree
Showing 62 changed files with 10,303 additions and 9,398 deletions.
37 changes: 19 additions & 18 deletions .makefile.docs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
help This help.
build Build docker dev image
run Run docker dev container
setup Setup project
lint Lint with pre-commit and render docs
lint-all Lint all files with pre-commit and render docs
tests Tests with Terratest
test-basic Test the basic example
test-complete Test the complete example
test-customer Test the customer example
test-managed Test the managed example
test-common Test the common example
test-matrix Test the matrix example
test-computed Test the computed example
test-rules-only Test the rules_only example
test-name-prefix Test the name_prefix example
test-unpack Test the unpack example
clean Clean project
help This help.
build Build docker dev image
run Run docker dev container
setup Setup project
lint Lint with pre-commit and render docs
lint-all Lint all files with pre-commit and render docs
tests Tests with Terratest
test-basic Test the basic example
test-complete Test the complete example
test-customer Test the customer example
test-managed Test the managed example
test-common Test the common example
test-matrix Test the matrix example
test-computed Test the computed example
test-rules-only Test the rules_only example
test-name-prefix Test the name_prefix example
test-unpack Test the unpack example
test-source-security-group-ids Test the source_security_group_ids example
clean Clean project
2 changes: 2 additions & 0 deletions .terraform-docs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ content: |-

- [Unpack Example](https://github.com/aidanmelen/terraform-aws-security-group-v2/tree/main/examples/unpack)

- [Source Security Group IDs Example](https://github.com/aidanmelen/terraform-aws-security-group-v2/tree/main/examples/source_security_group_ids)

## Key Concepts

| Terminology | Description |
Expand Down
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
NAME := security-group-v2
HOSTNAME := aidanmelen
PROVIDER := aws
VERSION := 2.0.2
VERSION := 2.1.0
SHELL := /bin/bash

.PHONY: help all

help: ## This help.
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

.DEFAULT_GOAL := help

Expand All @@ -34,6 +34,7 @@ setup: ## Setup project
cd examples/rules_only && terraform init
cd examples/name_prefix && terraform init
cd examples/unpack && terraform init
cd examples/source_security_group_ids && terraform init

# pre-commit
git init
Expand Down Expand Up @@ -62,7 +63,7 @@ lint-all: docs ## Lint all files with pre-commit and render docs
pre-commit run --all-files
git add -A

tests: test-basic test-complete test-customer test-managed test-common test-computed test-matrix test-rules-only test-name-prefix test-unpack ## Tests with Terratest
tests: test-basic test-complete test-customer test-managed test-common test-computed test-matrix test-rules-only test-name-prefix test-unpack test-source-security-group-ids ## Tests with Terratest

test-basic: ## Test the basic example
go test test/terraform_basic_test.go -timeout 5m -v |& tee test/terraform_basic_test.log
Expand Down Expand Up @@ -94,6 +95,9 @@ test-name-prefix: ## Test the name_prefix example
test-unpack: ## Test the unpack example
go test test/terraform_unpack_test.go -timeout 5m -v |& tee test/terraform_unpack_test.log

test-source-security-group-ids: ## Test the source_security_group_ids example
go test test/terraform_source_security_group_ids_test.go -timeout 5m -v |& tee test/terraform_source_security_group_ids_test.log

release:
git tag v${VERSION}
git push --tag
Expand Down
64 changes: 34 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ Create a Security Group with the following rules:
#tfsec:ignore:aws-ec2-no-public-egress-sgr
module "security_group" {
source = "aidanmelen/security-group-v2/aws"
version = ">= 2.0.2"
version = ">= 2.1.0"
name = local.name
description = "Allow TLS inbound traffic"
Expand Down Expand Up @@ -351,6 +351,8 @@ Please see the full examples for more information:

- [Unpack Example](https://github.com/aidanmelen/terraform-aws-security-group-v2/tree/main/examples/unpack)

- [Source Security Group IDs Example](https://github.com/aidanmelen/terraform-aws-security-group-v2/tree/main/examples/source_security_group_ids)

## Key Concepts

| Terminology | Description |
Expand Down Expand Up @@ -390,40 +392,42 @@ Run Terratest using the [Makefile](https://github.com/aidanmelen/terraform-aws-s
### Results

```
Terratest Suite (Module v2.0.2) (Terraform v1.3.1)
--- PASS: TestTerraformBasicExample (20.44s)
--- PASS: TestTerraformCompleteExample (43.24s)
--- PASS: TestTerraformCustomerRulesExample (30.02s)
--- PASS: TestTerraformManagedRulesExample (30.08s)
--- PASS: TestTerraformCommonRulesExample (23.85s)
--- PASS: TestTerraformMatrixRulesExample (30.98s)
--- PASS: TestTerraformComputedRulesExample (37.34s)
--- PASS: TestTerraformNamePrefixExample (21.79s)
--- PASS: TestTerraformRulesOnlyExample (20.94s)
--- PASS: TestTerraformUnpackRulesExample (43.72s)
Terratest Suite (Module v2.1.0) (Terraform v1.3.1)
--- PASS: TestTerraformBasicExample (24.80s)
--- PASS: TestTerraformCompleteExample (42.97s)
--- PASS: TestTerraformCustomerRulesExample (31.73s)
--- PASS: TestTerraformManagedRulesExample (32.37s)
--- PASS: TestTerraformCommonRulesExample (26.52s)
--- PASS: TestTerraformMatrixRulesExample (33.59s)
--- PASS: TestTerraformComputedRulesExample (38.88s)
--- PASS: TestTerraformNamePrefixExample (23.24s)
--- PASS: TestTerraformRulesOnlyExample (23.26s)
--- PASS: TestTerraformUnpackRulesExample (44.25s)
--- PASS: TestTerraformSourceSecurityGroupIdsExample (21.83s)
```

## Makefile Targets

```
help This help.
build Build docker dev image
run Run docker dev container
setup Setup project
lint Lint with pre-commit and render docs
lint-all Lint all files with pre-commit and render docs
tests Tests with Terratest
test-basic Test the basic example
test-complete Test the complete example
test-customer Test the customer example
test-managed Test the managed example
test-common Test the common example
test-matrix Test the matrix example
test-computed Test the computed example
test-rules-only Test the rules_only example
test-name-prefix Test the name_prefix example
test-unpack Test the unpack example
clean Clean project
help This help.
build Build docker dev image
run Run docker dev container
setup Setup project
lint Lint with pre-commit and render docs
lint-all Lint all files with pre-commit and render docs
tests Tests with Terratest
test-basic Test the basic example
test-complete Test the complete example
test-customer Test the customer example
test-managed Test the managed example
test-common Test the common example
test-matrix Test the matrix example
test-computed Test the computed example
test-rules-only Test the rules_only example
test-name-prefix Test the name_prefix example
test-unpack Test the unpack example
test-source-security-group-ids Test the source_security_group_ids example
clean Clean project
```

## Requirements
Expand Down
1 change: 1 addition & 0 deletions bin/render-terraform-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ sed -z "${PATTERN}" examples/computed/main.tf > examples/computed/.main.tf.docs
sed -z "${PATTERN}" examples/rules_only/main.tf > examples/rules_only/.main.tf.docs
sed -z "${PATTERN}" examples/name_prefix/main.tf > examples/name_prefix/.main.tf.docs
sed -z "${PATTERN}" examples/unpack/main.tf > examples/unpack/.main.tf.docs
sed -z "${PATTERN}" examples/source_security_group_ids/main.tf > examples/source_security_group_ids/.main.tf.docs
1 change: 1 addition & 0 deletions bin/render-terratest-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ tail -3 test/terraform_computed_test.log | head -1 >> test/.terratest.docs
tail -3 test/terraform_name_prefix_test.log | head -1 >> test/.terratest.docs
tail -3 test/terraform_rules_only_test.log | head -1 >> test/.terratest.docs
tail -3 test/terraform_unpack_test.log | head -1 >> test/.terratest.docs
tail -3 test/terraform_source_security_group_ids_test.log | head -1 >> test/.terratest.docs
2 changes: 1 addition & 1 deletion examples/basic/.main.tf.docs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#tfsec:ignore:aws-ec2-no-public-egress-sgr
module "security_group" {
source = "aidanmelen/security-group-v2/aws"
version = ">= 2.0.2"
version = ">= 2.1.0"

name = local.name
description = "Allow TLS inbound traffic"
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Note that this example may create resources which cost money. Run `terraform des
#tfsec:ignore:aws-ec2-no-public-egress-sgr
module "security_group" {
source = "aidanmelen/security-group-v2/aws"
version = ">= 2.0.2"
version = ">= 2.1.0"
name = local.name
description = "Allow TLS inbound traffic"
Expand Down
4 changes: 2 additions & 2 deletions examples/common/.main.tf.docs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#tfsec:ignore:aws-ec2-no-public-egress-sgr
module "public_https_sg" {
source = "aidanmelen/security-group-v2/aws"
version = ">= 2.0.2"
version = ">= 2.1.0"

name = "${local.name}-https"
description = "${local.name}-https"
Expand All @@ -16,7 +16,7 @@ module "public_https_sg" {
#tfsec:ignore:aws-ec2-no-public-egress-sgr
module "public_http_sg" {
source = "aidanmelen/security-group-v2/aws"
version = ">= 2.0.2"
version = ">= 2.1.0"

name = "${local.name}-http"
description = "${local.name}-http"
Expand Down
4 changes: 2 additions & 2 deletions examples/common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Note that this example may create resources which cost money. Run `terraform des
#tfsec:ignore:aws-ec2-no-public-egress-sgr
module "public_https_sg" {
source = "aidanmelen/security-group-v2/aws"
version = ">= 2.0.2"
version = ">= 2.1.0"
name = "${local.name}-https"
description = "${local.name}-https"
Expand All @@ -41,7 +41,7 @@ module "public_https_sg" {
#tfsec:ignore:aws-ec2-no-public-egress-sgr
module "public_http_sg" {
source = "aidanmelen/security-group-v2/aws"
version = ">= 2.0.2"
version = ">= 2.1.0"
name = "${local.name}-http"
description = "${local.name}-http"
Expand Down
24 changes: 22 additions & 2 deletions examples/complete/.main.tf.docs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#tfsec:ignore:aws-ec2-no-public-egress-sgr
module "security_group" {
source = "aidanmelen/security-group-v2/aws"
version = ">= 2.0.2"
version = ">= 2.1.0"

name = local.name
description = local.name
Expand Down Expand Up @@ -100,12 +100,32 @@ module "security_group" {
}
}

################################################################################
# Export Rule Aliases
################################################################################

resource "aws_security_group" "example" {
name = "${local.name}-export-rule-alises"
description = "Security group rule with exported module rule aliases."
vpc_id = data.aws_vpc.default.id
}

resource "aws_security_group_rule" "example" {
type = "ingress"
description = module.security_group.rule_aliases.https-443-tcp.description
from_port = module.security_group.rule_aliases.https-443-tcp.from_port
to_port = module.security_group.rule_aliases.https-443-tcp.to_port
protocol = module.security_group.rule_aliases.https-443-tcp.protocol
cidr_blocks = ["10.0.0.0/16"]
security_group_id = aws_security_group.example.id
}

################################################################################
# Disabled creation
################################################################################

module "disabled_sg" {
source = "aidanmelen/security-group-v2/aws"
version = ">= 2.0.2"
version = ">= 2.1.0"
create = false
}
26 changes: 23 additions & 3 deletions examples/complete/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Note that this example may create resources which cost money. Run `terraform des
#tfsec:ignore:aws-ec2-no-public-egress-sgr
module "security_group" {
source = "aidanmelen/security-group-v2/aws"
version = ">= 2.0.2"
version = ">= 2.1.0"
name = local.name
description = local.name
Expand Down Expand Up @@ -130,13 +130,33 @@ module "security_group" {
}
}
################################################################################
# Export Rule Aliases
################################################################################
resource "aws_security_group" "example" {
name = "${local.name}-export-rule-alises"
description = "Security group rule with exported module rule aliases."
vpc_id = data.aws_vpc.default.id
}
resource "aws_security_group_rule" "example" {
type = "ingress"
description = module.security_group.rule_aliases.https-443-tcp.description
from_port = module.security_group.rule_aliases.https-443-tcp.from_port
to_port = module.security_group.rule_aliases.https-443-tcp.to_port
protocol = module.security_group.rule_aliases.https-443-tcp.protocol
cidr_blocks = ["10.0.0.0/16"]
security_group_id = aws_security_group.example.id
}
################################################################################
# Disabled creation
################################################################################
module "disabled_sg" {
source = "aidanmelen/security-group-v2/aws"
version = ">= 2.0.2"
version = ">= 2.1.0"
create = false
}
```
Expand Down Expand Up @@ -167,6 +187,6 @@ module "disabled_sg" {
| <a name="output_egress"></a> [egress](#output\_egress) | The security group egress rules. |
| <a name="output_id"></a> [id](#output\_id) | The ID of the security group. |
| <a name="output_ingress"></a> [ingress](#output\_ingress) | The security group ingress rules. |
| <a name="output_postgresql_port"></a> [postgresql\_port](#output\_postgresql\_port) | Gather the PostgreSQL port from the module rule aliases. |
| <a name="output_sg_rule_with_exported_module_rule_alias"></a> [sg\_rule\_with\_exported\_module\_rule\_alias](#output\_sg\_rule\_with\_exported\_module\_rule\_alias) | Security group rule with exported module rule aliases. |
| <a name="output_terratest"></a> [terratest](#output\_terratest) | Outputs used by Terratest. |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
20 changes: 20 additions & 0 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,26 @@ module "security_group" {
}
}

################################################################################
# Export Rule Aliases
################################################################################

resource "aws_security_group" "example" {
name = "${local.name}-export-rule-alises"
description = "Security group rule with exported module rule aliases."
vpc_id = data.aws_vpc.default.id
}

resource "aws_security_group_rule" "example" {
type = "ingress"
description = module.security_group.rule_aliases.https-443-tcp.description
from_port = module.security_group.rule_aliases.https-443-tcp.from_port
to_port = module.security_group.rule_aliases.https-443-tcp.to_port
protocol = module.security_group.rule_aliases.https-443-tcp.protocol
cidr_blocks = ["10.0.0.0/16"]
security_group_id = aws_security_group.example.id
}

################################################################################
# Disabled creation
################################################################################
Expand Down
19 changes: 10 additions & 9 deletions examples/complete/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ output "egress" {
# Rule Aliases Lookup
###############################################################################

output "postgresql_port" {
description = "Gather the PostgreSQL port from the module rule aliases."
value = try(module.security_group.rule_aliases.postgresql-tcp.from_port, null)
output "sg_rule_with_exported_module_rule_alias" {
description = "Security group rule with exported module rule aliases."
value = aws_security_group_rule.example
}

################################################################################
Expand All @@ -51,11 +51,12 @@ output "disabled_sg_id" {
output "terratest" {
description = "Outputs used by Terratest."
value = {
"ingress_count" = try(length(module.security_group.security_group_ingress_rules), null)
"egress_count" = try(length(module.security_group.security_group_egress_rules), null)
"data_aws_security_group_default_id" = data.aws_security_group.default.id,
"data_aws_prefix_list_private_s3_id" = data.aws_prefix_list.private_s3.id,
"aws_security_group_other_id" = aws_security_group.other.id,
"aws_ec2_managed_prefix_list_other_id" = aws_ec2_managed_prefix_list.other.id,
"ingress_count" = try(length(module.security_group.security_group_ingress_rules), null)
"egress_count" = try(length(module.security_group.security_group_egress_rules), null)
"data_aws_security_group_default_id" = data.aws_security_group.default.id,
"data_aws_prefix_list_private_s3_id" = data.aws_prefix_list.private_s3.id,
"aws_security_group_other_id" = aws_security_group.other.id,
"aws_ec2_managed_prefix_list_other_id" = aws_ec2_managed_prefix_list.other.id,
"sg_id_with_exported_module_rule_alias" = aws_security_group.example.id
}
}
Loading

0 comments on commit f520c1a

Please sign in to comment.