Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(terraform/cloudflare): Configure DNS Records #373

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
6 changes: 6 additions & 0 deletions terraform/cloudflare/backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
terraform {
backend "pg" {
conn_str = "postgres://terraform:[email protected]:5432/terraform?sslmode=disable"
schema_name = "cloudflare"
}
}
42 changes: 42 additions & 0 deletions terraform/cloudflare/mirceaanton.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
data "cloudflare_zone" "mirceaanton" {
name = "mirceaanton.com"
}

# =================================================================================================
# Various TXT Verifications
# =================================================================================================
resource "cloudflare_record" "mirceaanton_TXT_verifications" {
for_each = {
"Google Verification" = {
name = "@",
content = "\"${var.google_verification_mirceaanton}\""
}
}

zone_id = data.cloudflare_zone.mirceaanton.id
type = "TXT"
proxied = false

name = each.value.name
comment = "Terraform: ${each.key}"
content = each.value.content
}


# =================================================================================================
# GitHub Pages
# =================================================================================================
resource "cloudflare_record" "mirceaanton_redirects" {
for_each = {
"WWW" = { name = "www", type = "CNAME", content = "mirceanton.com" },
"Root" = { name = "@", type = "CNAME", content = "mirceanton.com" },
}

zone_id = data.cloudflare_zone.mirceaanton.id
proxied = false

type = each.value.type
name = each.value.name
content = each.value.content
comment = "Terraform: Redirect ${each.key}"
}
55 changes: 55 additions & 0 deletions terraform/cloudflare/mirceanton.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
data "cloudflare_zone" "mirceanton" {
name = "mirceanton.com"
}

# =================================================================================================
# Various TXT Verifications
# =================================================================================================
resource "cloudflare_record" "mirceanton_TXT_verifications" {
for_each = {
"Discord Verification" = {
name = "_discord.com",
content = "\"${var.discord_verification_mirceanton}\""
},
"Google Verification" = {
name = "@",
content = "\"${var.google_verification_mirceanton}\""
}
}

zone_id = data.cloudflare_zone.mirceanton.id
type = "TXT"
proxied = false

name = each.value.name
comment = "Terraform: ${each.key}"
content = each.value.content
}

# =================================================================================================
# GitHub Pages
# =================================================================================================
resource "cloudflare_record" "mirceanton_github_pages" {
for_each = {
"WWW" = { name = "www", type = "CNAME", content = "mirceanton.github.io" },

"Verification" = {
name = "_github-pages-challenge-mirceanton",
type = "TXT",
content = "\"${var.github_verification_mirceanton}\""
}

"A1" = { name = "@", type = "A", content = "185.199.111.153" }
"A2" = { name = "@", type = "A", content = "185.199.110.153" }
"A3" = { name = "@", type = "A", content = "185.199.109.153" }
"A4" = { name = "@", type = "A", content = "185.199.108.153" }
}

zone_id = data.cloudflare_zone.mirceanton.id
proxied = false

type = each.value.type
name = each.value.name
content = each.value.content
comment = "Terraform: GitHub Pages ${each.key}"
}
12 changes: 12 additions & 0 deletions terraform/cloudflare/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
terraform {
required_providers {
cloudflare = {
source = "cloudflare/cloudflare"
version = "4.49.1"
}
}
}

provider "cloudflare" {
api_token = var.cloudflare_api_token
}
36 changes: 36 additions & 0 deletions terraform/cloudflare/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# =================================================================================================
# Provider Configuration
# =================================================================================================
variable "cloudflare_api_token" {
type = string
sensitive = true
description = "API Token to authenticate against CloudFlare"
}

# =================================================================================================
# Main Domain Verifications
# =================================================================================================
variable "github_verification_mirceanton" {
type = string
sensitive = true
description = "Content for the TXT record needed for GitHub Pages verification."
}
variable "google_verification_mirceanton" {
type = string
sensitive = true
description = "Content for the TXT record needed for Google verification."
}
variable "discord_verification_mirceanton" {
type = string
sensitive = true
description = "Content for the TXT record needed for Discord verification."
}

# =================================================================================================
# Secondary Domain Verifications
# =================================================================================================
variable "google_verification_mirceaanton" {
type = string
sensitive = true
description = "Content for the TXT record needed for Google verification."
}
Loading