I am trying to associate the Elastic Beanstalk with Route 53 using Alias record. However the zone_id of Elastic Beanastalk is not available. My current work around is to use CNAME and point to Elastic beanstalk cname attribute instead.
Terraform v0.6.16
If this issue appears to affect multiple resources, it may be an issue with Terraform's core, so please mention this.
N/A
N/A
N/A
Export _zone_id_ attribute so it can be used with Route 53 Alias record
No _zone_id_ attribute
Please list the steps required to reproduce the issue, for example:
alias {
name = "${aws_elastic_beanstalk_environment.api.cname}"
zone_id = "${aws_elastic_beanstalk_environment.api.zone_id}"
evaluate_target_health = false
}
Error running plan: 1 error(s) occurred:
* Resource 'aws_elastic_beanstalk_environment.api' does not have attribute 'zone_id' for variable 'aws_elastic_beanstalk_environment.api.zone_id'
N/A
N/A
@apavamontri There is no zone id of elastic beanstalk afaik, you have to use cname only.
@optimisticanshul But I found it in the Route 53 console. Screenshot attached


@apavamontri There are dedicated zone id's per region for Elastic Beanstalk. I'm not sure if it makes sense to export this as a part of the resource.
http://docs.aws.amazon.com/general/latest/gr/rande.html#elasticbeanstalk_region
@dharrisio Ahhh.. I shall use that in the default variable and try to that in Route 53 then. Thank you!
Ran into this issue today, thanks for the help @dharrisio and @apavamontri !
Edit: Just use aws_elastic_beanstalk_hosted_zone, thanks @bflad
No need to do this anymore.
variable "aws_elasticbeanstalk_zones" {
# https://docs.aws.amazon.com/general/latest/gr/rande.html#elasticbeanstalk_region
# Correct @ 30/04/18
type = "map"
default {
"us-east-2" = "Z14LCN19Q5QHIC"
"us-east-1" = "Z117KPS5GTRQ2G"
"us-west-1" = "Z1LQECGX5PH1X"
"us-west-2" = "Z38NKT9BP95V3O"
"ca-central-1" = "ZJFCZL7SSZB5I"
"ap-south-1" = "Z18NTBI3Y7N9TZ"
"ap-northeast-2" = "Z3JE5OI70TWKCP"
"ap-northeast-3" = "ZNE5GEY1TIAGY"
"ap-southeast-1" = "Z16FZ9L249IFLT"
"ap-southeast-2" = "Z2PCDNR3VC2G1N"
"ap-northeast-1" = "Z1R25G3KIG2GBW"
"eu-central-1" = "Z1FRNW7UH4DEZJ"
"eu-west-1" = "Z2NYPWQ7DFZAZH"
"eu-west-2" = "Z1GKAAAUGATPF1"
"eu-west-3" = "Z5WN6GAYWG5OB"
"sa-east-1" = "Z10X7K2B4QSOFV"
}
}
# example use:
resource "aws_route53_record" "my_domain" {
zone_id = "${data.aws_route53_zone.my_domain.zone_id}"
name = "subdomain.${data.aws_route53_zone.my_domain.name}"
type = "A"
alias {
name = "${aws_elastic_beanstalk_environment.my_elastic_beanstalk.cname}"
zone_id = "${var.aws_elasticbeanstalk_zones["eu-west-2"]}"
evaluate_target_health = false
}
}
data "aws_route53_zone" "my_domain" {
name = "example.com"
}
There is also a data source available for this: aws_elastic_beanstalk_hosted_zone
data "aws_elastic_beanstalk_hosted_zone" "current" {}
output "eb_hosted_zone_id" {
value = "${data.aws_elastic_beanstalk_hosted_zone.current.id}"
}
This was previously released in version 1.9.0 of the AWS provider and has been available in all releases since. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.
thanks a lot to @bflad I used successfully your piece of code in this way
resource "aws_elastic_beanstalk_environment" "myapp" {
/* a lot of code here */
}
data "aws_elastic_beanstalk_hosted_zone" "current" {}
resource "aws_route53_record" "app" {
zone_id = "${var.my_zone_id}"
name = "app"
type = "A"
alias {
name = "${lower(aws_elastic_beanstalk_environment.myapp.cname)}"
zone_id = "${data.aws_elastic_beanstalk_hosted_zone.current.id}"
evaluate_target_health = false
}
}
Glad it worked! I'm going to lock this thread to encourage any new bug reports/enhancements surrounding this to be submitted into the AWS provider repository. 馃憤
Most helpful comment
There is also a data source available for this:
aws_elastic_beanstalk_hosted_zoneThis was previously released in version 1.9.0 of the AWS provider and has been available in all releases since. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.