diff --git a/.github/actions/e2e_cleanup_timeframe/e2e-cleanup.sh b/.github/actions/e2e_cleanup_timeframe/e2e-cleanup.sh index d6d0365cb..0796ae1a0 100755 --- a/.github/actions/e2e_cleanup_timeframe/e2e-cleanup.sh +++ b/.github/actions/e2e_cleanup_timeframe/e2e-cleanup.sh @@ -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