Skip to content

Commit

Permalink
updated example aws provider version to keep terratest working. pleas…
Browse files Browse the repository at this point in the history
…e see hashicorp/terraform-provider-aws#28110 for more information.
  • Loading branch information
aidanmelen committed Dec 1, 2022
1 parent d7f1c82 commit 43a8d19
Show file tree
Hide file tree
Showing 40 changed files with 9,942 additions and 10,025 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,17 +393,17 @@ Run Terratest using the [Makefile](https://github.com/aidanmelen/terraform-aws-s

```
Terratest Suite (Module v2.1.1) (Terraform v1.3.1)
FAIL
--- 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)
--- PASS: TestTerraformBasicExample (24.84s)
--- PASS: TestTerraformCompleteExample (41.62s)
--- PASS: TestTerraformCustomerRulesExample (30.86s)
--- PASS: TestTerraformManagedRulesExample (30.15s)
--- PASS: TestTerraformCommonRulesExample (24.98s)
--- PASS: TestTerraformMatrixRulesExample (30.56s)
--- PASS: TestTerraformComputedRulesExample (37.52s)
--- PASS: TestTerraformNamePrefixExample (21.21s)
--- PASS: TestTerraformRulesOnlyExample (20.41s)
--- PASS: TestTerraformUnpackRulesExample (42.44s)
--- PASS: TestTerraformSourceSecurityGroupIdsExample (19.75s)
```

## Makefile Targets
Expand Down
114 changes: 114 additions & 0 deletions dynamic.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
###############################################################################
# Security Group Rules
###############################################################################

# normalize customer, managed and common rules
locals {
ingress_normalize = [
for rule in var.ingress : {
description = try(rule.description, local.rule_aliases[rule.rule].description, var.default_rule_description)
from_port = try(rule.from_port, local.rule_aliases[rule.rule].from_port, "The rule alias is invalid: ${rule.rule}. https://github.com/aidanmelen/terraform-aws-security-group-v2#rule-aliases")
to_port = try(rule.to_port, local.rule_aliases[rule.rule].to_port, null)
protocol = try(rule.protocol, local.rule_aliases[rule.rule].protocol, null)
cidr_blocks = try(rule.cidr_blocks, local.rule_aliases[rule.rule].cidr_blocks, null)
ipv6_cidr_blocks = try(rule.ipv6_cidr_blocks, local.rule_aliases[rule.rule].ipv6_cidr_blocks, null)
prefix_list_ids = try(rule.prefix_list_ids, local.rule_aliases[rule.rule].prefix_list_ids, null)
self = try(rule.self, local.rule_aliases[rule.rule].self, null)
source_security_group_id = try(rule.source_security_group_id, local.rule_aliases[rule.rule].source_security_group_id, null)
source_security_group_ids = try(rule.source_security_group_ids, local.rule_aliases[rule.rule].source_security_group_ids, null)
}
if var.create
]

egress_normalize = [
for rule in var.egress : {
description = try(rule.description, local.rule_aliases[rule.rule].description, var.default_rule_description)
from_port = try(rule.from_port, local.rule_aliases[rule.rule].from_port, "The rule alias is invalid: ${rule.rule}. https://github.com/aidanmelen/terraform-aws-security-group-v2#rule-aliases")
to_port = try(rule.to_port, local.rule_aliases[rule.rule].to_port)
protocol = try(rule.protocol, local.rule_aliases[rule.rule].protocol)
cidr_blocks = try(rule.cidr_blocks, local.rule_aliases[rule.rule].cidr_blocks, null)
ipv6_cidr_blocks = try(rule.ipv6_cidr_blocks, local.rule_aliases[rule.rule].ipv6_cidr_blocks, null)
prefix_list_ids = try(rule.prefix_list_ids, local.rule_aliases[rule.rule].prefix_list_ids, null)
self = try(rule.self, local.rule_aliases[rule.rule].self, null)
source_security_group_id = try(rule.source_security_group_id, local.rule_aliases[rule.rule].source_security_group_id, null)
source_security_group_ids = try(rule.source_security_group_ids, local.rule_aliases[rule.rule].source_security_group_ids, null)
}
if var.create
]
}

# unpack security group rule arguments
module "ingress_unpack" {
source = "./modules/null_unpack_rules"
count = var.unpack ? 1 : 0
create = var.create
rules = local.ingress_normalize
}

module "egress_unpack" {
source = "./modules/null_unpack_rules"
count = var.unpack ? 1 : 0
create = var.create
rules = local.egress_normalize
}

# create map of rules with unique keys to prevent for_each churn that occurs with a set of rules
locals {
ingress_map = {
for rule in try(module.ingress_unpack[0].rules, local.ingress_normalize) : lower(join("-", compact([
try(rule.rule, null),
try(rule.from_port, null),
try(rule.to_port, null),
try(rule.protocol, null),
try(join("-", rule.cidr_blocks), null),
try(join("-", rule.ipv6_cidr_blocks), null),
try(join("-", rule.prefix_list_ids), null),
try(rule.self, null),
try(rule.source_security_group_id, null),
]))) => rule
}

egress_map = {
for rule in try(module.egress_unpack[0].rules, local.egress_normalize) : lower(join("-", compact([
try(rule.rule, null),
try(rule.from_port, null),
try(rule.to_port, null),
try(rule.protocol, null),
try(join("-", rule.cidr_blocks), null),
try(join("-", rule.ipv6_cidr_blocks), null),
try(join("-", rule.prefix_list_ids), null),
try(rule.self, null),
try(rule.source_security_group_id, null),
]))) => rule
}
}

resource "aws_security_group_rule" "ingress" {
for_each = local.ingress_map
security_group_id = local.security_group_id
type = "ingress"
description = try(each.value.description, null)
from_port = try(each.value.from_port, null)
to_port = try(each.value.to_port, null)
protocol = try(each.value.protocol, null)
cidr_blocks = try(each.value.cidr_blocks, null)
ipv6_cidr_blocks = try(each.value.ipv6_cidr_blocks, null)
prefix_list_ids = try(each.value.prefix_list_ids, null)
self = try(each.value.self, null)
source_security_group_id = try(each.value.source_security_group_id, null)
}

resource "aws_security_group_rule" "egress" {
for_each = local.egress_map
security_group_id = local.security_group_id
type = "egress"
description = try(each.value.description, null)
from_port = try(each.value.from_port, null)
to_port = try(each.value.to_port, null)
protocol = try(each.value.protocol, null)
cidr_blocks = try(each.value.cidr_blocks, null)
ipv6_cidr_blocks = try(each.value.ipv6_cidr_blocks, null)
prefix_list_ids = try(each.value.prefix_list_ids, null)
self = try(each.value.self, null)
source_security_group_id = try(each.value.source_security_group_id, null)
}
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module "security_group" {
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.29 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.29, < 4.40.0 |
## Modules

| Name | Source | Version |
Expand Down
3 changes: 1 addition & 2 deletions examples/basic/provider.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

terraform {
required_version = ">= 0.13.1"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.29"
version = ">= 3.29, < 4.40.0"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ module "public_http_sg" {
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.29 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.29, < 4.40.0 |
## Modules

| Name | Source | Version |
Expand Down
3 changes: 1 addition & 2 deletions examples/common/provider.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

terraform {
required_version = ">= 0.13.1"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.29"
version = ">= 3.29, < 4.40.0"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/complete/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ module "disabled_sg" {
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.29 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.29, < 4.40.0 |
## Modules

| Name | Source | Version |
Expand Down
3 changes: 1 addition & 2 deletions examples/complete/provider.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

terraform {
required_version = ">= 0.13.1"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.29"
version = ">= 3.29, < 4.40.0"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/computed/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ module "security_group" {
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.29 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.29, < 4.40.0 |
## Modules

| Name | Source | Version |
Expand Down
3 changes: 1 addition & 2 deletions examples/computed/provider.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

terraform {
required_version = ">= 0.13.1"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.29"
version = ">= 3.29, < 4.40.0"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/customer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ module "security_group" {
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.29 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.29, < 4.40.0 |
## Inputs

| Name | Description | Type | Default | Required |
Expand Down
3 changes: 1 addition & 2 deletions examples/customer/provider.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

terraform {
required_version = ">= 0.13.1"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.29"
version = ">= 3.29, < 4.40.0"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/managed/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ module "security_group" {
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.29 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.29, < 4.40.0 |
## Inputs

| Name | Description | Type | Default | Required |
Expand Down
3 changes: 1 addition & 2 deletions examples/managed/provider.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

terraform {
required_version = ">= 0.13.1"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.29"
version = ">= 3.29, < 4.40.0"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/matrix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ module "security_group" {
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.29 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.29, < 4.40.0 |
## Modules

| Name | Source | Version |
Expand Down
3 changes: 1 addition & 2 deletions examples/matrix/provider.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

terraform {
required_version = ">= 0.13.1"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.29"
version = ">= 3.29, < 4.40.0"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/name_prefix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module "security_group" {
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.29 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.29, < 4.40.0 |
## Modules

| Name | Source | Version |
Expand Down
3 changes: 1 addition & 2 deletions examples/name_prefix/provider.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

terraform {
required_version = ">= 0.13.1"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.29"
version = ">= 3.29, < 4.40.0"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/rules_only/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module "security_group" {
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.29 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.29, < 4.40.0 |
## Inputs

| Name | Description | Type | Default | Required |
Expand Down
3 changes: 1 addition & 2 deletions examples/rules_only/provider.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

terraform {
required_version = ">= 0.13.1"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.29"
version = ">= 3.29, < 4.40.0"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/source_security_group_ids/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module "security_group_matrix" {
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.29 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.29, < 4.40.0 |
## Modules

| Name | Source | Version |
Expand Down
2 changes: 1 addition & 1 deletion examples/source_security_group_ids/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.29"
version = ">= 3.29, < 4.40.0"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/unpack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ module "security_group" {
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.29 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.29, < 4.40.0 |
## Modules

| Name | Source | Version |
Expand Down
3 changes: 1 addition & 2 deletions examples/unpack/provider.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

terraform {
required_version = ">= 0.13.1"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.29"
version = ">= 3.29, < 4.40.0"
}
}
}
Expand Down
Loading

0 comments on commit 43a8d19

Please sign in to comment.