Issue with multiple values for MX (and possibly other TXT) record type for bare domain resulting in mixed types in map??
Opened this issue · 6 comments
Description
Unless I'm doing something wrong, multiple values for MX (and possibly other TXT-style) record types are not supported and throw a Terraform error due to mixed map types in the local.recordsets
value... I hope I'm missing something particularly obvious...
Reproduction
Code Snippet to Reproduce
module "server_com_records" {
source = "terraform-aws-modules/route53/aws//modules/records"
version = "~> 2.0"
zone_name = keys(module.root_zones.route53_zone_zone_id)[0]
records = [
{
name = "" # Apex A Record (Works)
type = "A"
ttl = 3600
records = [
"1.3.3.7",
"1.2.3.4"
]
},
{
name = "" # Apex MX Record (Sometimes works with 1 records)
type = "MX"
ttl = 300
records = [
"5 mx1.mailserver.com"
]
},
{
name = "" # Apex MX Record (Doesn't Work with >= 2 records)
type = "MX"
ttl = 300
records = [
"5 mx1.mailserver.com",
"5 mx2.mailserver.com"
]
},
]
depends_on = [module.root_zones]
}
Expected behavior
MX record is created with 2 records
Actual behavior
│ Error: Inconsistent conditional result types
│
│ on .terraform/modules/server_com_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|3) attributes
│
│ The true result value has the wrong type: element types must all match for conversion to map.
Terminal Output Screenshot(s)
✗ terraform --version
Terraform v0.15.4
on darwin_amd64
+ provider registry.terraform.io/hashicorp/aws v3.42.0
Additional context
It sometimes doesn't work even with 1 record when multiple bare records are present...
I manually added output to print local.recordsets
in the .terraform/modules/server_com_records/modules/records/outputs.tf
and printed it in terraform console
:
> module.server_com_records
{
"route53_record_fqdn" = {
" A" = "server.com"
}
"route53_record_name" = {
" A" = "server.com"
}
"route53_recordsets" = {
" A" = {
"name" = ""
"records" = [
"1.3.3.7",
"1.2.3.4",
]
"ttl" = 3600
"type" = "A"
}
" MX" = {
"name" = ""
"records" = [
"5 mx1.mailserver.com",
"5 mx2.mailserver.com",
]
"ttl" = 300
"type" = "MX"
}
}
}
Just as a heads up, I downgraded to Terraform 0.14.11 and seems to be AOK -- I'll run more testing today, but it very well could be a possible bug in 0.15.x...
It can be is a bug in 0.15.
I saw similar strange behavior with this line in step-functions module earlier today when using 0.15 but not with 0.14
Yeah, I ran this in many variations this past week and it seems the issue is present in 0.15 .... will stick to 0.14 for now.
Sorry for the bother!
No problems. Thanks for the confirmation!
I noticed that the module works when replacing tomap({})
with {}
in [line 15( https://github.com/terraform-aws-modules/terraform-aws-route53/blob/736dcb71c44729d2b62ade80747e8de9abf369f8/modules/records/main.tf#L15) of the records module.
I don't know if that could be a valid workaround until the bug is fixed in terraform (btw, did you create an issue? I couldn't find one)?
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.