From fe38bebbd5fc16a72d90596c342318bf17538ce9 Mon Sep 17 00:00:00 2001 From: michael Date: Wed, 23 Oct 2024 00:22:32 -0400 Subject: [PATCH] cloudflare dns --- .gitignore | 3 ++ terraform/cloudflare/main.tf | 42 ++++++++++++++++++++ terraform/cloudflare/secrets.auto.example | 3 ++ terraform/cloudflare/variable_definitions.tf | 21 ++++++++++ terraform/cloudflare/variables.auto.tfvars | 6 +++ 5 files changed, 75 insertions(+) create mode 100644 terraform/cloudflare/main.tf create mode 100644 terraform/cloudflare/secrets.auto.example create mode 100644 terraform/cloudflare/variable_definitions.tf create mode 100644 terraform/cloudflare/variables.auto.tfvars diff --git a/.gitignore b/.gitignore index 81fce7e..2f0e0e2 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,9 @@ ansible/collections/** # Terraform lock file **/.terraform.lock.hcl +# Terraform secrets file +**/secrets.auto.tfvars + # Crash log files crash.log crash.*.log diff --git a/terraform/cloudflare/main.tf b/terraform/cloudflare/main.tf new file mode 100644 index 0000000..2e3cca9 --- /dev/null +++ b/terraform/cloudflare/main.tf @@ -0,0 +1,42 @@ +# terraform file to create dns resource in cloudflare +terraform { + required_version = ">= 1.8.0" + required_providers { + cloudflare = { + source = "cloudflare/cloudflare" + version = "~> 4.44" + } + } + backend "local" { + path = "/home/michael/Nextcloud/Backups/tfstate/cloudflare.tfstate" + } +} + +provider "cloudflare" { + api_token = var.api_token +} + +data "cloudflare_accounts" "default" { + name = var.account_name +} + +resource "cloudflare_zone" "balsillie_net" { + account_id = data.cloudflare_accounts.default[0].id + zone = "balsillie.net" + paused = false + plan = "free" + type = "full" +} + +resource "cloudflare_dns_zone_dnssec" "balsillie_net" { + zone_id = cloudflare_zone.balsillie_net.id +} + +resource "cloudflare_dns_record" "example_record" { + zone_id = cloudflare_zone.balsillie_net.id + proxied = false + type = "A" + ttl = 60 + name = "@" + content = "5.161.254.39" +} \ No newline at end of file diff --git a/terraform/cloudflare/secrets.auto.example b/terraform/cloudflare/secrets.auto.example new file mode 100644 index 0000000..cd595e2 --- /dev/null +++ b/terraform/cloudflare/secrets.auto.example @@ -0,0 +1,3 @@ +# Rename this file to "secrets.auto.tfvars" + +api_token = "CHANGE ME" \ No newline at end of file diff --git a/terraform/cloudflare/variable_definitions.tf b/terraform/cloudflare/variable_definitions.tf new file mode 100644 index 0000000..95bb10d --- /dev/null +++ b/terraform/cloudflare/variable_definitions.tf @@ -0,0 +1,21 @@ +variable "api_token" { + description = "Cloudflare account API token" + type = string + default = "" + sensitive = true +} + +variable "account_name" { + description = "Cloudflare account name" + type = string + default = "" +} + +variable "a_records" { + description = "DNS A records to create" + type = list(object({ + name = string + content = string + })) + default = [] +} \ No newline at end of file diff --git a/terraform/cloudflare/variables.auto.tfvars b/terraform/cloudflare/variables.auto.tfvars new file mode 100644 index 0000000..e6f793d --- /dev/null +++ b/terraform/cloudflare/variables.auto.tfvars @@ -0,0 +1,6 @@ +account_name = "balsillie" + +a_records = [ + {name = "@", content = ""}, + {name = "www", content = ""} +] \ No newline at end of file