From 2d491f78904e5384a34aff2c7f52ad5971d655fb Mon Sep 17 00:00:00 2001 From: Thomas Cardin <49320132+ThomasCardin@users.noreply.github.com> Date: Thu, 21 Nov 2024 09:58:23 -0500 Subject: [PATCH] changed record to for loop --- terraform/main.tf | 44 +++----------------------- terraform/modules/records/main.tf | 4 ++- terraform/modules/records/variables.tf | 6 ++-- terraform/variables.tf | 22 ++----------- 4 files changed, 14 insertions(+), 62 deletions(-) diff --git a/terraform/main.tf b/terraform/main.tf index 50139d9..63c72d0 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -1,41 +1,7 @@ -module "argocd-record" { - source = "./modules/records" +module "cname-records" { + source = "./modules/records" cloudflare_zone_id = var.cloudflare_zone_id - name = "argocd" -} - -module "argocd-record" { - source = "./modules/records" - cloudflare_zone_id = var.cloudflare_zone_id - - name = "trilium" -} - -module "argocd-record" { - source = "./modules/records" - cloudflare_zone_id = var.cloudflare_zone_id - - name = "ollama" -} - -module "argocd-record" { - source = "./modules/records" - cloudflare_zone_id = var.cloudflare_zone_id - - name = "ceph" -} - -module "argocd-record" { - source = "./modules/records" - cloudflare_zone_id = var.cloudflare_zone_id - - name = "grafana" -} - -module "argocd-record" { - source = "./modules/records" - cloudflare_zone_id = var.cloudflare_zone_id - - name = "oauth2" -} + names = ["argocd", "trilium", "ollama", "ceph", "grafana", "oauth2"] + type = "CNAME" +} \ No newline at end of file diff --git a/terraform/modules/records/main.tf b/terraform/modules/records/main.tf index d170d3e..5e0bad3 100644 --- a/terraform/modules/records/main.tf +++ b/terraform/modules/records/main.tf @@ -1,7 +1,9 @@ resource "cloudflare_record" "record" { + for_each = names + zone_id = var.cloudflare_zone_id value = var.dns - name = var.name + name = each.key type = var.type ttl = 1 proxied = true diff --git a/terraform/modules/records/variables.tf b/terraform/modules/records/variables.tf index d752240..055dfee 100644 --- a/terraform/modules/records/variables.tf +++ b/terraform/modules/records/variables.tf @@ -9,9 +9,9 @@ variable "dns" { default = "ninebasetwo.net" } -variable "name" { - description = "name of record" - type = string +variable "names" { + description = "names of record" + type = list(string) } variable "type" { diff --git a/terraform/variables.tf b/terraform/variables.tf index 7564324..4ac6a56 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -1,30 +1,14 @@ variable "email" { description = "The email address for Cloudflare" - type = string + type = string } variable "cloudflare_api_key" { description = "The API key for Cloudflare" - type = string + type = string } variable "cloudflare_zone_id" { description = "The zone ID for Cloudflare" - type = string -} - -variable "dns" { - description = "value for DNS record" - type = string -} - -variable "name" { - description = "name of record" - type = string -} - -variable "type" { - description = "type of record" - type = string - default = "CNAME" + type = string } \ No newline at end of file