Skip to content

robbyoconnor/terraform-cloudflare-github-pages-dns

Repository files navigation

Terraform Module to create the DNS entries for GitHub Pages.

This was developed primarily for myself, but I am releasing it in the hopes it helps someone else. This works only with Cloudflare DNS.

This will create A and AAAA records for the apex of your domain name. If you do not want this, you can set use_apex to false in the module block. You should use CNAMEs in that case by specifying them in the gh_pages_cnames set.

Note: This does not create the repository.

This can be found on the Terraform Registry.

Example usage

terraform {
  required_providers {
    cloudflare = {
      source  = "cloudflare/cloudflare"
      version = "~> 3.0"
    }
  }
}

provider "cloudflare" {
  api_token = var.cf_api_token
}

module "example" {
  source          = "robbyoconnor/github-pages-dns/cloudflare"
  version         = "1.0.0"
  gh_username     = "robbyoconnor"                  # optional, if you enable cnames, it will use this to generate username.github.io
  gh_pages_cnames = ["www", "anotherone", "thrice"] # optional
  cf_zone_id      = var.cf_zone_id
  cf_api_token    = var.cf_api_token
}

Requirements

Name Version
cloudflare ~> 3.0

Providers

Name Version
cloudflare 3.1.0

Modules

No modules.

Resources

Name Type
cloudflare_record.apex_a_records resource
cloudflare_record.apex_aaaa resource
cloudflare_record.cnames resource

Inputs

Name Description Type Default Required
cf_api_token This is the API token. You can obtain it at https://dash.cloudflare.com/profile/api-tokens string n/a yes
cf_zone_id The ID of the cloudflare zone string n/a yes
gh_pages_cnames CNAMEs for your github pages. This can span multiple repositories. set(string) [] no
gh_pages_ipv4 IPv4 records for GitHub pages list(string)
[
"185.199.108.153",
"185.199.109.153",
"185.199.110.153",
"185.199.111.153"
]
no
gh_pages_ipv6 IPv6 records for GitHub pages list(string)
[
"2606:50c0:8000::153",
"2606:50c0:8001::153",
"2606:50c0:8002::153",
"2606:50c0:8003::153"
]
no
gh_username Your github username (or org name). Required if CNAMEs are specified. string "" no
use_apex Sometimes people don't use the apex and rather use a subdomain, in that case, a CNAME is fine. bool true no

Outputs

No outputs.