diff --git a/.github/actions/clean_up/README.md b/.github/actions/clean_up/README.md new file mode 100644 index 00000000..c3484cf2 --- /dev/null +++ b/.github/actions/clean_up/README.md @@ -0,0 +1 @@ +# acceptance test action diff --git a/.github/actions/clean_up/action.yaml b/.github/actions/clean_up/action.yaml new file mode 100644 index 00000000..d8ee6a86 --- /dev/null +++ b/.github/actions/clean_up/action.yaml @@ -0,0 +1,148 @@ +name: CleanUp Project Resources +description: "Acceptance Testing CleanUp" + +inputs: + project_id: + description: "STACKIT project ID for tests" + required: true + + region: + description: "STACKIT region for tests" + default: 'eu01' + required: true + + tf_resource_prefix: + description: "prefix in resource names" + default: 'tf-acc-' + required: true + + service_account_json_content: + description: "STACKIT service account JSON file contents" + required: true + default: "" + + service_account_json_content_b64: + description: "STACKIT service account JSON file contents" + required: true + default: "" + + list_only: + description: "only list resources, DO NOT delete" + required: true + default: 'true' + +outputs: + resources: + description: "resource list" + value: ${{ steps.resource_lister.outputs.resources }} + + cli-version: + description: "stackit cli version" + value: ${{ steps.stackit_version.outputs.version }} + +runs: + using: "composite" + steps: + - name: Install needed tools + shell: bash + run: | + echo "::group::apt install" + set -e + apt-get -y -qq update >apt_update.log 2>apt_update_err.log + if [ $? -ne 0 ]; then + cat apt_update.log apt_update_err.log + fi + apt-get -y -qq install curl gnupg jq >apt_get.log 2>apt_get_err.log + if [ $? -ne 0 ]; then + cat apt_get.log apt_get_err.log + fi + echo "::endgroup::" + + echo "::group::apt add source" + curl https://packages.stackit.cloud/keys/key.gpg | gpg --dearmor -o /usr/share/keyrings/stackit.gpg + echo "deb [signed-by=/usr/share/keyrings/stackit.gpg] https://packages.stackit.cloud/apt/cli stackit main" | tee -a /etc/apt/sources.list.d/stackit.list + echo "::endgroup::" + + echo "::group::apt install stackit cli" + apt-get -y -qq update >apt_update.log 2>apt_update_err.log + if [ $? -ne 0 ]; then + cat apt_update.log apt_update_err.log + fi + apt-get -y -qq install stackit >apt_get.log 2>apt_get_err.log + if [ $? -ne 0 ]; then + cat apt_get.log apt_get_err.log + fi + echo "::endgroup::" + + - name: Check stackit cli version + id: stackit_version + run: | + set -e + VERSION=$(stackit --version | grep "Version:" | cut -d " " -f 2) + echo "stackit cli version: ${VERSION}" + echo "version=${VERSION}" >> $GITHUB_OUTPUT + shell: bash + + - name: Creating service_account file from json input + if: inputs.service_account_json_content != '' + shell: bash + run: | + echo "::group::create service account file" + set -e + set -o pipefail + + echo "${{ inputs.service_account_json_content }}" > .svc_acc.json + echo "::endgroup::" + + - name: Creating service_account file from base64 json input + if: inputs.service_account_json_content_b64 != '' + shell: bash + run: | + echo "::group::create service account file" + set -e + set -o pipefail + + echo "${{ inputs.service_account_json_content_b64 }}" | base64 -d > .svc_acc.json + echo "::endgroup::" + + - name: Check service account file exists + shell: bash + run: | + set -e + if [[ ! -s .svc_acc.json ]]; then + echo "ERROR: service account file missing or empty" + exit 1 + fi + + - name: Retrieve resources + id: resource_lister + run: | + set -e + STACKIT_SERVICE_ACCOUNT_KEY_PATH="${PWD}/.svc_acc.json" + export STACKIT_SERVICE_ACCOUNT_KEY_PATH + stackit auth activate-service-account --service-account-key-path .svc_acc.json + RES_JSON=$(stackit --project-id "${{ inputs.project_id }}" beta sqlserverflex instance list --output-format json | jq -r '.[] | select(.name | startswith("${{ inputs.tf_resource_prefix }}"))') + echo "resources=$(echo $RES_JSON)" >> $GITHUB_OUTPUT + shell: bash + + - name: List resources + run: | + set -e + echo "${{ steps.resource_lister.outputs.resources }} | jq -r " + shell: bash + + - name: Delete SQL Server Flex resources + if: ${{ inputs.list_only != 'true' }} + run: | + set -e + stackit auth activate-service-account --service-account-key-path .svc_acc.json + for s in $(stackit --project-id ${{ inputs.project_id }} beta sqlserverflex instance list --output-format json | jq -r '.[] | select(.name | startswith("tf-acc-")) | .id'); do stackit -y --project-id ${{ inputs.project_id }} beta sqlserverflex instance delete $s; done + shell: bash + + - name: Delete PostgreSQL Flex resources + if: ${{ inputs.list_only != 'true' }} + run: | + set -e + stackit auth activate-service-account --service-account-key-path .svc_acc.json + for s in $(stackit --project-id ${{ inputs.project_id }} postgresflex instance list --output-format json | jq -r '.[] | select(.name | startswith("tf-acc-")) | .id'); do stackit -y --project-id ${{ inputs.project_id }} postgresflex instance delete $s; done + shell: bash diff --git a/.github/workflows/ci_new.yaml b/.github/workflows/ci_new.yaml index 9ff6a379..08239560 100644 --- a/.github/workflows/ci_new.yaml +++ b/.github/workflows/ci_new.yaml @@ -28,7 +28,7 @@ jobs: config: if: ${{ github.event_name != 'schedule' }} name: Check GoReleaser config - runs-on: ubuntu-latest + runs-on: stackit-docker steps: - name: Checkout uses: actions/checkout@v6 @@ -40,7 +40,7 @@ jobs: prepare: name: Prepare GO cache - runs-on: ubuntu-latest + runs-on: stackit-docker permissions: actions: read # Required to identify workflow run. checks: write # Required to add status summary. @@ -102,7 +102,7 @@ jobs: needs: - config - prepare - runs-on: ubuntu-latest + runs-on: stackit-docker permissions: actions: read # Required to identify workflow run. checks: write # Required to add status summary. @@ -185,7 +185,7 @@ jobs: testing: name: CI run tests - runs-on: ubuntu-latest + runs-on: stackit-docker needs: - config - prepare @@ -278,7 +278,7 @@ jobs: main: if: ${{ github.event_name != 'schedule' }} name: CI run build and linting - runs-on: ubuntu-latest + runs-on: stackit-docker needs: - config - prepare @@ -329,7 +329,7 @@ jobs: code_coverage: name: "Code coverage report" if: github.event_name == 'pull_request' # Do not run when workflow is triggered by push to main branch - runs-on: ubuntu-latest + runs-on: stackit-docker needs: - main - prepare diff --git a/.github/workflows/clean_up.yaml b/.github/workflows/clean_up.yaml new file mode 100644 index 00000000..7552f4c3 --- /dev/null +++ b/.github/workflows/clean_up.yaml @@ -0,0 +1,25 @@ +name: TF Acceptance Test CleanUp + +on: + workflow_dispatch: + inputs: + list_only: + description: "only list resources" + default: 'true' + required: true + +jobs: + clean: + name: Clean up + runs-on: stackit-docker + steps: + - name: Checkout + uses: actions/checkout@v6 + + - name: Clean + uses: ./.github/actions/clean_up + with: + project_id: ${{ vars.TF_ACC_PROJECT_ID }} + region: 'eu01' + tf_resource_prefix: 'tf-acc-' + service_account_json_content_b64: "${{ secrets.TF_ACC_SERVICE_ACCOUNT_JSON_B64 }}" diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 633953f4..0f0bcddc 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -17,7 +17,7 @@ env: jobs: config: name: Check GoReleaser config - runs-on: ubuntu-latest + runs-on: stackit-docker steps: - name: Checkout uses: actions/checkout@v6 @@ -30,7 +30,7 @@ jobs: publish: name: "Publish provider" needs: config - runs-on: ubuntu-latest + runs-on: stackit-docker permissions: actions: read # Required to identify workflow run. checks: write # Required to add status summary. diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 79547c9a..d2dec624 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -16,14 +16,14 @@ permissions: jobs: goreleaser: - runs-on: ubuntu-latest + runs-on: stackit-docker steps: - uses: actions/checkout@v6 with: # Allow goreleaser to access older tag information. fetch-depth: 0 - - uses: https://code.forgejo.org/actions/setup-go@v6 + - uses: actions/setup-go@v6 with: go-version-file: "go.mod" cache: true diff --git a/.github/workflows/renovate.yaml b/.github/workflows/renovate.yaml index c629eab0..67c33d1b 100644 --- a/.github/workflows/renovate.yaml +++ b/.github/workflows/renovate.yaml @@ -8,13 +8,13 @@ on: jobs: renovate: name: Renovate - runs-on: ubuntu-latest + runs-on: stackit-docker steps: - name: Checkout uses: actions/checkout@v6 - name: Self-hosted Renovate - uses: renovatebot/github-action@v46.1.4 + uses: renovatebot/github-action@v46.1.5 with: configurationFile: .github/renovate.json # token: ${{ secrets.RENOVATE_TOKEN }} diff --git a/.github/workflows/stale.yaml b/.github/workflows/stale.yaml index 6198123e..32b39b56 100644 --- a/.github/workflows/stale.yaml +++ b/.github/workflows/stale.yaml @@ -20,7 +20,7 @@ permissions: jobs: stale: name: "Stale" - runs-on: ubuntu-latest + runs-on: stackit-docker timeout-minutes: 10 steps: - name: "Mark old PRs as stale" diff --git a/.github/workflows/tf-acc-test.yaml b/.github/workflows/tf-acc-test.yaml index 75a35382..743a091c 100644 --- a/.github/workflows/tf-acc-test.yaml +++ b/.github/workflows/tf-acc-test.yaml @@ -23,7 +23,7 @@ on: jobs: acc_test: name: Acceptance Tests - runs-on: ubuntu-latest + runs-on: stackit-docker steps: - name: Checkout uses: actions/checkout@v6 diff --git a/stackit/internal/services/sqlserverflexbeta/sqlserverflex_acc_test.go b/stackit/internal/services/sqlserverflexbeta/sqlserverflex_acc_test.go index 0d3d8c99..77955dd5 100644 --- a/stackit/internal/services/sqlserverflexbeta/sqlserverflex_acc_test.go +++ b/stackit/internal/services/sqlserverflexbeta/sqlserverflex_acc_test.go @@ -158,7 +158,8 @@ func TestAccInstance(t *testing.T) { PreConfig: func() { t.Logf("testing: %s - %s", t.Name(), "create and verify") }, - ExpectNonEmptyPlan: true, + // empty refresh plan + ExpectNonEmptyPlan: false, Config: testutils.StringFromTemplateMust( "testdata/instance_template.gompl", exData, diff --git a/stackit/internal/wait/sqlserverflexbeta/wait.go b/stackit/internal/wait/sqlserverflexbeta/wait.go index 18168968..fb94b9dc 100644 --- a/stackit/internal/wait/sqlserverflexbeta/wait.go +++ b/stackit/internal/wait/sqlserverflexbeta/wait.go @@ -89,9 +89,15 @@ func CreateInstanceWaitHandler( return false, nil, fmt.Errorf("could not convert error to oapierror.GenericOpenAPIError: %w", err) } switch oapiErr.StatusCode { + case http.StatusOK: + return false, nil, nil case http.StatusNotFound: return false, nil, nil default: + if strings.Contains(err.Error(), "is not a valid InstanceEdition") { + tflog.Info(ctx, "API WORKAROUND", map[string]interface{}{"err": err}) + return false, nil, nil + } return false, nil, fmt.Errorf("api error: %w", err) } }