Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.

feat(delivery): integrate TF refactor into cleanup script #487

Merged
merged 3 commits into from
Jun 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions terraform/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ gcloud scheduler jobs delete nightly-builds \
|| true

# Remove existing Terraform state (Part 1)
pushd "terraform/ops"
pushd terraform/environments/ops
terraform init
terraform apply \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

future change: could we switch to terraform destroy for brevity and clarity? This through me a bit as I was trying to figure out why a cleanup script was creating resources.

-destroy --auto-approve \
Expand All @@ -146,25 +146,33 @@ terraform apply \
popd

# Remove existing Terraform state (Part 2)
APP_PROJECTS=(
"${STAGE_PROJECT}"
"${PROD_PROJECT}"
)
pushd terraform/environments/staging
cat > terraform.tfvars <<EOF
google_ops_project_id = "${OPS_PROJECT}"
google_project_id = "${STAGE_PROJECT}"
EOF

pushd terraform/app
for proj in ${APP_PROJECTS[@]}; do
terraform init
terraform apply \
-destroy --auto-approve \
-var google_ops_project_id="${OPS_PROJECT}" \
-var google_project_id="${STAGE_PROJECT}" \
|| true
popd

# Remove existing Terraform state (Part 3)
pushd terraform/environments/prod
cat > terraform.tfvars <<EOF
google_ops_project_id = "${OPS_PROJECT}"
google_project_id = "${proj}"
google_project_id = "${PROD_PROJECT}"
EOF

terraform init
terraform apply \
-destroy --auto-approve \
-var google_ops_project_id="${OPS_PROJECT}" \
-var google_project_id="${proj}" \
|| true
done
terraform init
terraform apply \
-destroy --auto-approve \
-var google_ops_project_id="${OPS_PROJECT}" \
-var google_project_id="${PROD_PROJECT}" \
|| true
popd

echo "###################################################"
Expand Down