From 5bf55808410a8feb3bb6ab2ddcdb11a070778d26 Mon Sep 17 00:00:00 2001 From: Espen Albert Date: Wed, 5 Feb 2025 09:54:23 +0000 Subject: [PATCH 1/8] chore: Update cleanup-test-env workflow for MongoDB Atlas provider and cleanup script --- .github/workflows/cleanup-test-env.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/cleanup-test-env.yml b/.github/workflows/cleanup-test-env.yml index cba853860..7fd9747d3 100644 --- a/.github/workflows/cleanup-test-env.yml +++ b/.github/workflows/cleanup-test-env.yml @@ -9,18 +9,18 @@ jobs: clenup-test-env-general: 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 + ref: 133ee57735e0c8f2b22e74bbd9f8c3fdd8da2f9c - name: Cleanup cloud-dev CFN Test GitHub - shell: bash + uses: ./.github/templates/clean-atlas-org + with: + dry-run: 'true' 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" From d2a693be077e237b2e4fcca8fa824c7194447e08 Mon Sep 17 00:00:00 2001 From: Espen Albert Date: Wed, 5 Feb 2025 11:36:31 +0000 Subject: [PATCH 2/8] chore: Fix typo in cleanup-test-env workflow and add cleanup-prod-env job --- .github/workflows/cleanup-test-env.yml | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cleanup-test-env.yml b/.github/workflows/cleanup-test-env.yml index 7fd9747d3..4dc1989e1 100644 --- a/.github/workflows/cleanup-test-env.yml +++ b/.github/workflows/cleanup-test-env.yml @@ -6,7 +6,7 @@ on: - cron: "0 3 * * *" # workflow runs every day at 03:00 AM jobs: - clenup-test-env-general: + cleanup-test-env-general: runs-on: ubuntu-latest steps: - name: terraform-provider-mongodbatlas-checkout @@ -24,3 +24,20 @@ jobs: MONGODB_ATLAS_ORG_ID: ${{ secrets.CLOUD_DEV_ORG_ID }} MONGODB_ATLAS_BASE_URL: ${{ vars.MONGODB_ATLAS_BASE_URL }} 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 + ref: 133ee57735e0c8f2b22e74bbd9f8c3fdd8da2f9c + - name: Cleanup cloud-dev CFN Test GitHub + uses: ./.github/templates/clean-atlas-org + with: + dry-run: 'true' + 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" From 9702c78f808f15650b168e91a4ea7674417c4e2d Mon Sep 17 00:00:00 2001 From: Espen Albert Date: Wed, 5 Feb 2025 11:40:14 +0000 Subject: [PATCH 3/8] chore: Add cleanup-qa-rp (resource-policy) --- .github/workflows/cleanup-test-env.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.github/workflows/cleanup-test-env.yml b/.github/workflows/cleanup-test-env.yml index 4dc1989e1..b6987b1e4 100644 --- a/.github/workflows/cleanup-test-env.yml +++ b/.github/workflows/cleanup-test-env.yml @@ -24,6 +24,24 @@ jobs: MONGODB_ATLAS_ORG_ID: ${{ secrets.CLOUD_DEV_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 + ref: 133ee57735e0c8f2b22e74bbd9f8c3fdd8da2f9c + - name: Cleanup cloud-dev CFN Test GitHub + uses: ./.github/templates/clean-atlas-org + with: + dry-run: 'true' + 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: From e042ef865341e297c7d9f14020b586d2d2c3aa3d Mon Sep 17 00:00:00 2001 From: Espen Albert Date: Thu, 6 Feb 2025 21:39:38 +0000 Subject: [PATCH 4/8] chore: Remove dry-run option from cleanup-test-env workflow and add cleanup-prod-data-federation job --- .github/workflows/cleanup-test-env.yml | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/.github/workflows/cleanup-test-env.yml b/.github/workflows/cleanup-test-env.yml index b6987b1e4..7b26807b3 100644 --- a/.github/workflows/cleanup-test-env.yml +++ b/.github/workflows/cleanup-test-env.yml @@ -16,8 +16,6 @@ jobs: ref: 133ee57735e0c8f2b22e74bbd9f8c3fdd8da2f9c - name: Cleanup cloud-dev CFN Test GitHub uses: ./.github/templates/clean-atlas-org - with: - dry-run: 'true' env: MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.CLOUD_DEV_PUBLIC_KEY }} MONGODB_ATLAS_PRIVATE_KEY: ${{ secrets.CLOUD_DEV_PRIVATE_KEY }} @@ -34,8 +32,6 @@ jobs: ref: 133ee57735e0c8f2b22e74bbd9f8c3fdd8da2f9c - name: Cleanup cloud-dev CFN Test GitHub uses: ./.github/templates/clean-atlas-org - with: - dry-run: 'true' env: MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.MONGODB_ATLAS_RP_PUBLIC_KEY_QA }} MONGODB_ATLAS_PRIVATE_KEY: ${{ secrets.MONGODB_ATLAS_RP_PRIVATE_KEY_QA }} @@ -52,10 +48,23 @@ jobs: ref: 133ee57735e0c8f2b22e74bbd9f8c3fdd8da2f9c - name: Cleanup cloud-dev CFN Test GitHub uses: ./.github/templates/clean-atlas-org - with: - dry-run: 'true' 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 }} + MONGODB_ATLAS_PRIVATE_KEY: ${{ secrets.ATLAS_PRIVATE_KEY_FOR_FEDERATION }} + MONGODB_ATLAS_ORG_ID: ${{ secrets.ATLAS_ORG_ID_FOR_FEDERATION }} + MONGODB_ATLAS_CLEAN_RETRY_ATTEMPTS: "1" From 61a5fba7d269b39afddf993b8898e020bcacb2b9 Mon Sep 17 00:00:00 2001 From: Espen Albert Date: Thu, 6 Feb 2025 21:44:22 +0000 Subject: [PATCH 5/8] chore: Update MongoDB Atlas secrets for cleanup-test-env workflow --- .github/workflows/cleanup-test-env.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cleanup-test-env.yml b/.github/workflows/cleanup-test-env.yml index 7b26807b3..07374aa03 100644 --- a/.github/workflows/cleanup-test-env.yml +++ b/.github/workflows/cleanup-test-env.yml @@ -64,7 +64,7 @@ jobs: - name: Cleanup cloud-dev CFN Test GitHub uses: ./.github/templates/clean-atlas-org env: - MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.ATLAS_PUBLIC_KEY_FOR_FEDERATION }} - MONGODB_ATLAS_PRIVATE_KEY: ${{ secrets.ATLAS_PRIVATE_KEY_FOR_FEDERATION }} - MONGODB_ATLAS_ORG_ID: ${{ secrets.ATLAS_ORG_ID_FOR_FEDERATION }} + 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" From 3ca16ca498398d7ee9d67e655a768753a67112cb Mon Sep 17 00:00:00 2001 From: Espen Albert Date: Thu, 6 Feb 2025 21:57:07 +0000 Subject: [PATCH 6/8] chore: Rename cleanup-test-env job and add cleanup-dev-cfntest job --- .github/workflows/cleanup-test-env.yml | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cleanup-test-env.yml b/.github/workflows/cleanup-test-env.yml index 07374aa03..f46638d68 100644 --- a/.github/workflows/cleanup-test-env.yml +++ b/.github/workflows/cleanup-test-env.yml @@ -6,7 +6,7 @@ on: - cron: "0 3 * * *" # workflow runs every day at 03:00 AM jobs: - cleanup-test-env-general: + cleanup-dev-cfn-test-github: runs-on: ubuntu-latest steps: - name: terraform-provider-mongodbatlas-checkout @@ -21,7 +21,23 @@ jobs: MONGODB_ATLAS_PRIVATE_KEY: ${{ secrets.CLOUD_DEV_PRIVATE_KEY }} MONGODB_ATLAS_ORG_ID: ${{ secrets.CLOUD_DEV_ORG_ID }} MONGODB_ATLAS_BASE_URL: ${{ vars.MONGODB_ATLAS_BASE_URL }} - MONGODB_ATLAS_CLEAN_RETRY_ATTEMPTS: "1" + 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 + ref: 133ee57735e0c8f2b22e74bbd9f8c3fdd8da2f9c + - 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: From 1169fa8a2e5fc8918f5ca63358ad42a467bed578 Mon Sep 17 00:00:00 2001 From: Espen Albert Date: Fri, 7 Feb 2025 07:22:55 +0000 Subject: [PATCH 7/8] chore: Remove old cleanup-test-env script --- scripts/cleanup-test-env.sh | 70 ------------------------------------- 1 file changed, 70 deletions(-) delete mode 100755 scripts/cleanup-test-env.sh 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 From 455c7d5630ec4ada78939ba2ff9ae7c63d41b17c Mon Sep 17 00:00:00 2001 From: Espen Albert Date: Fri, 7 Feb 2025 15:48:13 +0000 Subject: [PATCH 8/8] use default branch in checkout for cleanup --- .github/workflows/cleanup-test-env.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/cleanup-test-env.yml b/.github/workflows/cleanup-test-env.yml index f46638d68..eba3ea590 100644 --- a/.github/workflows/cleanup-test-env.yml +++ b/.github/workflows/cleanup-test-env.yml @@ -13,7 +13,6 @@ jobs: 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: @@ -29,7 +28,6 @@ jobs: uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 with: repository: mongodb/terraform-provider-mongodbatlas - ref: 133ee57735e0c8f2b22e74bbd9f8c3fdd8da2f9c - name: Cleanup cloud-dev CFN Test uses: ./.github/templates/clean-atlas-org env: @@ -45,7 +43,6 @@ jobs: 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: @@ -61,7 +58,6 @@ jobs: 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: