Home

Awesome

Terraform-Cloudflare-Maintenance

Terraform module to create a responsive Maintenance Page using Cloudflare Workers.

The Cloudflare script intercepts all incoming requests and checks if the request is coming from an IP that is in the whitelist or if the request path matches a whitelisted path. If the request is not whitelisted, it returns a maintenance page.

The module can be used through Terraform's registry.

Preview

Preview

You can preview the full page here.

Usage

A detailed explanation of the implementation can be found here.

Export cloudflare credentials

TF_VAR_cloudflare_email=xxx
TF_VAR_cloudflare_api_key=xxx
TF_VAR_cloudflare_account_id=xxx

If using a token, make sure it has all the necessary permissions

Simple maintenance page with your logo, fav icon, company name, font and email with multiple routes on the same domain:

module "hodovi_cc_maintenance" {
  source          = "git::git@github.com:adinhodovic/terraform-cloudflare-maintenance.git?ref=0.7.0"
  cloudflare_zone = "hodovi.cc"
  patterns        = ["hodovi.cc/maintenance/*", "hodovi.cc/example/*"]
  company_name    = "HoneyLogic"
  email           = "support@honeylogic.io"
  statuspage_url  = "https://status.hodovi.cc"
  font            = "Poppins"
  logo_url        = "https://s3.eu-west-1.amazonaws.com/honeylogic.io/media/images/Honeylogic-blue.original.png"
  favicon_url     = "https://s3.eu-west-1.amazonaws.com/honeylogic.io/media/images/Honeylogic_-_icon.original.height-80.png"
}

Use the enabled flag to enable/disable the Cloudflare route when maintenance starts/ends:

module "hodovi_cc_maintenance" {
  source          = "git::git@github.com:adinhodovic/terraform-cloudflare-maintenance.git?ref=0.7.0"
  enabled         = false
  cloudflare_zone = "hodovi.cc"
  patterns        = ["hodovi.cc/maintenance/*"]
  company_name    = "HoneyLogic"
  email           = "support@honeylogic.io"
  statuspage_url  = "null"
  font            = "Poppins"
  logo_url        = "https://s3.eu-west-1.amazonaws.com/honeylogic.io/media/images/Honeylogic-blue.original.png"
  favicon_url     = "https://s3.eu-west-1.amazonaws.com/honeylogic.io/media/images/Honeylogic_-_icon.original.height-80.png"
}

Example can be found in examples/root-example.

<!-- BEGIN_TF_DOCS -->

Requirements

NameVersion
terraform>= 0.13
cloudflare>= 3.31.0

Providers

NameVersion
cloudflare>= 3.31.0

Resources

NameType
cloudflare_worker_route.thisresource
cloudflare_worker_script.thisresource
cloudflare_zones.thisdata source

Inputs

NameDescriptionTypeDefaultRequired
account_idCloudflare account idstringnullno
cloudflare_zonen/astringn/ayes
company_namen/astringn/ayes
emailThe email address to used for support inquiries.stringn/ayes
enabledFlag to create/delete the worker route.booltrueno
favicon_urlThe favicon to be displayed. Defaults to a maintenance icon from the web.string"https://cdn1.iconfinder.com/data/icons/ios-11-glyphs/30/maintenance-512.png"no
fontGoogle font that should be used.string"Poppins"no
logo_urlThe logo to be displayed.stringn/ayes
patternsThe DNS pattern list to deploy the maintenance page to.list(string)n/ayes
statuspage_urlThe status page address to get updated information.string"null"no
whitelist_ipsThe IPs that are whitelisted to bypass the maintenance page.string"null"no
whitelist_pathThe paths that are whitelisted defined with a regex expression to bypass the maintenance page.string"null"no
<!-- END_TF_DOCS -->

Notes

Get fonts from Google fonts. Ensure that the Google Font is identical in casing e.g "PT Sans" can't be "Pt Sans" otherwise it'll fail to fetch the font.