fix(dns): add Cloudflare DNS terraform to restore up2cloud.tech#7
Conversation
The domain is down because its DNS records are missing. This adds a Terraform config that: - Registers up2cloud.tech and www.up2cloud.tech as custom domains on the existing Cloudflare Pages project (up2cloud-tech) - Creates proxied CNAME records pointing both to up2cloud-tech.pages.dev via Cloudflare CNAME flattening To apply: cd terraform/cloudflare && terraform init && terraform apply Required vars: cloudflare_api_token, cloudflare_zone_id
Deploying up2cloud-tech with
|
| Latest commit: |
ab09777
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://33a6c73e.up2cloud-tech.pages.dev |
| Branch Preview URL: | https://fix-cloudflare-dns-records.up2cloud-tech.pages.dev |
There was a problem hiding this comment.
Code Review
This pull request introduces a Terraform configuration to set up Cloudflare Pages custom domains and DNS records. However, a critical issue was identified: defining explicit cloudflare_record resources for the apex and www domains will cause terraform apply to fail with a duplicate record error, as Cloudflare Pages automatically creates these DNS records when associating a custom domain.
| # --------------------------------------------------------------------------- | ||
| # DNS records | ||
| # Cloudflare CNAME flattening makes a CNAME work for the apex domain. | ||
| # proxied = true routes traffic through Cloudflare edge (DDoS, WAF, cache). | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| resource "cloudflare_record" "apex_cname" { | ||
| zone_id = var.cloudflare_zone_id | ||
| name = "@" | ||
| type = "CNAME" | ||
| value = "${local.project_name}.pages.dev" | ||
| proxied = true | ||
| comment = "Cloudflare Pages — up2cloud.tech" | ||
|
|
||
| depends_on = [cloudflare_pages_domain.apex] | ||
| } | ||
|
|
||
| resource "cloudflare_record" "www_cname" { | ||
| zone_id = var.cloudflare_zone_id | ||
| name = "www" | ||
| type = "CNAME" | ||
| value = "${local.project_name}.pages.dev" | ||
| proxied = true | ||
| comment = "Cloudflare Pages — www.up2cloud.tech" | ||
|
|
||
| depends_on = [cloudflare_pages_domain.www] | ||
| } |
There was a problem hiding this comment.
When you associate a custom domain with a Cloudflare Pages project using cloudflare_pages_domain, Cloudflare automatically creates the corresponding DNS CNAME records in your zone (if the zone is managed in the same Cloudflare account).
Because of this automatic behavior, defining explicit cloudflare_record resources for the apex and www domains will cause terraform apply to fail with a Code: 81057 (An identical DNS record already exists) error when it tries to create them.
To resolve this, you should remove the explicit cloudflare_record resources entirely. Cloudflare Pages will handle the DNS record creation and proxying automatically.
Root cause
up2cloud.techhas no DNS records. The domain resolves to NXDOMAIN, so browsers can't reach the site even though:up2cloud.github.io→up2cloud.tech)up2cloud-techis live atup2cloud-tech.pages.devWhat this PR adds
terraform/cloudflare/main.tf— registers the custom domain on Cloudflare Pages and creates the missing DNS records:up2cloud.techup2cloud-tech.pages.devwww.up2cloud.techup2cloud-tech.pages.devCI now validates both Terraform directories.
How to apply (fixes the outage immediately)
After apply, DNS propagates within seconds (Cloudflare) and the site will be back up.
Test plan
terraform applywith valid credentialshttps://up2cloud.techloads the sitehttps://www.up2cloud.techredirects to apexhttps://claude.ai/code/session_01AdacpfB74AC4xNZQeej9fw
Generated by Claude Code