create CloudFlare worker to host the go vanity page

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2019-08-06 14:36:02 -04:00
parent 6dd007e48b
commit 95192fff5f
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
3 changed files with 73 additions and 0 deletions

40
main.tf Normal file
View File

@ -0,0 +1,40 @@
/* Providers ---------------------------------------------*/
provider "cloudflare" {
email = var.cloudflare_email
token = var.cloudflare_token
org_id = var.cloudflare_org_id
}
/* Locals ------------------------------------------------*/
locals {
fqdn = "${var.subdomain}.${var.domain}"
}
/* Resources ---------------------------------------------*/
/* This JS script generats the Website from list of repos */
resource "cloudflare_worker_script" "vanity" {
name = "go-status-im-vanity"
content = "${file("go_vanity.js")}"
}
/* Handle all requests to configured subdomain with the script */
resource "cloudflare_worker_route" "vanity" {
zone = var.domain
pattern = "${local.fqdn}/*"
script_name = cloudflare_worker_script.vanity.name
depends_on = [cloudflare_worker_script.vanity]
}
/* DNS Entry */
resource "cloudflare_record" "vanity" {
domain = var.domain
name = var.subdomain
type = "CNAME"
proxied = true
/* value doesn't matter, worker handles it */
value = "golang.org"
}

30
variables.tf Normal file
View File

@ -0,0 +1,30 @@
/* CloudFlare Credentials --------------------------------*/
variable "cloudflare_token" {
description = "Token for interacting with Cloudflare API."
type = string
}
variable "cloudflare_email" {
description = "Email address of Cloudflare account."
type = string
}
variable "cloudflare_org_id" {
description = "ID of the CloudFlare organization."
type = string
}
/* General -----------------------------------------------*/
variable "domain" {
description = "Domain to be used for Go packages vanity."
type = string
default = "status.im"
}
variable "subdomain" {
description = "Subdomain of the domain to be used for Go vanity."
type = string
default = "go"
}

3
versions.tf Normal file
View File

@ -0,0 +1,3 @@
terraform {
required_version = ">= 0.12"
}