Thank you @apparentlymart,
approach you shown me, with some small corrections
domain => [
instead of
domain => {
is ok for my case. I just use eip referenced by name creating from a list like this
pub_ips = ["pubip1", "pubip2", "pubip3", "pubip4", ...]
Please, if you can, explane me better what you mean with your initial sentence I cannot understand completely
... because if you want to use arbitrary Terraform language expressions
then you need to write your value in the Terraform language, not externally
as an input variable.
And also what about contraint you pointed to (I cannot see as I can choose different pubip using target_key for each record), see code below:
(local variable)
local {
route53_hz_records_local = {
for domain, records in var.route53_hz_records : domain => [
for record in records : {
name = record.name
type = record.type
ttl = record.ttl
records = [
module.eip.eip[record.target_key].public_ip
]
}
]
}
}
(variables declaration)
variable "pub_ips" {
type = list(string)
default = []
}
variable "route53_hz_records" {
type = map(set(object({
name = string
type = string
ttl = number
target_key = string
})))
default = {}
}
(variables definition)
pub_ips = ["pubip1", "pubip2", "pubip3", "pubip4"]
route53_hz_records = {
"domain1.example.com" = [
{
"name" = "www"
"type" = "A"
"ttl" = 3600
"target_key" = "pubip1"
},
{
"name" = "service1"
"type" = "A"
"ttl" = 3600
"target_key" = "pubip3"
},
{
"name" = "service2"
"type" = "A"
"ttl" = 3600
"target_key" = "pubip4"
},
]
}
(eip)
module "eip" {
source = "..."
...
}
(records)
module "route53_hz_root_records" {
source = "..."
for_each = {
for domain, records in local.route53_hz_records_local :
domain => records
}
zone_name = each.key
records = each.value
}