I'm trying to make an SSL cert with terraform for multiple DNS records, following the docs here: https://www.terraform.io/docs/providers/aws/r/acm_certificate_validation.html
For the Route 53 records is gives this example:
resource "aws_route53_record" "cert_validation" {
name = "${aws_acm_certificate.cert.domain_validation_options.0.resource_record_name}"
type = "${aws_acm_certificate.cert.domain_validation_options.0.resource_record_type}"
zone_id = "${data.aws_route53_zone.zone.id}"
records = ["${aws_acm_certificate.cert.domain_validation_options.0.resource_record_value}"]
ttl = 60
}
Where the 0
in the name and type refer to the single DNS entry they've provided. If I add several subject_alternative_names
to the aws_acm_certificate
and add several manual aws_route53_record
with the 0
replaced by 1
2
etc, it works the way I want.
My question is, can I do this in one go using Terraform's count
. I've tried these two things with count = 5
:
name = "${aws_acm_certificate.cert.domain_validation_options.*.resource_record_name[count.index]}"
This complains that it's getting a string and not a list
name = "${aws_acm_certificate.cert.domain_validation_options.count.index.resource_record_name}"
This gives all of them the same name, and it's just "5".
Edit:
Setup:
resource "aws_route53_record" "cert_validation" {
count = 5
name = "${aws_acm_certificate.cert.domain_validation_options.*.resource_record_name[count.index]}"
type = "CNAME"
zone_id = "myzoneid"
records = ["${aws_acm_certificate.cert.domain_validation_options.*.resource_record_value[count.index]}"]
ttl = 60
}
Errors:
* aws_route53_record.cert_validation: 5 error(s) occurred:
* aws_route53_record.cert_validation[4]: At column 95, line 1: invalid index operation into non-indexable type: TypeString in:
${aws_acm_certificate.cert.domain_validation_options.*.resource_record_value[count.index]}
* aws_route53_record.cert_validation[2]: At column 94, line 1: invalid index operation into non-indexable type: TypeString in:
${aws_acm_certificate.cert.domain_validation_options.*.resource_record_name[count.index]}
* aws_route53_record.cert_validation[3]: At column 94, line 1: invalid index operation into non-indexable type: TypeString in:
${aws_acm_certificate.cert.domain_validation_options.*.resource_record_name[count.index]}
* aws_route53_record.cert_validation[0]: At column 95, line 1: invalid index operation into non-indexable type: TypeString in:
${aws_acm_certificate.cert.domain_validation_options.*.resource_record_value[count.index]}
* aws_route53_record.cert_validation[1]: At column 94, line 1: invalid index operation into non-indexable type: TypeString in:
${aws_acm_certificate.cert.domain_validation_options.*.resource_record_name[count.index]}
count = 5
) berecords = ...
? Considering thename
parameter takes a string and therecords
parameter takes a list that would make sense, especially with your second attempt below that.name
actuallyrecords
takes a list so you need to wrap it in square brackets to coerce it into a list.name
takes a string so you don't need to do anything. Can you post the actual error you are getting?