refactor: consolidate security-group and security-group-rule
This commit is contained in:
parent
3a722642b5
commit
7b16b3e7d5
11 changed files with 150 additions and 169 deletions
|
|
@ -1,32 +1,10 @@
|
|||
module "icmp_group" {
|
||||
source = "../security-group"
|
||||
project_id = var.project_id
|
||||
name = "icmp"
|
||||
}
|
||||
module "security_groups" {
|
||||
source = "../security-group"
|
||||
|
||||
module "ssh_group" {
|
||||
source = "../security-group"
|
||||
project_id = var.project_id
|
||||
name = "ssh"
|
||||
}
|
||||
for_each = var.security_groups
|
||||
|
||||
module "icmp_ingress" {
|
||||
source = "../security-group-rule"
|
||||
project_id = var.project_id
|
||||
security_group_id = module.icmp_group.id
|
||||
rules = var.icmp_ingress_rules
|
||||
}
|
||||
|
||||
module "icmp_egress" {
|
||||
source = "../security-group-rule"
|
||||
project_id = var.project_id
|
||||
security_group_id = module.icmp_group.id
|
||||
rules = var.icmp_egress_rules
|
||||
}
|
||||
|
||||
module "ssh_ingress" {
|
||||
source = "../security-group-rule"
|
||||
project_id = var.project_id
|
||||
security_group_id = module.ssh_group.id
|
||||
rules = var.ssh_ingress_rules
|
||||
}
|
||||
project_id = var.project_id
|
||||
name = each.value.name
|
||||
description = each.value.description
|
||||
rules = each.value.rules
|
||||
}
|
||||
|
|
@ -2,55 +2,58 @@ region = "eu01"
|
|||
service_account_token = ""
|
||||
project_id = ""
|
||||
|
||||
# icmp_ingress_rules = [
|
||||
# {
|
||||
# direction = "ingress"
|
||||
# description = "ICMP RULE 1"
|
||||
# ip_range = "0.0.0.0/0"
|
||||
# protocol = {
|
||||
# name = "icmp"
|
||||
# }
|
||||
# icmp_parameters = {
|
||||
# type = 8,
|
||||
# code = 0
|
||||
# }
|
||||
# },
|
||||
# {
|
||||
# direction = "ingress"
|
||||
# description = "ICMP RULE 2"
|
||||
# ip_range = "1.2.3.4/0"
|
||||
# protocol = {
|
||||
# name = "icmp"
|
||||
# }
|
||||
# icmp_parameters = {
|
||||
# type = 8,
|
||||
# code = 0
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
security_groups = {
|
||||
ssh_ingress_group = {
|
||||
name = "ssh-ingress-group"
|
||||
description = "ALLOW SSH ingress"
|
||||
rules = [
|
||||
{
|
||||
description = "SSH RULE 1"
|
||||
direction = "ingress"
|
||||
ether_type = "IPv4"
|
||||
ip_range = "0.0.0.0/0"
|
||||
protocol = {
|
||||
name = "tcp"
|
||||
}
|
||||
port_range = {
|
||||
min = 22
|
||||
max = 22
|
||||
}
|
||||
},
|
||||
]
|
||||
},
|
||||
|
||||
# ssh_ingress_rules = [
|
||||
# {
|
||||
# direction = "ingress"
|
||||
# description = "SSH RULE 1"
|
||||
# ip_range = "10.1.10.1/24"
|
||||
# port_range = {
|
||||
# min = 22,
|
||||
# max = 22
|
||||
# }
|
||||
# protocol = {
|
||||
# name = "tcp"
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
web_traffic_group = {
|
||||
name = "web-traffic-group"
|
||||
description = "ALLOW WEB TRAFFIC ingress"
|
||||
rules = [
|
||||
{
|
||||
description = "ALLOW ALL 80"
|
||||
direction = "ingress"
|
||||
ether_type = "IPv4"
|
||||
ip_range = "0.0.0.0/0"
|
||||
protocol = {
|
||||
name = "tcp"
|
||||
}
|
||||
port_range = {
|
||||
min = 80
|
||||
max = 80
|
||||
}
|
||||
},
|
||||
{
|
||||
description = "ALLOW ALL 443"
|
||||
direction = "ingress"
|
||||
ether_type = "IPv4"
|
||||
ip_range = "0.0.0.0/0"
|
||||
protocol = {
|
||||
name = "tcp"
|
||||
}
|
||||
port_range = {
|
||||
min = 443
|
||||
max = 443
|
||||
}
|
||||
},
|
||||
]
|
||||
},
|
||||
|
||||
# icmp_egress_rules = [
|
||||
# {
|
||||
# direction = "egress"
|
||||
# description = "ICMP EGRESS RULE 1"
|
||||
# ip_range = "0.0.0.0/0"
|
||||
# protocol = {
|
||||
# name = "icmp"
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
}
|
||||
|
|
@ -15,14 +15,29 @@ variable "service_account_token" {
|
|||
type = string
|
||||
}
|
||||
|
||||
variable "icmp_ingress_rules" {
|
||||
type = any
|
||||
}
|
||||
|
||||
variable "icmp_egress_rules" {
|
||||
type = any
|
||||
}
|
||||
|
||||
variable "ssh_ingress_rules" {
|
||||
type = any
|
||||
variable "security_groups" {
|
||||
type = map(object({
|
||||
name = optional(string)
|
||||
description = optional(string)
|
||||
rules = list(object({
|
||||
direction = string
|
||||
description = optional(string)
|
||||
ether_type = optional(string)
|
||||
icmp_parameters = optional(object({
|
||||
type = optional(number)
|
||||
code = optional(number)
|
||||
}))
|
||||
ip_range = optional(string)
|
||||
port_range = optional(object({
|
||||
min = number
|
||||
max = number
|
||||
}))
|
||||
protocol = optional(object({
|
||||
name = optional(string)
|
||||
number = optional(number)
|
||||
}))
|
||||
remote_security_group_id = optional(string)
|
||||
}))
|
||||
}))
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue