Skip to content

Commit

Permalink
changed record to for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasCardin committed Nov 21, 2024
1 parent 435ddfa commit 2d491f7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 62 deletions.
44 changes: 5 additions & 39 deletions terraform/main.tf
Original file line number Diff line number Diff line change
@@ -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"
}
4 changes: 3 additions & 1 deletion terraform/modules/records/main.tf
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions terraform/modules/records/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
22 changes: 3 additions & 19 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 2d491f7

Please sign in to comment.