Skip to content

Commit

Permalink
refine the self stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Oct 25, 2021
1 parent 0ac74a3 commit 29e7608
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 31 deletions.
71 changes: 41 additions & 30 deletions common/ports.tf
Original file line number Diff line number Diff line change
@@ -1,37 +1,48 @@
# ports = list of list of
# from_port
# to_port
# proto
# description
# cidr_block
# list of: all, external (more added as needed)

# example only. Use your own values as appropraite

locals {
n_all = ["0.0.0.0/0"]
n_census = ["148.129.0.0/16", "192.168.0.0/16", "172.16.0.0/12", "10.0.0.0/8"]
source_groups = ["all", "external"]

ports = [
[80, 80, "tcp", "http", local.n_census, ["external"]],
[443, 443, "tcp", "https", local.n_census, ["external"]],
[8080, 8080, "tcp", "Tomcat-http", local.n_census, ["external"]],
[8443, 8443, "tcp", "Tomcat-https", local.n_census, ["external"]],
]
ports = var.ingress_port_list

# ingress_networks = var.ingress_networks
ingress_networks = []
# egress_networks = var.egress_networks
egress_networks = local.n_all
ingress_networks = var.ingress_networks
egress_networks = var.egress_networks

# these are ignored
ingress_sg = var.ingress_security_groups
egress_sg = var.egress_security_groups

p_fields = ["from", "to", "proto", "description", "cidr", "source_group"]
p_map = [for p in local.ports : zipmap(local.p_fields, p)]
port_map = { for s in local.source_groups :
s => [for p in local.p_map : p if contains(p["source_group"], s)]
}
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
p_map = length(var.ingress_port_list) > 0 ? [for p in compress(concat(local.ports, var.ingress_port_list)) : zipmap(local.p_fields, p)] : [for p in local.ports : zipmap(local.p_fields, p)]
port_map = { "external" = compress(concat(local.p_map, var.ingress_port_map)) }

p_self_fields = ["from", "to", "proto", "description"]
self_port_list = length(var.ingress_self_port_list) > 0 ? [for p in var.ingress_self_port_list : zipmap(local.p_self_fields, p)] : local._defaults["self_port_list"]
self_port_map = compress(concat(local.self_port_list, var.ingress_self_port_map))
}

# locals {
# n_all = ["0.0.0.0/0"]
# n_census = ["148.129.0.0/16", "192.168.0.0/16", "172.16.0.0/12", "10.0.0.0/8"]
# source_groups = ["all", "external"]
#
# ports = [
# [80, 80, "tcp", "http", local.n_census, ["external"]],
# [443, 443, "tcp", "https", local.n_census, ["external"]],
# [8080, 8080, "tcp", "Tomcat-http", local.n_census, ["external"]],
# [8443, 8443, "tcp", "Tomcat-https", local.n_census, ["external"]],
# ]
#
# # ingress_networks = var.ingress_networks
# ingress_networks = []
# # egress_networks = var.egress_networks
# egress_networks = local.n_all
#
# # these are ignored
# ingress_sg = var.ingress_security_groups
# egress_sg = var.egress_security_groups
#
# p_fields = ["from", "to", "proto", "description", "cidr", "source_group"]
# p_map = [for p in local.ports : zipmap(local.p_fields, p)]
# port_map = { for s in local.source_groups :
# s => [for p in local.p_map : p if contains(p["source_group"], s)]
# }
# }
#
#
2 changes: 1 addition & 1 deletion common/resources.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ resource "aws_security_group" "this_security_group" {

# ingress self (list with one or zero items)
dynamic "ingress" {
for_each = local.self
for_each = local.self_port_map
iterator = sg
content {
description = "${local.short_description}: self ${sg.value["description"]}"
Expand Down

0 comments on commit 29e7608

Please sign in to comment.