Skip to content

Commit

Permalink
AWS/Azure/Gcloud Networking - replace defaults with an empty string a…
Browse files Browse the repository at this point in the history
…nd raise a helpful message for users
  • Loading branch information
bryan-bar committed Feb 15, 2024
1 parent ae3cf03 commit cd712b6
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
5 changes: 5 additions & 0 deletions edbterraform/data/terraform/aws/modules/security/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ resource "aws_security_group_rule" "rule" {
error_message = "${each.key} has type ${each.value.type}. Must be ingress or egress."
}

precondition {
error_message = "port defaults must be one of: service, public, internal or an empty string ('')"
condition = contains(["service", "internal", "public", ""], try(each.value.defaults, ""))
}

precondition {
condition = each.value.cidrs != null && length(each.value.cidrs) > 0
error_message = <<-EOT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ variable "spec" {
cidr = optional(string)
})), {})
ports = optional(list(object({
defaults = optional(string, "service")
defaults = optional(string, "")
port = optional(number)
to_port = optional(number)
protocol = string
Expand All @@ -55,7 +55,7 @@ variable "spec" {
region = string
ssh_port = optional(number, 22)
ports = optional(list(object({
defaults = optional(string, "internal")
defaults = optional(string, "")
port = optional(number)
to_port = optional(number)
protocol = string
Expand Down
5 changes: 5 additions & 0 deletions edbterraform/data/terraform/azure/modules/security/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,10 @@ resource "azurerm_network_security_rule" "rules" {
condition = each.value.type == "ingress" || each.value.type == "egress"
error_message = "${each.key} has type ${each.value.type}. Must be ingress or egress."
}

precondition {
error_message = "port defaults must be one of: service, public, internal or an empty string ('')"
condition = contains(["service", "internal", "public", ""], try(each.value.defaults, ""))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ variable "spec" {
cidr = optional(string)
})), {})
ports = optional(list(object({
defaults = optional(string, "service")
defaults = optional(string, "")
port = optional(number)
to_port = optional(number)
protocol = string
Expand All @@ -60,7 +60,7 @@ variable "spec" {
instance_type = string
ssh_port = optional(number, 22)
ports = optional(list(object({
defaults = optional(string, "internal")
defaults = optional(string, "")
port = optional(number)
to_port = optional(number)
protocol = string
Expand Down
5 changes: 5 additions & 0 deletions edbterraform/data/terraform/gcloud/modules/security/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,10 @@ resource "google_compute_firewall" "rules" {
condition = each.value.type == "ingress" || each.value.type == "egress"
error_message = "${each.key} has type ${each.value.type}. Must be ingress or egress."
}

precondition {
error_message = "port defaults must be one of: service, public, internal or an empty string ('')"
condition = contains(["service", "internal", "public", ""], try(each.value.defaults, ""))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ variable "spec" {
cidr = optional(string)
})), {})
ports = optional(list(object({
defaults = optional(string, "service")
defaults = optional(string, "")
port = optional(number)
to_port = optional(number)
protocol = string
Expand All @@ -59,7 +59,7 @@ variable "spec" {
ip_forward = optional(bool)
ssh_port = optional(number, 22)
ports = optional(list(object({
defaults = optional(string, "internal")
defaults = optional(string, "")
port = optional(number)
to_port = optional(number)
protocol = string
Expand Down

0 comments on commit cd712b6

Please sign in to comment.