Skip to content

AutomationDojo/terraform-cloudflare-management

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

47 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 = "AutomationDojo/management/cloudflare//modules/pages"
  version = "2.3.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 = "AutomationDojo/management/cloudflare//modules/dns"
  version = "2.3.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 = "AutomationDojo/management/cloudflare//modules/email"
  version = "2.3.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 = "AutomationDojo/management/cloudflare//modules/r2"
  version = "2.3.1"

  account_id = var.cloudflare_account_id

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

Tunnel Module

module "tunnel" {
  source = "AutomationDojo/management/cloudflare//modules/tunnel"
  version = "2.3.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"
        }
      ]
    }
  }
}

Registry

Available on the Terraform Registry: AutomationDojo/management/cloudflare

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

License

Packages

 
 
 

Contributors