terraform_pages_issue

TF_LOG=debug environment variable so if you on Linux then just TF_LOG=debug terraform apply
8 Replies
MrElephantt
MrElephantt17mo ago
Well I finally realized I had accidentally set the start date on the token and not the end date. So that fixed 1 issue but I'm still getting an error.
Error: error creating cloudflare pages project "cranberry": received internal server error response (HTTP 500), please try again later

│ with cloudflare_pages_project.cranberry,
│ on cloudflare.tf line 10, in resource "cloudflare_pages_project" "cranberry":
│ 10: resource "cloudflare_pages_project" "cranberry" {
Error: error creating cloudflare pages project "cranberry": received internal server error response (HTTP 500), please try again later

│ with cloudflare_pages_project.cranberry,
│ on cloudflare.tf line 10, in resource "cloudflare_pages_project" "cranberry":
│ 10: resource "cloudflare_pages_project" "cranberry" {
Cyb3r-Jak3
Cyb3r-Jak3OP17mo ago
If you run with the log variable it will show the actual response with any error information
MrElephantt
MrElephantt17mo ago
@Cyb3r-Jok3 here is the log, it looks like it was repeating over and over again so I trimmed it up, hopefully not too much. https://gist.github.com/snaveevans/68db6118a2c8c9f4cb88fe9a407871a9
Gist
cloudflare_pages_terraform_error.txt
GitHub Gist: instantly share code, notes, and snippets.
Cyb3r-Jak3
Cyb3r-Jak3OP17mo ago
That's weird. Just check with one of my projects and it works fine. If you are able to open a support ticket then you should, else you can make an issue on the GitHub repo
MrElephantt
MrElephantt17mo ago
Do you have an example of a simple pages terraform file that worked for you? I tried another project and I'm still getting 500s. I guess maybe this will could help as well to determine if my terraform file is bad.
terraform {
required_providers {
cloudflare = {
source = "cloudflare/cloudflare"
version = "~> 4.0"
}
}
}

resource "cloudflare_pages_project" "resume" {
account_id = "[redacted]"
name = "resume-site"
production_branch = "main"

build_config {
build_command = "npm run build"
destination_dir = "public"
}

source {
type = "github"
config {
owner = "[redacted]
repo_name = "resume"
production_branch = "main"
pr_comments_enabled = true
deployments_enabled = true
production_deployment_enabled = true
preview_branch_excludes = ["main"]
}
}
}
terraform {
required_providers {
cloudflare = {
source = "cloudflare/cloudflare"
version = "~> 4.0"
}
}
}

resource "cloudflare_pages_project" "resume" {
account_id = "[redacted]"
name = "resume-site"
production_branch = "main"

build_config {
build_command = "npm run build"
destination_dir = "public"
}

source {
type = "github"
config {
owner = "[redacted]
repo_name = "resume"
production_branch = "main"
pr_comments_enabled = true
deployments_enabled = true
production_deployment_enabled = true
preview_branch_excludes = ["main"]
}
}
}
Cyb3r-Jak3
Cyb3r-Jak3OP17mo ago
resource "cloudflare_pages_project" "cloudflare-utils" {
account_id = var.account_id
name = "cloudflare-utils"
production_branch = "main"
build_config {
build_command = "pip install -r requirements.txt && mkdocs build"
destination_dir = "site"
root_dir = "documentation"
web_analytics_tag = "<>"
web_analytics_token = "<>"
}
source {
type = "github"
config {
owner = "Cyb3r-Jak3"
repo_name = "cloudflare-utils"
production_branch = "main"
preview_branch_includes = ["*"]
}
}
deployment_configs {
preview {
always_use_latest_compatibility_date = true
fail_open = false
environment_variables = {
PYTHON_VERSION = "3.10"
}
placement {}
}
production {
fail_open = false
environment_variables = {
PYTHON_VERSION = "3.8"
}
placement {}
}
}
}
resource "cloudflare_pages_project" "cloudflare-utils" {
account_id = var.account_id
name = "cloudflare-utils"
production_branch = "main"
build_config {
build_command = "pip install -r requirements.txt && mkdocs build"
destination_dir = "site"
root_dir = "documentation"
web_analytics_tag = "<>"
web_analytics_token = "<>"
}
source {
type = "github"
config {
owner = "Cyb3r-Jak3"
repo_name = "cloudflare-utils"
production_branch = "main"
preview_branch_includes = ["*"]
}
}
deployment_configs {
preview {
always_use_latest_compatibility_date = true
fail_open = false
environment_variables = {
PYTHON_VERSION = "3.10"
}
placement {}
}
production {
fail_open = false
environment_variables = {
PYTHON_VERSION = "3.8"
}
placement {}
}
}
}
Oh maybe try adding
deployment_configs {
production {
placement {}
}
preview {
placement {}
}
}
deployment_configs {
production {
placement {}
}
preview {
placement {}
}
}
to your resource.
MrElephantt
MrElephantt17mo ago
@Cyb3r-Jok3 Sorry took me a bit to come around and test it but it works! The only changes that were made were the following
build_config {
...
-root_dir="" # removed
}
...
source {
...
+pr_comments_enabled = true
+deployments_enabled = true
}
build_config {
...
-root_dir="" # removed
}
...
source {
...
+pr_comments_enabled = true
+deployments_enabled = true
}
Seems minor but obviously something in there did it. But 2 additional questions that maybe you could help answer. 1. The deployment wasn't created automatically, is there something that can be done to enable them automatically? 2. How do you configure account_id via account_id = var.account_id? I'd like to configure mine in another way other than plain text, I have yet to commit it because I don't want it in there.
Cyb3r-Jak3
Cyb3r-Jak3OP17mo ago
1. I don't believe the first deploy happens automatically but any after the project has been created should work 2. Using terraform variables https://developer.hashicorp.com/terraform/language/values/variables
Want results from more Discord servers?
Add your server