Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ MaroonRides infrastructure: one Contabo VPS (`prod-server`) running NixOS and a
single-node k3s cluster (`prod`) reconciled by Flux.

- `tofu/`: Contabo instance + NixOS install, `maroonrides.app` DNS records,
the `web.maroonrides.app` Pages project and its GitHub deploy secrets,
Cloudflare tokens, R2 backup bucket, Tailscale policy, Flux webhooks
- `nixos/`: host configuration
- `kubernetes/`: Flux tree. `apps/base` is the platform, `apps/prod` the apps
Expand All @@ -16,12 +17,12 @@ State is `infra.tfstate` in the `maroonrides-tofu-state` R2 bucket. `tofu/.env`

Item `tofu-credentials` in the `Maroon Rides Deployment` 1Password vault:

| Section | Fields | Permissions |
| ------------ | ---------------------------------------------------- | ---------------------------------------------------------------------------- |
| `cloudflare` | `api_token` | Account: API Tokens Edit, Workers R2 Storage Edit; zone: Zone Read, DNS Edit |
| `github` | `token` | `Maroon-Rides/infra`: Webhooks read/write |
| `contabo` | `client_id`, `client_secret`, `username`, `password` | Contabo API |
| `tailscale` | `client_id`, `client_secret` | OAuth client, all scopes |
| Section | Fields | Permissions |
| ------------ | ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| `cloudflare` | `api_token` | Account: API Tokens Edit, Workers R2 Storage Edit, Cloudflare Pages Edit; zone: Zone Read, DNS Edit |
| `github` | `token` | `Maroon-Rides/infra`: Webhooks read/write; `Maroon-Rides/MaroonRides`: Secrets and Variables read/write |
| `contabo` | `client_id`, `client_secret`, `username`, `password` | Contabo API |
| `tailscale` | `client_id`, `client_secret` | OAuth client, all scopes |

## Bring-up

Expand Down
10 changes: 10 additions & 0 deletions tofu/config/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,13 @@ module "flux_webhooks" {
domain = local.domain
vault_uuid = local.vault_uuid
}

module "pages_web" {
source = "../modules/pages-web"

account_id = local.account_id
zone_id = local.zone_id
domain = local.domain
project_name = "maroonrides-web"
repository = "MaroonRides"
}
60 changes: 60 additions & 0 deletions tofu/modules/pages-web/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
locals {
hostname = "web.${var.domain}"
}

// Deployments are direct uploads from GitHub Actions, so the project has no git source.
resource "cloudflare_pages_project" "web" {
account_id = var.account_id
name = var.project_name
production_branch = "main"
}

resource "cloudflare_pages_domain" "web" {
account_id = var.account_id
project_name = cloudflare_pages_project.web.name
name = local.hostname
}

resource "cloudflare_dns_record" "web" {
zone_id = var.zone_id
name = local.hostname
type = "CNAME"
content = cloudflare_pages_project.web.subdomain
proxied = true
ttl = 1
}

resource "cloudflare_account_token" "pages_deploy" {
account_id = var.account_id
name = "maroonrides pages deploy"

policies = [
{
effect = "allow"
permission_groups = [
{ id = "8d28297797f24fb8a0c332fe0866ec89" }, # Pages Write
]
resources = jsonencode({
"com.cloudflare.api.account.${var.account_id}" = "*"
})
}
]
}

resource "github_actions_secret" "cloudflare_api_token" {
repository = var.repository
secret_name = "CLOUDFLARE_API_TOKEN"
plaintext_value = cloudflare_account_token.pages_deploy.value
}

resource "github_actions_variable" "cloudflare_account_id" {
repository = var.repository
variable_name = "CLOUDFLARE_ACCOUNT_ID"
value = var.account_id
}

resource "github_actions_variable" "pages_project" {
repository = var.repository
variable_name = "CLOUDFLARE_PAGES_PROJECT"
value = cloudflare_pages_project.web.name
}
19 changes: 19 additions & 0 deletions tofu/modules/pages-web/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
variable "account_id" {
type = string
}

variable "zone_id" {
type = string
}

variable "domain" {
type = string
}

variable "project_name" {
type = string
}

variable "repository" {
type = string
}
10 changes: 10 additions & 0 deletions tofu/modules/pages-web/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_providers {
cloudflare = {
source = "cloudflare/cloudflare"
}
github = {
source = "integrations/github"
}
}
}