fix: Add cloud_network default and conditional networks 49/74049/1 master v0.18.1
authorAnil Belur <abelur@linuxfoundation.org>
Wed, 7 Jan 2026 12:52:05 +0000 (22:52 +1000)
committerAnil Belur <abelur@linuxfoundation.org>
Wed, 7 Jan 2026 12:52:05 +0000 (22:52 +1000)
Fix packer validation error when cloud_network variable is not set.

Issue:
- builder.pkr.hcl: cloud_network variable had no default value
- Both templates: networks parameter required array, failed with null

Changes:
1. Added 'default = null' to cloud_network variable in builder.pkr.hcl
2. Made networks parameter conditional in both templates:
   - If cloud_network is null: networks = null (uses OpenStack default)
   - If cloud_network is set: networks = [cloud_network]

Error Fixed:
  Error: Unset variable "cloud_network"
  A used variable must be set or have a default value

Validation:
  packer validate -syntax-only templates/builder.pkr.hcl
  packer validate -syntax-only templates/docker.pkr.hcl
  Both pass successfully

Impact:
- Allows validation without cloud_network set
- Maintains backward compatibility when cloud_network is provided
- No functional change to actual builds (cloud_network provided at runtime)

Related: opendaylight/releng-builder validation failure

Change-Id: I0da5fa2b8decb71444e4066d3a82f79435aa8130
Signed-off-by: Anil Belur <askb23@gmail.com>
Signed-off-by: Anil Belur <abelur@linuxfoundation.org>
templates/builder.pkr.hcl
templates/docker.pkr.hcl

index 34ca8a5..b960dea 100644 (file)
@@ -56,7 +56,8 @@ variable "cloud_pass" {
 }
 
 variable "cloud_network" {
-  type = string
+  type    = string
+  default = null
 }
 
 variable "cloud_region" {
@@ -200,7 +201,7 @@ source "openstack" "builder" {
   metadata = {
     ci_managed = "yes"
   }
-  networks                = ["${var.cloud_network}"]
+  networks                = var.cloud_network != null ? ["${var.cloud_network}"] : null
   region                  = "${var.cloud_region}"
   source_image_name       = "${var.base_image}"
 
index b0c538d..bd65fb5 100644 (file)
@@ -206,7 +206,7 @@ source "openstack" "docker" {
   metadata = {
     ci_managed = "yes"
   }
-  networks                = ["${var.cloud_network}"]
+  networks                = var.cloud_network != null ? ["${var.cloud_network}"] : null
   region                  = "${var.cloud_region}"
   source_image_name       = "${var.base_image}"