Reusing a previously deleted custom domain on Cloudflare Pages
While I've decided that I probably don't need Cloudflare in my life, I still had a draft in the backlog related to the service.
If you've been following along over the years, you know this site has had many forms and many hosting providers. Assuming my memory is holding up, here's all the stops along the way:
- PHP (self-hosted)
- WordPress (self-hosted)
- PHP (self-hosted)
- Tumblr (yes, I did that)
- Jekyll + GitHub Pages
- WordPress (managed)
- Jekyll + GitHub Pages
- Jeykll + GitLab Pages
- Jekyll + Cloudflare Pages
- WordPress (managed)
- Eleventy + Cloudflare Pages
- Eleventy (self-hosted)
Clearly I hate myself.
What's old is new again
Having been through the ringer a few times over, there have been some reruns. One in particular was Cloudflare Pages.
After migrating back to WordPress, I pointed my domain to WP Engine. After that, I deleted my Cloudflare Pages. At the time it seemed like I had done everything correctly.
Then I got a bug up my ass and decided to ditch WordPress yet again.
Enjoying the Cloudflare Pages experience previously, and not yet at the point where I wanted to declare my technical independence, I figured I could just set things up again.
This was mostly true, as I setup the site, and got things deploying to the default URL they give you. Then when I tried to setup my custom domain, I was greeted with an error about my domain already being configured.
Da fuck.
Deletion of the soft kind
I had very much deleted my site from Cloudflare Pages. I assumed in doing so that I had deleted everything, including the custom domain I had configured.
My DNS entries sure didn't give any indication that I had anything configured. No Cloudflare UI that I had checked had my domain listed.
After some research, it seems my assumptions were wrong. Turns out I had deleted the Cloudflare Pages site, but not the domain attached to the project. The project had an invisible death grip on the domain.
To make matters worse, this isn't evident from the UI and you have to get dirty with the API to resolve matters.
Delete the project, reuse the domain
Sure enough, when I had checked the API, the domain was in fact still listed. In an attempt to think like the engineer that thought this was okay, I came up with the rational conclusion that most sane people wouldn't rubber band their hosting providers. Thus, the likelihood of a return, attempting to use the same domain, would be low.
I probably would have made the same conclusion, and cut the same corner to make sure the project was delivered on time. I'd to think there's a backlog item that covers this over at Cloudflare.
So having identified the issue, I still needed to remedy things. Fortunately, it was a quick fix, but does require that you configure an API key with the correct permissions.
After you have your API key setup, you can just run the following, making sure to setup the variables or replace them with your values:
curl https://api.cloudflare.com/client/v4/accounts/$CF_ACCOUNT_ID/pages/projects/$CF_PROJECT_ID/domains/$CF_DOMAIN \
-X DELETE \
-H "X-Auth-Email: $CF_EMAIL" \
-H "X-Auth-Key: $CF_API_KEY"
Once that's been run successfully, you can add the custom domain again.