From d827a7059e236c9013d596d24fc495d2d0214feb Mon Sep 17 00:00:00 2001 From: lyc8503 Date: Sun, 19 May 2024 21:35:01 +0800 Subject: [PATCH] fix #13: create worker subdomain during deployment --- .github/workflows/deploy.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index dc44bc1..542397c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -40,6 +40,28 @@ jobs: env: CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} + + # This is a temporary workaround to fix issue #13 + # On a new Cloudflare account, the terraform apply will fail with `workers.api.error.subdomain_required` + # This may be due to the account not having a worker subdomain yet, so we create a dummy worker and then delete it. + # Cloudflare should allocate a worker subdomain after this. + # https://github.com/cloudflare/terraform-provider-cloudflare/issues/3304 + - name: Create worker subdomain + id: create_dummy_worker + run: | + curl --request PUT --fail-with-body \ + --url https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/workers/scripts/dummy-ib4db6ntj5csdef3 \ + --header 'Authorization: Bearer '$CLOUDFLARE_API_TOKEN \ + --header 'Content-Type: application/javascript' \ + --data 'addEventListener('\''fetch'\'', (event) => event.respondWith(new Response('\''OK'\'')))'\ + + curl --request DELETE --fail-with-body \ + --url https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/workers/scripts/dummy-ib4db6ntj5csdef3 \ + --header 'Authorization: Bearer '$CLOUDFLARE_API_TOKEN \ + --header 'Content-Type: application/json' + env: + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} + CLOUDFLARE_ACCOUNT_ID: ${{ steps.fetch_account_id.outputs.account_id }} - name: Install packages run: |