Deploying Cloudflare Pages site using Terraform

Good morning all. Apologies if I am using the wrong section for this question. New user only joined moments ago. Im trying to build a pages site using terraform. My code creates the pages project and settings, however it does not trigger a deployment. I was curious if anyone had this issue previously or have I just missed a config setting? Appreciate any advice please..I must have missed something in the docs.. If it helps this is my code:
resource "cloudflare_pages_project" "blog_pages_project" {
account_id = var.cloudflare_account_id
name = "blog"
production_branch = "main"

source {
type = "github"
config {
owner = "raveygravy"
repo_name = "blog"
production_branch = "main"
pr_comments_enabled = true
deployments_enabled = true
production_deployment_enabled = true
preview_deployment_setting = "all"
preview_branch_includes = ["*"]
preview_branch_excludes = ["main", "prod"]
}
}

build_config {
build_command = "hugo --gc --minify"
destination_dir = "public"
root_dir = ""
}

deployment_configs {
preview {
environment_variables = {
HUGO_VERSION = "0.118.2"
NODE_VERSION = "18.17.1"
}
fail_open = true
}
production {
environment_variables = {
HUGO_VERSION = "0.118.2"
NODE_VERSION = "18.17.1"
}
fail_open = true
}
}
}
resource "cloudflare_pages_project" "blog_pages_project" {
account_id = var.cloudflare_account_id
name = "blog"
production_branch = "main"

source {
type = "github"
config {
owner = "raveygravy"
repo_name = "blog"
production_branch = "main"
pr_comments_enabled = true
deployments_enabled = true
production_deployment_enabled = true
preview_deployment_setting = "all"
preview_branch_includes = ["*"]
preview_branch_excludes = ["main", "prod"]
}
}

build_config {
build_command = "hugo --gc --minify"
destination_dir = "public"
root_dir = ""
}

deployment_configs {
preview {
environment_variables = {
HUGO_VERSION = "0.118.2"
NODE_VERSION = "18.17.1"
}
fail_open = true
}
production {
environment_variables = {
HUGO_VERSION = "0.118.2"
NODE_VERSION = "18.17.1"
}
fail_open = true
}
}
}
4 Replies
linuxandy
linuxandy•9mo ago
This is what Im greeted with on my cloudflare page after a successful terraform apply
linuxandy
linuxandy•9mo ago
No description
linuxandy
linuxandy•9mo ago
Ah I think Ive figured it out - will update once fully understood - apologies for the noise Solved it - for anyone else new to this - dont forget to create your github workflow for deploying 😛 This is what I ended up with as my github action workflow
name: Deploy Hugo to Cloudflare Pages

on:
push:
branches:
- main # Replace with your default branch if not 'main'

jobs:
build:
runs-on: ubuntu-latest

steps:
# Checkout the repository
- name: Checkout
uses: actions/checkout@v3

# Setup Hugo
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: "0.87.0" # Replace with your desired Hugo version

# Build the Hugo site
- name: Build
run: hugo --minify

# Deploy to Cloudflare Pages
- name: Deploy to Cloudflare Pages
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
accountId: ${{ secrets.CF_ACCOUNT_ID }}
projectName: blog # Replace with your Cloudflare project name
directory: public # Replace if your build directory is different
wranglerVersion: "3"
name: Deploy Hugo to Cloudflare Pages

on:
push:
branches:
- main # Replace with your default branch if not 'main'

jobs:
build:
runs-on: ubuntu-latest

steps:
# Checkout the repository
- name: Checkout
uses: actions/checkout@v3

# Setup Hugo
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: "0.87.0" # Replace with your desired Hugo version

# Build the Hugo site
- name: Build
run: hugo --minify

# Deploy to Cloudflare Pages
- name: Deploy to Cloudflare Pages
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
accountId: ${{ secrets.CF_ACCOUNT_ID }}
projectName: blog # Replace with your Cloudflare project name
directory: public # Replace if your build directory is different
wranglerVersion: "3"
Cyb3r-Jak3
Cyb3r-Jak3•9mo ago
Do you want to deploy with direct upload or use the pages build in CI? When you create a project with terraform, it was start building on the next commit