I ma trying to deploy AWS SES Service through Terraform. Here is my main.tf
block.
I am using existing domain and zone_id in route 53
resource "aws_ses_domain_identity" "domain_identity" {
domain = var.my_domain #domain already exists
}
resource "aws_ses_domain_dkim" "dkim_domain" {
domain = aws_ses_domain_identity.domain_identity.domain
}
resource "aws_route53_record" "ses_verification" {
depends_on = [ aws_ses_domain_dkim.dkim_domain ]
zone_id = var.zone_id #Existing zone_id
name = "_amazonaws.qa.com"
type = "TXT"
ttl = 600
records = [aws_ses_domain_identity.domain_identity.verification_token]
}
resource "aws_route53_record" "ses_dkim_record" {
depends_on = [ aws_ses_domain_dkim.dkim_domain ]
count = length(aws_ses_domain_dkim.dkim_domain.dkim_tokens)
zone_id = var.zone_id
name = element(aws_ses_domain_dkim.dkim_domain.dkim_tokens, count.index)
type = "CNAME"
ttl = 600
records = [concat(element(aws_ses_domain_dkim.dkim_domain.dkim_tokens, count.index),".amazonses.com")]
}
While running Terraform apply, I am getting below error:
╷
│ Error: Invalid count argument
│
│ on ses/main.tf line 30, in resource "aws_route53_record" "ses_dkim_record":
│ 30: count = length(aws_ses_domain_dkim.dkim_domain.dkim_tokens)
│
│ The "count" value depends on resource attributes that cannot be determined
│ until apply, so Terraform cannot predict how many instances will be
│ created. To work around this, use the -target argument to first apply only
│ the resources that the count depends on.
╵
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: command terminated with exit code 1
I am deploying SES for the first time so not sure where it is failing.
Thank You
1
According to the documentation, “count
can’t refer to any resource attributes that aren’t known until after a configuration is applied”. So you have to apply the aws_ses_domain_dkim.dkim_domain
resource before you can refer to it in a count
and make this file a two-stage apply.
You could use the method mentioned in the error “To work around this, use the -target argument to first apply only the resources that the count depends on” or comment out the ses_dkim_record
on your first apply.
Looking at the for_each
documentation may provide an alternative solution.