Skip to content

Commit

Permalink
feat: cloudflare pages project tf module
Browse files Browse the repository at this point in the history
  • Loading branch information
zackpollard committed Nov 28, 2024
1 parent 1cd1d85 commit 9472a16
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tf/shared/modules/cloudflare-pages-project/config.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = "~> 1.7"

required_providers {
cloudflare = {
source = "cloudflare/cloudflare"
version = "~>4.46"
}
}
}
5 changes: 5 additions & 0 deletions tf/shared/modules/cloudflare-pages-project/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
locals {
app_name = replace(var.app_name, "/[^a-zA-Z\\d]/", "-")
dashed_domain = replace(var.domain, "/[^a-zA-Z\\d]/", "-")
sanitised_project_name = "${local.app_name}-${local.dashed_domain}-${var.env}"
}
7 changes: 7 additions & 0 deletions tf/shared/modules/cloudflare-pages-project/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "pages_project" {
value = {
id = cloudflare_pages_project.project.id
name = cloudflare_pages_project.project.name
subdomain = cloudflare_pages_project.project.subdomain
}
}
33 changes: 33 additions & 0 deletions tf/shared/modules/cloudflare-pages-project/project.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
resource "cloudflare_pages_project" "project" {
account_id = var.cloudflare_account_id
name = local.sanitised_project_name
production_branch = "prod"

build_config {
web_analytics_tag = cloudflare_web_analytics_site.analytics.site_tag
web_analytics_token = cloudflare_web_analytics_site.analytics.site_token
}

lifecycle {
ignore_changes = [
build_config["build_caching"],
]
}
}

data "cloudflare_zone" "zone" {
name = var.domain
}

module "domain" {
source = "../domain"

app_name = var.app_name
env = var.env
}

resource "cloudflare_web_analytics_site" "analytics" {
account_id = var.cloudflare_account_id
host = module.domain.fqdn
auto_install = false
}
3 changes: 3 additions & 0 deletions tf/shared/modules/cloudflare-pages-project/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
provider "cloudflare" {
api_token = var.cloudflare_api_token
}
8 changes: 8 additions & 0 deletions tf/shared/modules/cloudflare-pages-project/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
variable "cloudflare_api_token" {}
variable "cloudflare_account_id" {}

variable "env" {}
variable "app_name" {}
variable "domain" {
default = "immich.app"
}

0 comments on commit 9472a16

Please sign in to comment.