Skip to content

Commit

Permalink
add ingress self port list
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Oct 25, 2021
1 parent 02d63b2 commit 0ac74a3
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 33 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
- custom
- create custom submodule, requires port list passed

* v2.2.1 -- 20211022
- custom
- add ingress_self_* option

# OLDER

## web
Expand Down
6 changes: 5 additions & 1 deletion common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ No modules.

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_egress_networks"></a> [egress\_networks](#input\_egress\_networks) | List of egress networks (with all pre-defined egress ports) | `list(string)` | `[]` | no |
| <a name="input_egress_networks"></a> [egress\_networks](#input\_egress\_networks) | List of egress networks (with all pre-defined egress ports) (default: any) | `list(string)` | <pre>[<br> "0.0.0.0/0"<br>]</pre> | no |
| <a name="input_egress_security_groups"></a> [egress\_security\_groups](#input\_egress\_security\_groups) | List of egress security groups (all ports) | `list(string)` | `[]` | no |
| <a name="input_enable_self"></a> [enable\_self](#input\_enable\_self) | Enable\|Disable self full access | `bool` | `false` | no |
| <a name="input_ingress_networks"></a> [ingress\_networks](#input\_ingress\_networks) | List of ingress networks for access (with all pre-defined ingress ports) | `list(string)` | `[]` | no |
| <a name="input_ingress_port_list"></a> [ingress\_port\_list](#input\_ingress\_port\_list) | Ingress port list of 5-tuple: from, to, proto, description, and cidr(list) | `list` | `[]` | no |
| <a name="input_ingress_port_map"></a> [ingress\_port\_map](#input\_ingress\_port\_map) | Ingress port list of objects: from, to, proto, description and cidr(list) | <pre>list(object({<br> from = number<br> to = number<br> proto = any<br> description = string<br> cidr = list(string)<br> }))</pre> | `[]` | no |
| <a name="input_ingress_security_groups"></a> [ingress\_security\_groups](#input\_ingress\_security\_groups) | List of ingress security groups for all ports | `list(string)` | `[]` | no |
| <a name="input_ingress_self_port_list"></a> [ingress\_self\_port\_list](#input\_ingress\_self\_port\_list) | Ingress port list of 4-tuple: from, to, proto, description | `list` | <pre>[<br> [<br> 0,<br> 0,<br> -1,<br> "all"<br> ]<br>]</pre> | no |
| <a name="input_ingress_self_port_map"></a> [ingress\_self\_port\_map](#input\_ingress\_self\_port\_map) | Ingress self access port list of objects: from, to, proto, description | <pre>list(object({<br> from = number<br> to = number<br> proto = any<br> description = string<br> }))</pre> | `[]` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | Extra security group tags | `map` | `{}` | no |
| <a name="input_use_vpc_cidr"></a> [use\_vpc\_cidr](#input\_use\_vpc\_cidr) | Enable\|Disable use of VPC CIDR block in the ingress\_networks | `bool` | `false` | no |
| <a name="input_vpc_full_name"></a> [vpc\_full\_name](#input\_vpc\_full\_name) | VPC Name | `string` | `""` | no |
Expand Down
14 changes: 7 additions & 7 deletions common/resources.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ locals {
external_ingress_networks = compact(concat(local.vpc_networks, local.ingress_networks))
ingress_sg_names = zipmap(var.ingress_security_groups, data.aws_security_group.ingress_security_groups[*].name)
egress_sg_names = zipmap(var.egress_security_groups, data.aws_security_group.egress_security_groups[*].name)
self = var.enable_self ? [1] : []
self = var.enable_self ? local.self_ports : []
}

resource "aws_security_group" "this_security_group" {
Expand All @@ -20,7 +20,7 @@ resource "aws_security_group" "this_security_group" {
from_port = p.value["from"]
to_port = p.value["to"]
protocol = p.value["proto"]
cidr_blocks = length(p.value["cidr"]) == 0 ? flatten(compact(concat(local.external_ingress_networks, var.ingress_networks))) : flatten(compact(concat(p.value["cidr"], var.ingress_networks)))
cidr_blocks = length(p.value["cidr"]) == 0 ? distinct(flatten(compact(concat(local.external_ingress_networks, var.ingress_networks)))) : distinct(flatten(compact(concat(p.value["cidr"], var.ingress_networks))))
}
}

Expand All @@ -42,10 +42,10 @@ resource "aws_security_group" "this_security_group" {
for_each = local.self
iterator = sg
content {
description = "${local.short_description}: from self"
from_port = 0
to_port = 0
protocol = -1
description = "${local.short_description}: self ${sg.value["description"]}"
from_port = sg.value["from"]
to_port = sg.value["to"]
protocol = sg.value["proto"]
self = true
}
}
Expand All @@ -56,7 +56,7 @@ resource "aws_security_group" "this_security_group" {
from_port = 0
to_port = 0
protocol = -1
cidr_blocks = flatten(compact(concat(local.egress_networks, var.egress_networks)))
cidr_blocks = distinct(flatten(compact(concat(local.egress_networks, var.egress_networks))))
}

# egress security group ids (all)
Expand Down
4 changes: 2 additions & 2 deletions common/variables.common.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ variable "ingress_networks" {
}

variable "egress_networks" {
description = "List of egress networks (with all pre-defined egress ports)"
description = "List of egress networks (with all pre-defined egress ports) (default: any)"
type = list(string)
default = []
default = ["0.0.0.0/0"]
}

variable "ingress_security_groups" {
Expand Down
35 changes: 35 additions & 0 deletions common/variables.port_list.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
variable "ingress_port_list" {
description = "Ingress port list of 5-tuple: from, to, proto, description, and cidr(list)"
# type = list(tuple([number, number, any, string, list]))
default = []
}

variable "ingress_port_map" {
description = "Ingress port list of objects: from, to, proto, description and cidr(list)"
type = list(object({
from = number
to = number
proto = any
description = string
cidr = list(string)
}))
default = []
}

variable "ingress_self_port_list" {
description = "Ingress port list of 4-tuple: from, to, proto, description"
# type = list(tuple([number, number, any, string]))
default = [[0, 0, -1, "all"]]
}

variable "ingress_self_port_map" {
description = "Ingress self access port list of objects: from, to, proto, description"
type = list(object({
from = number
to = number
proto = any
description = string
}))
default = []
}

2 changes: 1 addition & 1 deletion common/version.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
locals {
_module_version = "2.2.0"
_module_version = "2.2.2"
}
4 changes: 3 additions & 1 deletion custom/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,15 @@ No modules.
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_description"></a> [description](#input\_description) | Security Group Description | `string` | `""` | no |
| <a name="input_egress_networks"></a> [egress\_networks](#input\_egress\_networks) | List of egress networks (with all pre-defined egress ports) | `list(string)` | `[]` | no |
| <a name="input_egress_networks"></a> [egress\_networks](#input\_egress\_networks) | List of egress networks (with all pre-defined egress ports) (default: any) | `list(string)` | <pre>[<br> "0.0.0.0/0"<br>]</pre> | no |
| <a name="input_egress_security_groups"></a> [egress\_security\_groups](#input\_egress\_security\_groups) | List of egress security groups (all ports) | `list(string)` | `[]` | no |
| <a name="input_enable_self"></a> [enable\_self](#input\_enable\_self) | Enable\|Disable self full access | `bool` | `false` | no |
| <a name="input_ingress_networks"></a> [ingress\_networks](#input\_ingress\_networks) | List of ingress networks for access (with all pre-defined ingress ports) | `list(string)` | `[]` | no |
| <a name="input_ingress_port_list"></a> [ingress\_port\_list](#input\_ingress\_port\_list) | Ingress port list of 5-tuple: from, to, proto, description, and cidr(list) | `list` | `[]` | no |
| <a name="input_ingress_port_map"></a> [ingress\_port\_map](#input\_ingress\_port\_map) | Ingress port list of objects: from, to, proto, description and cidr(list) | <pre>list(object({<br> from = number<br> to = number<br> proto = any<br> description = string<br> cidr = list(string)<br> }))</pre> | `[]` | no |
| <a name="input_ingress_security_groups"></a> [ingress\_security\_groups](#input\_ingress\_security\_groups) | List of ingress security groups for all ports | `list(string)` | `[]` | no |
| <a name="input_ingress_self_port_list"></a> [ingress\_self\_port\_list](#input\_ingress\_self\_port\_list) | Ingress port list of 4-tuple: from, to, proto, description | `list` | <pre>[<br> [<br> 0,<br> 0,<br> -1,<br> "all"<br> ]<br>]</pre> | no |
| <a name="input_ingress_self_port_map"></a> [ingress\_self\_port\_map](#input\_ingress\_self\_port\_map) | Ingress self access port list of objects: from, to, proto, description | <pre>list(object({<br> from = number<br> to = number<br> proto = any<br> description = string<br> }))</pre> | `[]` | no |
| <a name="input_name"></a> [name](#input\_name) | Security Group Name (required) | `string` | n/a | yes |
| <a name="input_short_description"></a> [short\_description](#input\_short\_description) | Security Group Short Description | `string` | `""` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | Extra security group tags | `map` | `{}` | no |
Expand Down
6 changes: 6 additions & 0 deletions custom/ports.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ locals {
p_fields = ["from", "to", "proto", "description", "cidr"]
p_map = length(var.ingress_port_list) > 0 ? [for p in local.ports : zipmap(local.p_fields, p)] : var.ingress_port_map
port_map = { "external" = local.p_map }

# ingres
#variables.port_list.tf:variable "ingress_self_port_list" {
#variables.port_list.tf:variable "ingress_self_port_map" {
self_port_list = [{ from = 0, to = 0, proto = -1, description = "all" }]
self_ports = local.self_port_list
}
1 change: 1 addition & 0 deletions custom/variables.port_list.tf
20 changes: 0 additions & 20 deletions custom/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,3 @@ variable "short_description" {
type = string
default = ""
}


variable "ingress_port_list" {
description = "Ingress port list of 5-tuple: from, to, proto, description, and cidr(list)"
# type = list(tuple([number, number, any, string, list]))
default = []
}

variable "ingress_port_map" {
description = "Ingress port list of objects: from, to, proto, description and cidr(list)"
type = list(object({
from = number
to = number
proto = any
description = string
cidr = list(string)
}))
default = []
}

6 changes: 5 additions & 1 deletion sas/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,15 @@ No modules.
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_description"></a> [description](#input\_description) | Security Group Description | `string` | `""` | no |
| <a name="input_egress_networks"></a> [egress\_networks](#input\_egress\_networks) | List of egress networks (with all pre-defined egress ports) | `list(string)` | `[]` | no |
| <a name="input_egress_networks"></a> [egress\_networks](#input\_egress\_networks) | List of egress networks (with all pre-defined egress ports) (default: any) | `list(string)` | <pre>[<br> "0.0.0.0/0"<br>]</pre> | no |
| <a name="input_egress_security_groups"></a> [egress\_security\_groups](#input\_egress\_security\_groups) | List of egress security groups (all ports) | `list(string)` | `[]` | no |
| <a name="input_enable_self"></a> [enable\_self](#input\_enable\_self) | Enable\|Disable self full access | `bool` | `false` | no |
| <a name="input_ingress_networks"></a> [ingress\_networks](#input\_ingress\_networks) | List of ingress networks for access (with all pre-defined ingress ports) | `list(string)` | `[]` | no |
| <a name="input_ingress_port_list"></a> [ingress\_port\_list](#input\_ingress\_port\_list) | Ingress port list of 5-tuple: from, to, proto, description, and cidr(list) | `list` | `[]` | no |
| <a name="input_ingress_port_map"></a> [ingress\_port\_map](#input\_ingress\_port\_map) | Ingress port list of objects: from, to, proto, description and cidr(list) | <pre>list(object({<br> from = number<br> to = number<br> proto = any<br> description = string<br> cidr = list(string)<br> }))</pre> | `[]` | no |
| <a name="input_ingress_security_groups"></a> [ingress\_security\_groups](#input\_ingress\_security\_groups) | List of ingress security groups for all ports | `list(string)` | `[]` | no |
| <a name="input_ingress_self_port_list"></a> [ingress\_self\_port\_list](#input\_ingress\_self\_port\_list) | Ingress port list of 4-tuple: from, to, proto, description | `list` | <pre>[<br> [<br> 0,<br> 0,<br> -1,<br> "all"<br> ]<br>]</pre> | no |
| <a name="input_ingress_self_port_map"></a> [ingress\_self\_port\_map](#input\_ingress\_self\_port\_map) | Ingress self access port list of objects: from, to, proto, description | <pre>list(object({<br> from = number<br> to = number<br> proto = any<br> description = string<br> }))</pre> | `[]` | no |
| <a name="input_name"></a> [name](#input\_name) | Security Group Name | `string` | `""` | no |
| <a name="input_short_description"></a> [short\_description](#input\_short\_description) | Security Group Short Description | `string` | `""` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | Extra security group tags | `map` | `{}` | no |
Expand Down
3 changes: 3 additions & 0 deletions sas/ports.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,7 @@ locals {
port_map = { for s in local.source_groups :
s => [for p in local.p_map : p if contains(p["source_group"], s)]
}

self_port_list = [{ from = 0, to = 0, proto = -1, description = "all" }]
self_ports = local.self_port_list
}
1 change: 1 addition & 0 deletions sas/variables.port_list.tf

0 comments on commit 0ac74a3

Please sign in to comment.