Skip to content

Commit

Permalink
feat(modules/zone): complex variable types
Browse files Browse the repository at this point in the history
  • Loading branch information
kevcube committed Sep 16, 2024
1 parent 3261326 commit b6a907b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
14 changes: 7 additions & 7 deletions modules/zones/main.tf
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
resource "aws_route53_zone" "this" {
for_each = { for k, v in var.zones : k => v if var.create }

name = lookup(each.value, "domain_name", each.key)
comment = lookup(each.value, "comment", null)
force_destroy = lookup(each.value, "force_destroy", false)
name = coalesce(each.value.domain_name, each.key)
comment = each.value.comment
force_destroy = each.value.force_destroy

delegation_set_id = lookup(each.value, "delegation_set_id", null)
delegation_set_id = each.value.delegation_set_id

dynamic "vpc" {
for_each = try(tolist(lookup(each.value, "vpc", [])), [lookup(each.value, "vpc", {})])
for_each = each.value.vpc

content {
vpc_id = vpc.value.vpc_id
vpc_region = lookup(vpc.value, "vpc_region", null)
vpc_region = vpc.value.vpc_region
}
}

tags = merge(
lookup(each.value, "tags", {}),
each.value.tags,
var.tags
)
}
16 changes: 13 additions & 3 deletions modules/zones/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,22 @@ variable "create" {

variable "zones" {
description = "Map of Route53 zone parameters"
type = any
default = {}
type = map(object({
domain_name = optional(string)
comment = optional(string)
force_destroy = optional(bool)
delegation_set_id = optional(string)
vpc = optional(list(object({
vpc_id = string
vpc_region = optional(string)
})))
tags = optional(map(string), {})
}))
default = {}
}

variable "tags" {
description = "Tags added to all zones. Will take precedence over tags from the 'zones' variable"
type = map(any)
type = map(string)
default = {}
}

0 comments on commit b6a907b

Please sign in to comment.