-
Notifications
You must be signed in to change notification settings - Fork 29
192 lines (168 loc) · 8.03 KB
/
sumaform-validation.yml
File metadata and controls
192 lines (168 loc) · 8.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
name: Sumaform validation
on:
pull_request:
paths:
- 'terracumber_config/tf_files/**/*.tf'
- 'terracumber_config/tf_files/tfvars/**/*.tfvars'
- 'jenkins_pipelines/scripts/tf_vars_generator/**'
- '.github/workflows/sumaform-validation.yml'
jobs:
validate_sumaform:
name: Validate sumaform files
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd #v6.0.2
- id: tf_files
name: Get modified .tf files
uses: Ana06/get-changed-files@25f79e676e7ea1868813e21465014798211fad8c #v2.3.0
with:
filter: '*.tf'
- name: Install terraform
uses: hashicorp/setup-terraform@5e8dbf3c6d9deaf4193ca7a8fb23f2ac83bb6c85
with:
terraform_version: 1.6.0
terraform_wrapper: false
- name: Install opentofu
uses: opentofu/setup-opentofu@fc711fa910b93cba0f3fbecaafc9f42fd0c411cb # v2.0.0
with:
tofu_version: 1.10.7
- name: Checkout sumaform
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd #v6.0.2
with:
repository: uyuni-project/sumaform
path: sumaform
ref: master
- name: Install Python dependencies
run: |
pip install -r jenkins_pipelines/scripts/tf_vars_generator/requirements.txt
- name: Download Feilong terraform provider asset
uses: robinraju/release-downloader@28fc21f50d76778e7023361aa1f863e717d3d56f #v1.13
with:
repository: Bischoff/terraform-provider-feilong
tag: 'v0.0.9'
fileName: 'terraform-provider-feilong_0.0.9_linux_amd64.tar.gz'
extract: true
- name: Setup Providers
run: |
# Install feilong provider
srcdir=/home/runner/work/susemanager-ci/susemanager-ci/
dstdir_terraform=/usr/share/terraform/plugins/registry.terraform.io/bischoff/feilong/0.0.9/linux_amd64/
dstdir_opentofu=/usr/share/terraform/plugins/registry.opentofu.org/bischoff/feilong/0.0.9/linux_amd64/
sudo mkdir -p $dstdir_terraform
sudo mkdir -p $dstdir_opentofu
sudo ln -s $srcdir/terraform-provider-feilong $dstdir_terraform
sudo ln -s $srcdir/terraform-provider-feilong $dstdir_opentofu
# Setup sumaform with the 'null' backend
cd sumaform
ln -sfn ../backend_modules/null modules/backend
mkdir -p ~/.ssh && touch ~/.ssh/id_ed25519
- name: Test TFVars Generation & Validation
run: |
export PYTHONPATH=$PYTHONPATH:$PWD/jenkins_pipelines/scripts
SCRIPT_PATH="jenkins_pipelines/scripts/tf_vars_generator/prepare_tfvars.py"
TEMPLATE_TF="terracumber_config/tf_files/templates/build-validation-single-provider.tf"
# --- DEBUG: Verify Sumaform Checkout ---
echo "::group::Debug: Verify Sumaform Directory"
ls -F sumaform/
if [ ! -d "sumaform/modules" ]; then
echo "::error::sumaform/modules directory missing! Checkout failed?"
exit 1
fi
echo "::endgroup::"
# --- Personal BV ---
echo "::group::Test 1: Generate Personal BV Configuration"
# Generate the tfvars file in the current directory
python3 $SCRIPT_PATH \
--env-file "terracumber_config/tf_files/personal/environment.tfvars" \
--inject "CUCUMBER_GITREPO=test" \
--inject "CUCUMBER_BRANCH=test" \
--user "apprentice" \
--output "personal_generated.tfvars" \
--minion1 "sles15sp4_minion" \
--product-version "5.1-released" \
--base-os "slmicro61o" \
--merge-files "terracumber_config/tf_files/tfvars/location.tfvars"
# Prepare the execution environment inside 'sumaform' directory
# This is required because the modules (source = "./modules/base") exist there.
cp $TEMPLATE_TF sumaform/main.tf
mv personal_generated.tfvars sumaform/
# Create dummy variables to satisfy TF requirements
cat <<EOF > sumaform/variables.tf
variable "ENVIRONMENT_CONFIGURATION" {}
variable "BASE_CONFIGURATIONS" {}
variable "PLATFORM_LOCATION_CONFIGURATION" {}
variable "LOCATION" {}
variable "SCC_USER" { default="u" }
variable "SCC_PASSWORD" { default="p" }
variable "SCC_PTF_USER" { default="" }
variable "SCC_PTF_PASSWORD" { default="" }
variable "ZVM_ADMIN_TOKEN" { default="" }
variable "GIT_USER" { default="" }
variable "GIT_PASSWORD" { default="" }
variable "SERVER_CONTAINER_REPOSITORY" { default="" }
variable "PROXY_CONTAINER_REPOSITORY" { default="" }
variable "SERVER_CONTAINER_IMAGE" { default="" }
variable "SERVER_ADDITIONAL_REPOS" { default={} }
variable "PROXY_ADDITIONAL_REPOS" { default={} }
variable "BASE_OS" { default="" }
variable "PRODUCT_VERSION" { default="" }
variable "CUCUMBER_GITREPO" {}
variable "CUCUMBER_BRANCH" {}
variable PRIVATE_SSH_KEY_PATH { default="" }
variable PUBLIC_SSH_KEY_PATH { default="" }
EOF
# Run Tofu inside the sumaform directory
cd sumaform
tofu init -input=false
tofu validate
tofu plan -var-file="personal_generated.tfvars" -no-color > /dev/null && echo "Personal BV Plan: OK" || echo "Personal BV Plan: FAILED"
# Clean up for next test
rm main.tf variables.tf personal_generated.tfvars
cd ..
echo "::endgroup::"
# --- TEST 2: Static BV ---
echo "::group::Test 2: Validate Static TFVars (MLM 5.1 Micro)"
STATIC_VARS="terracumber_config/tf_files/tfvars/build-validation-tfvars/mlm51_micro_build_validation_nue.tfvars"
LOCATION_VARS="terracumber_config/tf_files/tfvars/location.tfvars"
# Generate/Clean
python3 $SCRIPT_PATH \
--output "static_merged.tfvars" \
--merge-files "$STATIC_VARS" "$LOCATION_VARS" \
--inject "CUCUMBER_GITREPO=test" \
--inject "CUCUMBER_BRANCH=test" \
--clean \
--keep-resources "sles15sp4_minion"
# Move to sumaform dir
mv static_merged.tfvars sumaform/
# (Note: main.tf template must be copied again if it was cleaned up, or reused)
cp $TEMPLATE_TF sumaform/main.tf
# (Re-create variables.tf if deleted, or assume it persists if not cleaned. Re-creating is safer)
cat <<EOF > sumaform/variables.tf
variable "ENVIRONMENT_CONFIGURATION" {}
variable "BASE_CONFIGURATIONS" {}
variable "PLATFORM_LOCATION_CONFIGURATION" {}
variable "LOCATION" {}
variable "SCC_USER" { default="u" }
variable "SCC_PASSWORD" { default="p" }
variable "SCC_PTF_USER" { default="" }
variable "SCC_PTF_PASSWORD" { default="" }
variable "ZVM_ADMIN_TOKEN" { default="" }
variable "GIT_USER" { default="" }
variable "GIT_PASSWORD" { default="" }
variable "SERVER_CONTAINER_REPOSITORY" { default="" }
variable "PROXY_CONTAINER_REPOSITORY" { default="" }
variable "SERVER_CONTAINER_IMAGE" { default="" }
variable "SERVER_ADDITIONAL_REPOS" { default={}
variable "PROXY_ADDITIONAL_REPOS" { default={} }
variable "BASE_OS" { default="" }
variable "PRODUCT_VERSION" { default="" }
variable "CUCUMBER_GITREPO" {}
variable "CUCUMBER_BRANCH" {}
variable PRIVATE_SSH_KEY_PATH { default="" }
variable PUBLIC_SSH_KEY_PATH { default="" }
EOF
# Run Tofu
cd sumaform
tofu plan -var-file="static_merged.tfvars" -no-color > /dev/null && echo "Static BV Plan: OK" || echo "Static BV Plan: FAILED"
cd ..
echo "::endgroup::"