diff --git a/.github/workflows/cleanup-test-env.yml b/.github/workflows/cleanup-test-env.yml index cba853860..eba3ea590 100644 --- a/.github/workflows/cleanup-test-env.yml +++ b/.github/workflows/cleanup-test-env.yml @@ -6,21 +6,77 @@ on: - cron: "0 3 * * *" # workflow runs every day at 03:00 AM jobs: - clenup-test-env-general: + cleanup-dev-cfn-test-github: runs-on: ubuntu-latest steps: - - name: Checkout + - name: terraform-provider-mongodbatlas-checkout uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 with: - sparse-checkout: | - scripts - - uses: mongodb/atlas-github-action@15663d068c40a8582d881560961fce9d45e0df9a + repository: mongodb/terraform-provider-mongodbatlas - name: Cleanup cloud-dev CFN Test GitHub - shell: bash + uses: ./.github/templates/clean-atlas-org env: MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.CLOUD_DEV_PUBLIC_KEY }} MONGODB_ATLAS_PRIVATE_KEY: ${{ secrets.CLOUD_DEV_PRIVATE_KEY }} MONGODB_ATLAS_ORG_ID: ${{ secrets.CLOUD_DEV_ORG_ID }} - MONGODB_ATLAS_OPS_MANAGER_URL: ${{ vars.MONGODB_ATLAS_BASE_URL }} - PROJECT_TO_NOT_DELETE: ${{ vars.CLOUD_DEV_PROJECT_ID }} - run: ./scripts/cleanup-test-env.sh + MONGODB_ATLAS_BASE_URL: ${{ vars.MONGODB_ATLAS_BASE_URL }} + MONGODB_ATLAS_CLEAN_RETRY_ATTEMPTS: "1" + cleanup-dev-cfntest: + runs-on: ubuntu-latest + steps: + - name: terraform-provider-mongodbatlas-checkout + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + with: + repository: mongodb/terraform-provider-mongodbatlas + - name: Cleanup cloud-dev CFN Test + uses: ./.github/templates/clean-atlas-org + env: + MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.CLOUD_DEV_CFN_TEST_PUBLIC_KEY }} + MONGODB_ATLAS_PRIVATE_KEY: ${{ secrets.CLOUD_DEV_CFN_TEST_PRIVATE_KEY }} + MONGODB_ATLAS_ORG_ID: ${{ secrets.CLOUD_DEV_CFN_TEST_ORG_ID }} + MONGODB_ATLAS_BASE_URL: ${{ vars.MONGODB_ATLAS_BASE_URL }} + MONGODB_ATLAS_CLEAN_RETRY_ATTEMPTS: "1" + cleanup-qa-env-rp: + runs-on: ubuntu-latest + steps: + - name: terraform-provider-mongodbatlas-checkout + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + with: + repository: mongodb/terraform-provider-mongodbatlas + - name: Cleanup cloud-dev CFN Test GitHub + uses: ./.github/templates/clean-atlas-org + env: + MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.MONGODB_ATLAS_RP_PUBLIC_KEY_QA }} + MONGODB_ATLAS_PRIVATE_KEY: ${{ secrets.MONGODB_ATLAS_RP_PRIVATE_KEY_QA }} + MONGODB_ATLAS_ORG_ID: ${{ vars.MONGODB_ATLAS_RP_ORG_ID_QA }} + MONGODB_ATLAS_BASE_URL: https://cloud-qa.mongodb.com/ + MONGODB_ATLAS_CLEAN_RETRY_ATTEMPTS: "1" + cleanup-prod-env-general: + runs-on: ubuntu-latest + steps: + - name: terraform-provider-mongodbatlas-checkout + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + with: + repository: mongodb/terraform-provider-mongodbatlas + - name: Cleanup cloud-dev CFN Test GitHub + uses: ./.github/templates/clean-atlas-org + env: + MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.ATLAS_PUBLIC_KEY_PUBLISHING }} + MONGODB_ATLAS_PRIVATE_KEY: ${{ secrets.ATLAS_PRIVATE_KEY_PUBLISHING }} + MONGODB_ATLAS_ORG_ID: ${{ secrets.ATLAS_ORG_ID_PUBLISHING }} + MONGODB_ATLAS_CLEAN_RETRY_ATTEMPTS: "1" + cleanup-prod-data-federation: + runs-on: ubuntu-latest + steps: + - name: terraform-provider-mongodbatlas-checkout + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + with: + repository: mongodb/terraform-provider-mongodbatlas + ref: 133ee57735e0c8f2b22e74bbd9f8c3fdd8da2f9c + - name: Cleanup cloud-dev CFN Test GitHub + uses: ./.github/templates/clean-atlas-org + env: + MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.ATLAS_PUBLIC_KEY_FOR_FEDERATION_PUBLISHING }} + MONGODB_ATLAS_PRIVATE_KEY: ${{ secrets.ATLAS_PRIVATE_KEY_FOR_FEDERATION_PUBLISHING }} + MONGODB_ATLAS_ORG_ID: ${{ vars.ATLAS_ORG_ID_FOR_FEDERATION_PUBLISHING }} + MONGODB_ATLAS_CLEAN_RETRY_ATTEMPTS: "1" diff --git a/scripts/cleanup-test-env.sh b/scripts/cleanup-test-env.sh deleted file mode 100755 index 0e224e6a3..000000000 --- a/scripts/cleanup-test-env.sh +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2023 MongoDB Inc -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -Eeou pipefail - -delete_endpoint() { - provider=$1 - count=$(atlas privateEndpoints "${provider}" list --projectId "${clean_project_id}" -o=go-template="{{len .}}") - retVal=$? - if [ $retVal -ne 0 ]; then - count=0 - fi - if [ "${count}" != "0" ]; then - echo "Project ${clean_project_id} contains ${provider} endpoints, will start deleting" - id=$(atlas privateEndpoints "${provider}" list --projectId "${clean_project_id}" -o=go-template="{{(index . 0).Id}}") - atlas privateEndpoints "${provider}" delete "${id}" --force --projectId "${clean_project_id}" - fi -} - -projectToSkip="${PROJECT_TO_NOT_DELETE:-NONE}" - -export MCLI_OPS_MANAGER_URL="${MONGODB_ATLAS_OPS_MANAGER_URL}" -export MCLI_PRIVATE_API_KEY="${MONGODB_ATLAS_PRIVATE_KEY}" -export MCLI_PUBLIC_API_KEY="${MONGODB_ATLAS_PUBLIC_KEY}" -export MCLI_ORG_ID="${MONGODB_ATLAS_ORG_ID}" -org_id="${MONGODB_ATLAS_ORG_ID}" - -# Get all project Ids inside the organization -projects=$(atlas project ls --limit 500 --orgId "${org_id}" -o json) - -echo "${projects}" | jq -c '.results[].id' | while read -r id; do - # Trim the quotes from the id - clean_project_id=$(echo "$id" | tr -d '"') - if [ "${clean_project_id}" = "${projectToSkip}" ]; then - echo "Skipping project with ID ${projectToSkip}" - continue - fi - - clusters=$(atlas cluster ls --projectId "${clean_project_id}" -o=go-template="{{.TotalCount}}") - if [ "${clusters}" != "0" ]; then - echo "Project ${clean_project_id} contains clusters. Skipping..." - continue - fi - - set +e - delete_endpoint "aws" - delete_endpoint "gcp" - delete_endpoint "azure" - set -e - - echo "Deleting projectId ${clean_project_id}" - # This command can fail if project has a cluster, a private endpoint, or general failure. The echo command always succeeds so the subshell will succeed and continue - ( - atlas project delete "${clean_project_id}" --force || - echo "Failed to delete project with ID ${clean_project_id}" - ) -done