@@ -99,18 +99,6 @@ function download_terraform_binary() {
9999 terraform version
100100}
101101
102- # facilitates scp copy from inside the contianer
103- function fix_user_permissions() {
104- # Dev Note: scp in a container needs this fix-up
105- if ! whoami & > /dev/null
106- then
107- if [[ -w /etc/passwd ]]
108- then
109- echo " ${USER_NAME:- default} :x:$( id -u) :0:${USER_NAME:- default} user:${HOME} :/sbin/nologin" >> /etc/passwd
110- fi
111- fi
112- }
113-
114102# Cleanup prior runs
115103# VPC: Load Balancers, images, vm instances
116104# PowerVS: images, pvm instances
@@ -168,7 +156,7 @@ function cleanup_prior() {
168156 echo " Cleaning up the Security Groups"
169157 ibmcloud is security-groups --vpc " ${VPC_NAME} " --resource-group-name " ${RESOURCE_GROUP} " --output json \
170158 | jq -r ' [.[] | select(.name | contains("ocp-sec-group"))] | .[]?.name' \
171- | xargs --no-run-if-empty -I {} ibmcloud security-group-delete {} --vpc " ${VPC_NAME} " --force\
159+ | xargs --no-run-if-empty -I {} ibmcloud is security-group-delete {} --vpc " ${VPC_NAME} " --force\
172160 || true
173161
174162 echo " Cleaning up the VPC Load Balancers"
@@ -202,14 +190,31 @@ function cleanup_prior() {
202190# Destroy the cluster based on the set configuration / tfvars
203191function destroy_upi_cluster() {
204192 echo " destroy terraform to build PowerVS UPI cluster"
205- cp " ${SHARED_DIR} " /var-multi-arch-upi.tfvars " ${IBMCLOUD_HOME} " /ocp4-upi-powervs/var-multi-arch-upi.tfvars
206- echo " UPI TFVARS copied: ${IBMCLOUD_HOME} " /ocp4-upi-powervs/data/var-multi-arch-upi.tfvars
207193
208194 cp " ${CLUSTER_PROFILE_DIR} " /ssh-privatekey " ${IBMCLOUD_HOME} " /ocp4-upi-powervs/data/id_rsa
209195 cp " ${CLUSTER_PROFILE_DIR} " /ssh-publickey " ${IBMCLOUD_HOME} " /ocp4-upi-powervs/data/id_rsa.pub
210196 chmod 0600 " ${IBMCLOUD_HOME} " /ocp4-upi-powervs/data/id_rsa
211197
198+ # Loads the tfvars if it exists in the shared directory
199+ if [ ! -f " ${SHARED_DIR} " /var-multi-arch-upi.tfvars ]
200+ then
201+ echo " No tfvars provided. exiting..."
202+ exit 0
203+ fi
204+
205+ cp " ${SHARED_DIR} " /var-multi-arch-upi.tfvars " ${IBMCLOUD_HOME} " /ocp4-upi-powervs/var-multi-arch-upi.tfvars
206+ echo " UPI TFVARS copied: ${IBMCLOUD_HOME} " /ocp4-upi-powervs/data/var-multi-arch-upi.tfvars
207+
208+ # Loads the tfstate if it exists in the shared directory
209+ if [ ! -f " ${SHARED_DIR} " /terraform.tfstate ]
210+ then
211+ echo " No tfstate file provided"
212+ exit 0
213+ fi
214+
212215 cp " ${SHARED_DIR} " /terraform.tfstate " ${IBMCLOUD_HOME} " /ocp4-upi-powervs/data/terraform.tfstate
216+
217+ # Destroys the current installation for this run
213218 cd " ${IBMCLOUD_HOME} " /ocp-install-dir/ocp4-upi-powervs && \
214219 " ${IBMCLOUD_HOME} " /ocp-install-dir/terraform init && \
215220 " ${IBMCLOUD_HOME} " /ocp-install-dir/terraform destroy -auto-approve \
@@ -229,13 +234,8 @@ setup_ibmcloud_cli
229234download_terraform_binary
230235download_automation_code
231236login_ibmcloud
232-
233- if [ -f " ${SHARED_DIR} " /var-multi-arch-upi.tfvars ]
234- then
235- cleanup_prior
236- fix_user_permissions
237- destroy_upi_cluster
238- fi
237+ cleanup_prior
238+ destroy_upi_cluster
239239
240240echo " IBM Cloud PowerVS resources destroyed successfully $( date) "
241241
0 commit comments