44 pull_request :
55 paths :
66 - ' terracumber_config/tf_files/**/*.tf'
7- - ' .github/workflows/sumaform-validation.yml'
8- - ' !terracumber_config/tf_files/*build-validation*.tf'
9- - ' !terracumber_config/tf_files/PR-testing-template.tf'
7+ - ' terracumber_config/tf_files/tfvars/**/*.tfvars'
8+ - ' jenkins_pipelines/scripts/tf_vars_generator/**'
109
1110jobs :
1211 validate_sumaform :
1312 name : Validate sumaform files
1413 runs-on : ubuntu-latest
1514 steps :
1615 - uses : actions/checkout@v4
16+
1717 - id : tf_files
1818 name : Get modified .tf files
1919 uses : Ana06/get-changed-files@v2.3.0
2020 with :
2121 filter : ' *.tf'
2222
23- # --- MISSING STEP RE-ADDED ---
2423 - name : Install terraform
25- if : steps.tf_files.outputs.added_modified
2624 uses : hashicorp/setup-terraform@v3
2725 with :
2826 terraform_version : 1.6.0
29- terraform_wrapper : false # Required for script loops to work
30- # -----------------------------
27+ terraform_wrapper : false
3128
3229 - name : Install opentofu
33- if : steps.tf_files.outputs.added_modified
3430 uses : opentofu/setup-opentofu@v1.0.6
3531 with :
3632 tofu_version : 1.10.7
3733 - name : Checkout sumaform
38- if : steps.tf_files.outputs.added_modified
3934 uses : actions/checkout@v4
4035 with :
41- repository : uyuni-project /sumaform
36+ repository : maximenoel8 /sumaform
4237 path : sumaform
38+ ref : module_bv
39+
40+ - name : Install Python dependencies
41+ run : |
42+ pip install -r jenkins_pipelines/scripts/tf_vars_generator/requirements.txt
43+
4344 - name : Download Feilong terraform provider asset
4445 if : steps.tf_files.outputs.added_modified
4546 uses : robinraju/release-downloader@v1.12
@@ -48,110 +49,136 @@ jobs:
4849 tag : ' v0.0.9'
4950 fileName : ' terraform-provider-feilong_0.0.9_linux_amd64.tar.gz'
5051 extract : true
51- - name : Validate files
52- if : steps.tf_files.outputs.added_modified
53- env :
54- TF_VAR_SCC_USER : " user"
55- TF_VAR_SCC_PASSWORD : " password"
56- TF_VAR_MIRROR : " "
57- TF_VAR_PULL_REQUEST_REPO : " "
58- TF_VAR_MASTER_REPO : " "
59- TF_VAR_MASTER_OTHER_REPO : " "
60- TF_VAR_MASTER_SUMAFORM_TOOLS_REPO : " "
61- TF_VAR_UPDATE_REPO : " "
62- TF_VAR_ADDITIONAL_REPO_URL : " "
63- TF_VAR_TEST_PACKAGES_REPO : " "
64- TF_VAR_SLE_CLIENT_REPO : " "
65- TF_VAR_RHLIKE_CLIENT_REPO : " "
66- TF_VAR_DEBLIKE_CLIENT_REPO : " "
67- TF_VAR_OPENSUSE_CLIENT_REPO : " "
68- TF_VAR_ZVM_ADMIN_TOKEN : " "
69- TF_VAR_CONTAINER_REPOSITORY : " "
70- TF_VAR_SERVER_CONTAINER_REPOSITORY : " "
71- TF_VAR_PROXY_CONTAINER_REPOSITORY : " "
72- TF_VAR_SERVER_CONTAINER_IMAGE : " "
73- TF_VAR_ENVIRONMENT : " apprentice"
52+
53+ - name : Setup Providers
7454 run : |
7555 # Install feilong provider
7656 srcdir=/home/runner/work/susemanager-ci/susemanager-ci/
77- dstdir_terraform=/usr/share/terraform/plugins/registry.terraform.io/bischoff/feilong/0.0.4 /linux_amd64/
78- dstdir_opentofu=/usr/share/terraform/plugins/registry.opentofu.org/bischoff/feilong/0.0.4 /linux_amd64/
57+ dstdir_terraform=/usr/share/terraform/plugins/registry.terraform.io/bischoff/feilong/0.0.9 /linux_amd64/
58+ dstdir_opentofu=/usr/share/terraform/plugins/registry.opentofu.org/bischoff/feilong/0.0.9 /linux_amd64/
7959 sudo mkdir -p $dstdir_terraform
8060 sudo mkdir -p $dstdir_opentofu
8161 sudo ln -s $srcdir/terraform-provider-feilong $dstdir_terraform
8262 sudo ln -s $srcdir/terraform-provider-feilong $dstdir_opentofu
8363
84- # Remove libvirt and feilong provider settings
85- sed -i \
86- -e '/provider *"/,/^[ \/#]*\}\s*$/d' \
87- -e '/libvirt = {/,/^[ \/#]*\}\s*$/d' \
88- -e '/libvirt =/d' \
89- -e '/feilong = {/,/^[ \/#]*\}\s*$/d' \
90- -e '/feilong =/d' \
91- ${{steps.tf_files.outputs.added_modified}}
92-
93- # Also exclude s390 minions from terraform plan
94- sed -i \
95- -e '/^module ".*s390.*" {$/,/^}$/d' \
96- -e '/.*s390.*_configuration *= module.*s390.*\.configuration/d' \
97- ${{steps.tf_files.outputs.added_modified}}
98-
9964 # Setup sumaform with the 'null' backend
10065 cd sumaform
10166 ln -sfn ../backend_modules/null modules/backend
67+ mkdir -p ~/.ssh && touch ~/.ssh/id_ed25519
10268
103- # Provide a fake private SSH key
104- mkdir -p ~/.ssh
105- touch ~/.ssh/id_ed25519
106-
107- # --- OpenTofu Validation Loop ---
108- for tf_file in ${{steps.tf_files.outputs.added_modified}}; do
109- if [[ "$tf_file" != "terracumber_config/tf_files/PR-testing-template.tf" ]]; then
110- echo "::notice::[TOFU] Validating '`basename $tf_file`'..."
111- rm -f main.tf variables.tf environment.tfvars
112- cp ../$tf_file main.tf
113- PLAN_ARGS=""
114- SOURCE_DIR=$(dirname "../$tf_file")
115- if [ -f "$SOURCE_DIR/variables.tf" ]; then
116- cp "$SOURCE_DIR/variables.tf" variables.tf
117- echo "::notice::Included variables.tf from $SOURCE_DIR"
118- fi
119- if [ -f "$SOURCE_DIR/environment.tfvars" ]; then
120- cp "$SOURCE_DIR/environment.tfvars" environment.tfvars
121- # echo SCC_PTF_USER="nothing" >> environment.tfvars
122- # echo SCC_PTF_PASSWORD="nothing" >> environment.tfvars
123- PLAN_ARGS="-var-file=environment.tfvars"
124- echo "::notice::Included environment.tfvars from $SOURCE_DIR"
125- fi
126- # export TOFU_LOG=trace
127- tofu init -input=false
128- tofu validate
129- tofu plan -input=false $PLAN_ARGS
130- echo
131- fi
132- done
69+ - name : Test TFVars Generation & Validation
70+ run : |
71+ export PYTHONPATH=$PYTHONPATH:$PWD/jenkins_pipelines/scripts
72+ SCRIPT_PATH="jenkins_pipelines/scripts/tf_vars_generator/prepare_tfvars.py"
73+ TEMPLATE_TF="terracumber_config/tf_files/templates/build-validation-single-provider.tf"
74+
75+ # --- DEBUG: Verify Sumaform Checkout ---
76+ echo "::group::Debug: Verify Sumaform Directory"
77+ ls -F sumaform/
78+ if [ ! -d "sumaform/modules" ]; then
79+ echo "::error::sumaform/modules directory missing! Checkout failed?"
80+ exit 1
81+ fi
82+ echo "::endgroup::"
13383
134- # --- OpenTofu Validation Loop ---
135- for tf_file in ${{steps.tf_files.outputs.added_modified}}; do
136- if [[ "$tf_file" != "terracumber_config/tf_files/PR-testing-template.tf" ]]; then
137- echo "::notice::[TERRAFORM] Validating '`basename $tf_file`'..."
138- rm -f main.tf variables.tf environment.tfvars
139- cp ../$tf_file main.tf
140- SOURCE_DIR=$(dirname "../$tf_file")
141- PLAN_ARGS=""
142- if [ -f "$SOURCE_DIR/variables.tf" ]; then
143- cp "$SOURCE_DIR/variables.tf" variables.tf
144- echo "::notice::Included variables.tf from $SOURCE_DIR"
145- fi
146- if [ -f "$SOURCE_DIR/environment.tfvars" ]; then
147- cp "$SOURCE_DIR/environment.tfvars" environment.tfvars
148- PLAN_ARGS="-var-file=environment.tfvars"
149- echo "::notice::Included environment.tfvars from $SOURCE_DIR"
150- fi
151- # export TF_LOG=trace
152- terraform init -input=false
153- terraform validate
154- terraform plan -input=false $PLAN_ARGS
155- echo
156- fi
157- done
84+ # --- Personal BV ---
85+ echo "::group::Test 1: Generate Personal BV Configuration"
86+
87+ # Generate the tfvars file in the current directory
88+ python3 $SCRIPT_PATH \
89+ --env-file "terracumber_config/tf_files/personal/environment.tfvars" \
90+ --inject "CUCUMBER_GITREPO=test" \
91+ --inject "CUCUMBER_BRANCH=test" \
92+ --user "maxime" \
93+ --output "personal_generated.tfvars" \
94+ --minion1 "sles15sp4_minion" \
95+ --product-version "5.1-released" \
96+ --base-os "slmicro61o" \
97+ --merge-files "terracumber_config/tf_files/tfvars/location.tfvars"
98+
99+ # Prepare the execution environment inside 'sumaform' directory
100+ # This is required because the modules (source = "./modules/base") exist there.
101+ cp $TEMPLATE_TF sumaform/main.tf
102+
103+ mv personal_generated.tfvars sumaform/
104+
105+ # Create dummy variables to satisfy TF requirements
106+ cat <<EOF > sumaform/variables.tf
107+ variable "ENVIRONMENT_CONFIGURATION" {}
108+ variable "BASE_CONFIGURATIONS" {}
109+ variable "PLATFORM_LOCATION_CONFIGURATION" {}
110+ variable "LOCATION" {}
111+ variable "SCC_USER" { default="u" }
112+ variable "SCC_PASSWORD" { default="p" }
113+ variable "SCC_PTF_USER" { default="" }
114+ variable "SCC_PTF_PASSWORD" { default="" }
115+ variable "ZVM_ADMIN_TOKEN" { default="" }
116+ variable "GIT_USER" { default="" }
117+ variable "GIT_PASSWORD" { default="" }
118+ variable "SERVER_CONTAINER_REPOSITORY" { default="" }
119+ variable "PROXY_CONTAINER_REPOSITORY" { default="" }
120+ variable "SERVER_CONTAINER_IMAGE" { default="" }
121+ variable "BASE_OS" { default="" }
122+ variable "PRODUCT_VERSION" { default="" }
123+ variable "CUCUMBER_GITREPO" {}
124+ variable "CUCUMBER_BRANCH" {}
125+ EOF
126+
127+ # Run Tofu inside the sumaform directory
128+ cd sumaform
129+
130+ tofu init -input=false
131+ tofu validate
132+ tofu plan -var-file="personal_generated.tfvars" -no-color > /dev/null && echo "Personal BV Plan: OK" || echo "Personal BV Plan: FAILED"
133+
134+ # Clean up for next test
135+ rm main.tf variables.tf personal_generated.tfvars
136+ cd ..
137+ echo "::endgroup::"
138+
139+ # --- TEST 2: Static BV ---
140+ echo "::group::Test 2: Validate Static TFVars (MLM 5.1 Micro)"
141+ STATIC_VARS="terracumber_config/tf_files/tfvars/build-validation-tfvars/mlm51_micro_build_validation_nue.tfvars"
142+ LOCATION_VARS="terracumber_config/tf_files/tfvars/location.tfvars"
143+
144+ # Generate/Clean
145+ python3 $SCRIPT_PATH \
146+ --output "static_merged.tfvars" \
147+ --merge-files "$STATIC_VARS" "$LOCATION_VARS" \
148+ --inject "CUCUMBER_GITREPO=test" \
149+ --inject "CUCUMBER_BRANCH=test" \
150+ --clean \
151+ --keep-resources "sles15sp4_minion"
152+
153+ # Move to sumaform dir
154+ mv static_merged.tfvars sumaform/
155+ # (Note: main.tf template must be copied again if it was cleaned up, or reused)
156+ cp $TEMPLATE_TF sumaform/main.tf
157+ # (Re-create variables.tf if deleted, or assume it persists if not cleaned. Re-creating is safer)
158+ cat <<EOF > sumaform/variables.tf
159+ variable "ENVIRONMENT_CONFIGURATION" {}
160+ variable "BASE_CONFIGURATIONS" {}
161+ variable "PLATFORM_LOCATION_CONFIGURATION" {}
162+ variable "LOCATION" {}
163+ variable "SCC_USER" { default="u" }
164+ variable "SCC_PASSWORD" { default="p" }
165+ variable "SCC_PTF_USER" { default="" }
166+ variable "SCC_PTF_PASSWORD" { default="" }
167+ variable "ZVM_ADMIN_TOKEN" { default="" }
168+ variable "GIT_USER" { default="" }
169+ variable "GIT_PASSWORD" { default="" }
170+ variable "SERVER_CONTAINER_REPOSITORY" { default="" }
171+ variable "PROXY_CONTAINER_REPOSITORY" { default="" }
172+ variable "SERVER_CONTAINER_IMAGE" { default="" }
173+ variable "BASE_OS" { default="" }
174+ variable "PRODUCT_VERSION" { default="" }
175+ variable "CUCUMBER_GITREPO" {}
176+ variable "CUCUMBER_BRANCH" {}
177+ EOF
178+
179+ # Run Tofu
180+ cd sumaform
181+
182+ tofu plan -var-file="static_merged.tfvars" -no-color > /dev/null && echo "Static BV Plan: OK" || echo "Static BV Plan: FAILED"
183+ cd ..
184+ echo "::endgroup::"
0 commit comments