diff --git a/modules/dns/main.tf b/modules/dns/main.tf index 19c2d0d7..7e6154a2 100644 --- a/modules/dns/main.tf +++ b/modules/dns/main.tf @@ -22,10 +22,10 @@ locals { zone = ( var.zone_create ? try( - google_dns_managed_zone.non-public.0, try( - google_dns_managed_zone.public.0, null - ) + google_dns_managed_zone.non-public.0, try( + google_dns_managed_zone.public.0, null ) + ) : try(data.google_dns_managed_zone.public.0, null) ) dns_keys = try( @@ -94,12 +94,12 @@ resource "google_dns_managed_zone" "non-public" { } data "google_dns_managed_zone" "public" { - count = var.zone_create ? 0 : 1 - name = var.name + count = var.zone_create ? 0 : 1 + name = var.name } resource "google_dns_managed_zone" "public" { - count = (var.zone_create && var.type == "public" ) ? 1 : 0 + count = (var.zone_create && var.type == "public") ? 1 : 0 project = var.project_id name = var.name dns_name = var.domain @@ -132,7 +132,7 @@ resource "google_dns_managed_zone" "public" { } data "google_dns_keys" "dns_keys" { - count = var.zone_create && ( var.dnssec_config == {} || var.type != "public" ) ? 0 : 1 + count = var.zone_create && (var.dnssec_config == {} || var.type != "public") ? 0 : 1 managed_zone = local.zone.id } diff --git a/modules/dns/variables.tf b/modules/dns/variables.tf index d6e267d9..be32349b 100644 --- a/modules/dns/variables.tf +++ b/modules/dns/variables.tf @@ -97,6 +97,10 @@ variable "type" { description = "Type of zone to create, valid values are 'public', 'private', 'forwarding', 'peering', 'service-directory'." type = string default = "private" + validation { + condition = contains(["public", "private", "forwarding", "peering", "service-directory"], var.type) + error_message = "Zone must be one of 'public', 'private', 'forwarding', 'peering', 'service-directory'." + } } variable "zone_create" { @@ -106,3 +110,4 @@ variable "zone_create" { } + diff --git a/modules/gcs/variables.tf b/modules/gcs/variables.tf index 3f48caa6..7c8d800f 100644 --- a/modules/gcs/variables.tf +++ b/modules/gcs/variables.tf @@ -88,6 +88,10 @@ variable "storage_class" { description = "Bucket storage class." type = string default = "MULTI_REGIONAL" + validation { + condition = contains(["STANDARD", "MULTI_REGIONAL", "REGIONAL", "NEARLINE", "COLDLINE", "ARCHIVE"], var.storage_class) + error_message = "Storage class must be one of STANDARD, MULTI_REGIONAL, REGIONAL, NEARLINE, COLDLINE, ARCHIVE." + } } variable "versioning" { diff --git a/modules/net-vpc/variables.tf b/modules/net-vpc/variables.tf index 7aa0fd8b..6c3ab855 100644 --- a/modules/net-vpc/variables.tf +++ b/modules/net-vpc/variables.tf @@ -100,6 +100,11 @@ variable "routing_mode" { description = "The network routing mode (default 'GLOBAL')" type = string default = "GLOBAL" + validation { + condition = var.routing_mode == "GLOBAL" || var.routing_mode == "REGIONAL" + error_message = "Routing type must be GLOBAL or REGIONAL." + } + } variable "shared_vpc_host" { diff --git a/modules/project/variables.tf b/modules/project/variables.tf index a0e965bf..8972166a 100644 --- a/modules/project/variables.tf +++ b/modules/project/variables.tf @@ -83,6 +83,10 @@ variable "parent" { description = "Parent folder or organization in 'folders/folder_id' or 'organizations/org_id' format." type = string default = null + validation { + condition = can(regex("(organizations|folders)/[0-9]+", var.parent)) + error_message = "Parent must be of the form folders/folder_id or organizations/organization_id." + } } variable "policy_boolean" {