diff --git a/README.md b/README.md index 95ba7523..8a7809e5 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,7 @@ running out of space. ### [bosh-delete-deployment][bosh-delete-deployment-task-yaml] This deletes a BOSH deployment. +If you want to delete all of the available BOSH deployments you can set the `DELETE_ALL_DEPLOYMENTS` flag to `true`. ### [bosh-deploy][bosh-deploy-task-yaml] This performs a BOSH upload-stemcell and BOSH deployment. diff --git a/bosh-delete-deployment/task b/bosh-delete-deployment/task index ded00b38..c54c211e 100755 --- a/bosh-delete-deployment/task +++ b/bosh-delete-deployment/task @@ -4,6 +4,21 @@ set -exu # shellcheck disable=SC1091 source cf-deployment-concourse-tasks/shared-functions +function bosh_delete_all_deployments() { + local deployments + deployments=$(bosh deployments --json | jq -r '.Tables[].Rows[].name') + + for deployment in ${deployments}; do + if [ -n "${deployment}" ]; then + echo "Deleting deployment: ${deployment}" + bosh \ + -n \ + delete-deployment -d "${deployment}" \ + ${force_flag} + fi + done +} + function check_delete_deployment_params() { if [ -z "$DEPLOYMENT_NAME" ]; then echo "DEPLOYMENT_NAME has not been set" @@ -25,9 +40,13 @@ function bosh_delete_deployment() { } function main() { - check_delete_deployment_params setup_bosh_env_vars - bosh_delete_deployment + if [ "$DELETE_ALL_DEPLOYMENTS" = true ]; then + bosh_delete_all_deployments + else + check_delete_deployment_params + bosh_delete_deployment + fi } main diff --git a/bosh-delete-deployment/task.yml b/bosh-delete-deployment/task.yml index 149eaef5..e18876d8 100644 --- a/bosh-delete-deployment/task.yml +++ b/bosh-delete-deployment/task.yml @@ -21,6 +21,10 @@ params: # - If blank or '.', uses `bbl-state` input as the location for bbl state # - If the specified path does not exist, it will be created + DELETE_ALL_DEPLOYMENTS: false + # - Optional + # - When true, deletes ALL BOSH deployments + DEPLOYMENT_NAME: cf IGNORE_ERRORS: false