Skip to content

AutomationDojo/tf-module-cloudflare

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cloudflare Terraform Module

Comprehensive Terraform module for managing Cloudflare resources with modular submodules.

Features

  • 📄 Pages - Cloudflare Pages projects management
  • 🌐 DNS - DNS records management
  • 📧 Email Routing - Email forwarding and routing rules
  • 💾 R2 Storage - R2 object storage buckets management
  • 🔒 Tunnel - Cloudflare Tunnels for secure origin connectivity
  • 🔄 Automated Versioning - Semantic release integration
  • 📝 Auto-generated Docs - Terraform-docs integration

Submodules

  • pages - Cloudflare Pages projects
  • dns - DNS records management
  • email - Email routing and forwarding
  • r2 - R2 object storage buckets
  • tunnel - Cloudflare Tunnels

Quick Start

Pages Module

module "pages" {
  source = "git::git@github.com:AutomationDojo/tf-module-cloudflare.git//modules/pages?ref=v2.0.1"

  account_id = var.cloudflare_account_id

  projects = {
    my-site = {
      name              = "my-site"
      production_branch = "main"
      github_owner      = "my-org"
      github_repo       = "my-repo"
      build_command     = "npm run build"
      destination_dir   = "dist"
      custom_domain     = "example.com"
      deployment_configs = {
        production = {
          environment_variables = {
            NODE_VERSION = "22"
          }
        }
      }
    }
  }
}

DNS Module

module "dns" {
  source = "git::git@github.com:AutomationDojo/tf-module-cloudflare.git//modules/dns?ref=v2.0.1"

  zone_id = var.cloudflare_zone_id

  records = [
    {
      name    = "www"
      type    = "CNAME"
      value   = "example.com"
      ttl     = 1
      proxied = true
    }
  ]
}

Email Routing Module

module "email" {
  source = "git::git@github.com:AutomationDojo/tf-module-cloudflare.git//modules/email?ref=v2.0.1"

  zone_id    = var.cloudflare_zone_id
  account_id = var.cloudflare_account_id

  email_routing = {
    enabled = true
    addresses = [
      {
        email = "admin@example.com"
      }
    ]
    rules = [
      {
        name     = "Forward contact emails"
        enabled  = true
        priority = 0
        matchers = [
          {
            type  = "literal"
            field = "to"
            value = "contact@yourdomain.com"
          }
        ]
        actions = [
          {
            type  = "forward"
            value = ["admin@example.com"]
          }
        ]
      }
    ]
  }
}

R2 Storage Module

module "r2" {
  source = "git::git@github.com:AutomationDojo/tf-module-cloudflare.git//modules/r2?ref=v2.0.1"

  account_id = var.cloudflare_account_id

  buckets = [
    {
      name          = "my-storage-bucket"
      location      = "eeur"
      jurisdiction  = "eu"
      storage_class = "Standard"
    }
  ]
}

Tunnel Module

module "tunnel" {
  source = "git::git@github.com:AutomationDojo/tf-module-cloudflare.git//modules/tunnel?ref=v2.0.1"

  account_id = var.cloudflare_account_id

  tunnels = {
    my-tunnel = {
      name = "my-app-tunnel"
      ingress_rules = [
        {
          hostname = "app.example.com"
          service  = "http://localhost:8080"
        },
        {
          service = "http_status:404"
        }
      ]
    }
  }
}

Documentation

Full documentation is available at: https://automationdojo.github.io/tf-module-cloudflare

Local Documentation

To view the documentation locally:

# Install dependencies
pip install -r requirements.txt

# Serve documentation locally
mkdocs serve

# Open http://127.0.0.1:8000 in your browser

Examples

See examples directory for complete usage examples.

Requirements

  • Terraform >= 1.0
  • Cloudflare Provider ~> 5.0

License

MIT

Packages

 
 
 

Contributors