So I’m trying to follow what this poster is doing. The module I’m using is this.
My code works fine if I only have one type of record in the YAML file, if I try to mix a normal record along with an alias then the code blows up. I noticed in the other discussion, there was mention of using a splat. Correct me if I’m wrong but I believe the module I’m using takes this into consideration, it’s just the for loop I’m using may not satisfy the code within the module.
Error: Inconsistent conditional result types
on .terraform/modules/records/modules/records/main.tf line 15, in resource "aws_route53_record" "this":
15: for_each = var.create && (var.zone_id != null || var.zone_name != null) ? local.recordsets : tomap({})
|----------------
| local.recordsets is object with 2 attributes
The true result value has the wrong type: object is required.
Working YAML file
zone_id: Z12345678
records:
- name: route53-alias1.example.com
type: A
alias:
name: abc.com
zone_id: Z12345678
- name: route53-alias.example.com
type: A
alias:
name: alias.elb.amazon.com
zone_id: Z12345678
Non-working YAML file
zone_id: Z12345678
records:
- name: route53-alias1.example.com
type: A
records:
- 192.168.0.1
- name: route53-alias.example.com
type: A
alias:
name: alias.elb.amazon.com
zone_id: Z12345678
main.tf
locals {
zone_data_raw = yamldecode(file("${path.module}//zone_data.yaml"))
zone_data = {
zone_id = local.zone_data_raw.zone_id
records = [for r in local.zone_data_raw.records : {
name = r.name
type = r.type
ttl = lookup(r, "ttl", null)
alias = lookup(r, "alias", {})
records = lookup(r, "records", null)
}]
}
}
module "records" {
source = "terraform-aws-modules/route53/aws//modules/records"
zone_id = local.zone_data_raw.zone_id
private_zone = true
records = local.zone_data.records
}