diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f6341bb..1b61a84 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,7 +38,7 @@ jobs: - name: Setup OpenTofu uses: opentofu/setup-opentofu@v2 with: - tofu_version: "1.12.6" + tofu_version_file: .opentofu-version tofu_wrapper: false # Enforce consistent formatting across all OpenTofu configurations @@ -100,7 +100,7 @@ jobs: - name: Setup TFLint uses: terraform-linters/setup-tflint@v6 with: - tflint_version: v0.64.0 + tflint_version_file: .tflint-version # Inspect all OpenTofu root modules and reusable modules. # Use the shared configuration from the repository root. @@ -112,8 +112,14 @@ jobs: # Install Checkov in an isolated Python environment. - name: Install Checkov run: | + set -euo pipefail + python3 -m venv "$RUNNER_TEMP/checkov-venv" - "$RUNNER_TEMP/checkov-venv/bin/python" -m pip install "checkov==3.4.0" + + "$RUNNER_TEMP/checkov-venv/bin/python" -m pip install \ + -r requirements-checkov.txt + + "$RUNNER_TEMP/checkov-venv/bin/checkov" --version # Scan OpenTofu configurations and GitHub Actions workflows. - name: Run Checkov diff --git a/.github/workflows/destroy.yml b/.github/workflows/destroy.yml index 6b53856..e9a78c1 100644 --- a/.github/workflows/destroy.yml +++ b/.github/workflows/destroy.yml @@ -1,4 +1,4 @@ -name: Destroy Infrastructure (TEST) +name: Destroy Infrastructure (TEST, STAGE) on: workflow_dispatch: @@ -12,12 +12,22 @@ permissions: jobs: destroy: - name: Destroy TEST + name: Destroy ${{ matrix.environment }} if: github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main' runs-on: [self-hosted, linux, assignment2] timeout-minutes: 60 - environment: TEST + strategy: + fail-fast: false + max-parallel: 1 + matrix: + include: + - environment: TEST + path: test + - environment: STAGE + path: stage + + environment: ${{ matrix.environment }} env: OS_AUTH_TYPE: v3applicationcredential @@ -28,7 +38,7 @@ jobs: OS_APPLICATION_CREDENTIAL_ID: ${{ secrets.OS_APPLICATION_CREDENTIAL_ID }} OS_APPLICATION_CREDENTIAL_SECRET: ${{ secrets.OS_APPLICATION_CREDENTIAL_SECRET }} KOPS_STATE_STORE: swift://demo-kops - TARGET_ENV: test + TARGET_ENV: ${{ matrix.path }} steps: - name: Checkout @@ -50,7 +60,10 @@ jobs: tofu version command -v jq - test "$TARGET_ENV" = "test" + case "$TARGET_ENV" in + test|stage) ;; + *) echo "::error::Unsupported environment: $TARGET_ENV"; exit 1 ;; + esac : "${OS_AUTH_URL:?Missing OS_AUTH_URL}" : "${OS_REGION_NAME:?Missing OS_REGION_NAME}" @@ -135,7 +148,7 @@ jobs: kubectl auth can-i get secrets -n iac --quiet kubectl auth can-i create leases.coordination.k8s.io -n iac --quiet - - name: Destroy TEST frontend then network + - name: Destroy frontend then network shell: bash env: TF_IN_AUTOMATION: "true" @@ -153,8 +166,8 @@ jobs: PLAN_FILE="$RUNNER_TEMP/destroy-$TARGET_ENV-$STACK.tfplan" PLAN_JSON="$RUNNER_TEMP/destroy-$TARGET_ENV-$STACK.json" - # Verify that the backend belongs to TEST. - grep -Eq "secret_suffix[[:space:]]*=[[:space:]]*\"assignment2-test-$STACK\"" \ + # Verify that the backend belongs to the selected environment. + grep -Eq "secret_suffix[[:space:]]*=[[:space:]]*\"assignment2-$TARGET_ENV-$STACK\"" \ "$STACK_DIR/providers.tf" echo "::group::Destroy $TARGET_ENV $STACK" diff --git a/.tflint-version b/.tflint-version new file mode 100644 index 0000000..367d488 --- /dev/null +++ b/.tflint-version @@ -0,0 +1 @@ +0.66.0 \ No newline at end of file diff --git a/requirements-checkov.txt b/requirements-checkov.txt new file mode 100644 index 0000000..9a65bcb --- /dev/null +++ b/requirements-checkov.txt @@ -0,0 +1 @@ +checkov==3.4.3 \ No newline at end of file