Browse Source

feat: Manage DNS records via Cloudflare Provider

pull/3/head
Karan Sharma 11 months ago
parent
commit
63de919c1d
  1. 127
      floyd/terraform/cloudflare/records.tf
  2. 3
      floyd/terraform/cloudflare/variables.tf
  3. 8
      floyd/terraform/cloudflare/versions.tf
  4. 5
      floyd/terraform/cloudflare/zones.tf
  5. 3
      floyd/terraform/env.sample
  6. 11
      floyd/terraform/main.tf
  7. 8
      floyd/terraform/providers.tf
  8. 4
      floyd/terraform/variables.tf
  9. 3
      floyd/terraform/versions.tf

127
floyd/terraform/cloudflare/records.tf

@ -0,0 +1,127 @@
resource "cloudflare_record" "firefly" {
zone_id = cloudflare_zone.mrkaran_dev.id
name = "firefly"
type = "A"
ttl = "1"
proxied = "false"
value = var.ips["tailscale_floyd"]
}
resource "cloudflare_record" "floyd" {
zone_id = cloudflare_zone.mrkaran_dev.id
name = "floyd"
type = "A"
ttl = "1"
proxied = "false"
value = var.ips["floating"]
}
resource "cloudflare_record" "git" {
zone_id = cloudflare_zone.mrkaran_dev.id
name = "git"
type = "A"
ttl = "1"
proxied = "true"
value = var.ips["public"]
}
resource "cloudflare_record" "grafana" {
zone_id = cloudflare_zone.mrkaran_dev.id
name = "grafana"
type = "A"
ttl = "1"
proxied = "false"
value = var.ips["tailscale_floyd"]
}
resource "cloudflare_record" "pi" {
zone_id = cloudflare_zone.mrkaran_dev.id
name = "pi"
type = "A"
ttl = "1"
proxied = "false"
value = var.ips["tailscale_floyd"]
}
resource "cloudflare_record" "koadings" {
zone_id = cloudflare_zone.mrkaran_dev.id
name = "koadings"
type = "A"
ttl = "1"
proxied = "false"
value = var.ips["tailscale_floyd"]
}
resource "cloudflare_record" "shynet" {
zone_id = cloudflare_zone.mrkaran_dev.id
name = "shynet"
type = "A"
ttl = "1"
proxied = "true"
value = var.ips["public"]
}
resource "cloudflare_record" "sync" {
zone_id = cloudflare_zone.mrkaran_dev.id
name = "sync"
type = "A"
ttl = "1"
proxied = "false"
value = var.ips["tailscale_floyd"]
}
resource "cloudflare_record" "tailscale" {
zone_id = cloudflare_zone.mrkaran_dev.id
name = "tailscale"
type = "A"
ttl = "1"
proxied = "false"
value = var.ips["tailscale_floyd"]
}
resource "cloudflare_record" "wiki" {
zone_id = cloudflare_zone.mrkaran_dev.id
name = "wiki"
type = "A"
ttl = "1"
proxied = "false"
value = var.ips["tailscale_floyd"]
}

3
floyd/terraform/cloudflare/variables.tf

@ -0,0 +1,3 @@
variable "ips" {
type = map
}

8
floyd/terraform/cloudflare/versions.tf

@ -0,0 +1,8 @@
terraform {
required_providers {
cloudflare = {
source = "cloudflare/cloudflare"
}
}
required_version = ">= 0.13"
}

5
floyd/terraform/cloudflare/zones.tf

@ -0,0 +1,5 @@
resource "cloudflare_zone" "mrkaran_dev" {
zone = "mrkaran.dev"
plan = "free"
}

3
floyd/terraform/env.sample

@ -1,6 +1,7 @@
DIGITALOCEAN_TOKEN=
CLOUDFLARE_API_TOKEN=
TF_VAR_bookstack_mariadb_password=
TF_VAR_cloudflare_api_token=
TF_VAR_cloudflare_caddy_api_token=
TF_VAR_firefly_postgres_password=
TF_VAR_firefly_app_key=
TF_VAR_gitea_secret_key=

11
floyd/terraform/main.tf

@ -49,7 +49,7 @@ module "bookstack" {
module "caddy" {
source = "./caddy"
ips = var.ips
cloudflare_api_token = var.cloudflare_api_token
cloudflare_api_token = var.cloudflare_caddy_api_token
monitoring_network = module.monitoring.monitoring_network
providers = {
docker = docker.floyd
@ -87,6 +87,15 @@ module "syncthing" {
}
}
module "cloudflare" {
source = "./cloudflare"
ips = var.ips
providers = {
cloudflare = cloudflare
}
}
### UNUSED SERVICES ###
### GOODBYE ###

8
floyd/terraform/providers.tf

@ -11,5 +11,11 @@ provider "docker" {
provider "digitalocean" {
# You need to set this in your .bashrc
# export DIGITALOCEAN_TOKEN="Your API TOKEN"
#
}
# Configure the Cloudflare provider.
provider "cloudflare" {
version = "~> 2.0"
# You need to set this in your .bashrc
# export CLOUDFLARE_API_TOKEN="Your API TOKEN"
}

4
floyd/terraform/variables.tf

@ -16,9 +16,9 @@ variable "bookstack_mariadb_password" {
description = "Password for Bookstack MariaDB server"
}
variable "cloudflare_api_token" {
variable "cloudflare_caddy_api_token" {
type = string
description = "API key to edit DNS zones in Cloudflare"
description = "API key to edit DNS zones in Cloudflare used by Caddy"
}
variable "firefly_postgres_password" {

3
floyd/terraform/versions.tf

@ -6,6 +6,9 @@ terraform {
docker = {
source = "terraform-providers/docker"
}
cloudflare = {
source = "cloudflare/cloudflare"
}
}
required_version = ">= 0.13"
}

Loading…
Cancel
Save