Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions compute/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ variable "psc_consumer_subnet_cidr" {
type = string
default = "10.0.2.0/29"
description = "CIDR for the PSC consumer subnet created in this VPC. Must not overlap var.subnet_cidr."

validation {
condition = can(cidrnetmask(var.psc_consumer_subnet_cidr))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This passes 10.0.2.1/29 and /30–/32, and GCP rejects both at apply. Also require a network address and a prefix of /29 or shorter.

Suggested change
condition = can(cidrnetmask(var.psc_consumer_subnet_cidr))
condition = (
can(cidrnetmask(var.psc_consumer_subnet_cidr)) &&
try(cidrsubnet(var.psc_consumer_subnet_cidr, 0, 0) == var.psc_consumer_subnet_cidr, false) &&
try(tonumber(split("/", var.psc_consumer_subnet_cidr)[1]) <= 29, false)
)

error_message = "psc_consumer_subnet_cidr must be an IPv4 CIDR such as 10.0.2.0/29."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · With the condition from haimbj1's suggestion on line 64, this message is wrong for 10.0.2.1/29 and /30, because both are IPv4 CIDRs. Say what the check requires.

Suggested change
error_message = "psc_consumer_subnet_cidr must be an IPv4 CIDR such as 10.0.2.0/29."
error_message = "psc_consumer_subnet_cidr must be an IPv4 network address with a prefix of /29 or shorter, such as 10.0.2.0/29."

}
}

variable "caller_cidr" {
Expand Down
Loading