Skip to content

Commit 80323d2

Browse files
committed
Adding validations
1 parent 5f61cf6 commit 80323d2

4 files changed

Lines changed: 10 additions & 7 deletions

File tree

modules/compute/vm-instance/variables.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,15 @@ variable "network_interfaces" {
233233
}
234234
validation {
235235
condition = alltrue([
236-
for ni in var.network_interfaces : ni.nic_type == "GVNIC" || ni.nic_type == "VIRTIO_NET" || ni.nic_type == "MRDMA" || ni.nic_type == "IRDMA" || ni.nic_type == "IDPF" || ni.nic_type == null
236+
for ni in var.network_interfaces : ni.nic_type == null || contains(["GVNIC", "VIRTIO_NET", "MRDMA", "IRDMA", "IDPF"], ni.nic_type)
237237
])
238-
error_message = "In the variable network_interfaces, field \"nic_type\" must be \"GVNIC\", \"VIRTIO_NET\", \"MRDMA\", \"IRDMA\",\"IDPF\" or null."
238+
error_message = "In the variable network_interfaces, field \"nic_type\" must be \"GVNIC\", \"VIRTIO_NET\", \"MRDMA\", \"IRDMA\", \"IDPF\" or null."
239239
}
240240
validation {
241241
condition = alltrue([
242-
for ni in var.network_interfaces : ni.stack_type == "IPV4_ONLY" || ni.stack_type == "IPV4_IPV6" || ni.stack_type == "IPV6_ONLY" || ni.stack_type == null
242+
for ni in var.network_interfaces : ni.stack_type == null || contains(["IPV4_ONLY", "IPV4_IPV6", "IPV6_ONLY"], ni.stack_type)
243243
])
244-
error_message = "In the variable network_interfaces, field \"stack_type\" must be either \"IPV4_ONLY\", \"IPV4_IPV6\" , \"IPV6_ONLY\" or null."
244+
error_message = "In the variable network_interfaces, field \"stack_type\" must be either \"IPV4_ONLY\", \"IPV4_IPV6\", \"IPV6_ONLY\" or null."
245245
}
246246
}
247247

modules/network/gpu-rdma-vpc/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
locals {
1818
autoname = replace(var.deployment_name, "_", "-")
1919
network_name = var.network_name == null ? "${local.autoname}-net" : var.network_name
20-
subnet_prefix = try(var.subnetworks_template.name_prefix, null) == null ? "${local.autoname}-subnet" : var.subnetworks_template.name_prefix
20+
subnet_prefix = var.subnetworks_template==null || var.subnetworks_template.name_prefix == null ? "${local.autoname}-subnet" : var.subnetworks_template.name_prefix
2121
is_roce_metal = var.network_profile != null ? can(regex("vpc-roce-metal", var.network_profile)) : false
2222

2323
new_bits = local.is_roce_metal ? 0 : ceil(log(var.subnetworks_template.count, 2))

modules/network/gpu-rdma-vpc/outputs.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,6 @@ output "subnetwork_interfaces_gke" {
5555

5656
output "subnetwork_name_prefix" {
5757
description = "Prefix of the RDMA subnetwork names"
58-
value = var.subnetworks_template.name_prefix
58+
# This uses a conditional: if the variable is null, return null; otherwise, return the prefix.
59+
value = var.subnetworks_template != null ? var.subnetworks_template.name_prefix : null
5960
}

modules/network/gpu-rdma-vpc/variables.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ variable "subnetworks_template" {
8181
}
8282

8383
validation {
84-
condition = can(cidrhost(var.subnetworks_template.ip_range, 0))
84+
# If the template is null, return true (pass).
85+
# Otherwise, check if the CIDR format is valid.
86+
condition = var.subnetworks_template == null ? true : can(cidrhost(var.subnetworks_template.ip_range, 0))
8587
error_message = "IP address range must be in CIDR format."
8688
}
8789
}

0 commit comments

Comments
 (0)