Add service-specific web egress rules
This commit is contained in:
@@ -103,6 +103,16 @@ locals {
|
||||
cidr_ipv4 = "0.0.0.0/0"
|
||||
}
|
||||
},
|
||||
{
|
||||
for key, rule in var.web_egress_service_rules :
|
||||
"service_${key}" => {
|
||||
description = rule.description
|
||||
ip_protocol = rule.ip_protocol
|
||||
from_port = rule.port
|
||||
to_port = rule.port
|
||||
cidr_ipv4 = rule.cidr_ipv4
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
ssh_security_group_name = coalesce(var.ssh_security_group.name, "${var.name_prefix}-ssh-enabled")
|
||||
|
||||
@@ -123,6 +123,27 @@ variable "web_egress_policy" {
|
||||
}
|
||||
}
|
||||
|
||||
variable "web_egress_service_rules" {
|
||||
description = "Additional public-web egress rules for services on a single explicit destination CIDR."
|
||||
type = map(object({
|
||||
description = string
|
||||
ip_protocol = string
|
||||
port = number
|
||||
cidr_ipv4 = string
|
||||
}))
|
||||
|
||||
validation {
|
||||
condition = alltrue([
|
||||
for rule in values(var.web_egress_service_rules) :
|
||||
contains(["tcp", "udp"], rule.ip_protocol) &&
|
||||
rule.port >= 1 && rule.port <= 65535 && rule.port == floor(rule.port) &&
|
||||
trimspace(rule.description) != "" &&
|
||||
can(cidrnetmask(rule.cidr_ipv4))
|
||||
])
|
||||
error_message = "Every service egress rule must have a description, TCP or UDP protocol, an integer port from 1 through 65535, and a valid IPv4 CIDR."
|
||||
}
|
||||
}
|
||||
|
||||
variable "web_instance" {
|
||||
description = "Existing public web EC2 instance. user_data is intentionally absent."
|
||||
type = object({
|
||||
|
||||
Reference in New Issue
Block a user