ci: dont fail if Azure resources were already deleted (#3827)

* ci: dont fail if Azure resources were already deleted
* ci: fix error assignement

---------

Signed-off-by: Daniel Weiße <dw@edgeless.systems>
This commit is contained in:
Daniel Weiße 2025-05-12 11:24:11 +02:00 committed by GitHub
parent 0c73a3ed25
commit 228e1e76fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -15,6 +15,14 @@ function download_tfstate_artifact {
function delete_terraform_resources {
delete_err=0
if pushd "${1}/${2}"; then
# Workaround for cleaning up Azure resources
# We include a data source that is only used to generate output
# If this data source is deleted before we call terraform destroy,
# terraform will first try to evaluate the data source and fail,
# causing the destroy to fail as well.
sed -i '/data "azurerm_user_assigned_identity" "uaid" {/,/}/d' main.tf
sed -i '/output "user_assigned_identity_client_id" {/,/}/d' outputs.tf
terraform init > /dev/null || delete_err=1 # first, install plugins
terraform destroy -auto-approve || delete_err=1
popd || exit 1
@ -79,9 +87,15 @@ echo "[*] deleting resources"
error_occurred=0
for directory in ./terraform-state-*; do
echo " deleting resources in ${directory}"
delete_terraform_resources "${directory}" "constellation-terraform" || echo "[!] deleting resources failed" && error_occurred=1
if ! delete_terraform_resources "${directory}" "constellation-terraform"; then
echo "[!] deleting resources failed"
error_occurred=1
fi
echo " deleting IAM configuration in ${directory}"
delete_terraform_resources "${directory}" "constellation-iam-terraform" || echo "[!] deleting IAM resources failed" && error_occurred=1
if ! delete_terraform_resources "${directory}" "constellation-iam-terraform"; then
echo "[!] deleting IAM resources failed"
error_occurred=1
fi
echo " deleting directory ${directory}"
rm -rf "${directory}"
done