Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export Elastic Beanstalk's Zone ID for Route 53 Alias record #7071

Closed
apavamontri opened this issue Jun 8, 2016 · 8 comments
Closed

Export Elastic Beanstalk's Zone ID for Route 53 Alias record #7071

apavamontri opened this issue Jun 8, 2016 · 8 comments

Comments

@apavamontri
Copy link

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 Version

Terraform v0.6.16

Affected Resource(s)

  • aws_elastic_beanstalk_environment
  • aws_route53_record

If this issue appears to affect multiple resources, it may be an issue with Terraform's core, so please mention this.

Terraform Configuration Files

N/A

Debug Output

N/A

Panic Output

N/A

Expected Behavior

Export zone_id attribute so it can be used with Route 53 Alias record

Actual Behavior

No zone_id attribute

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. Create elastic beanstalk application
  2. Create elastic beanstalk environment
  3. Create Route53 alias record with:
alias {
    name = "${aws_elastic_beanstalk_environment.api.cname}"
    zone_id = "${aws_elastic_beanstalk_environment.api.zone_id}"
    evaluate_target_health = false
  }

Error Message

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'

Important Factoids

N/A

References

N/A

@sharmaansh21
Copy link
Contributor

@apavamontri There is no zone id of elastic beanstalk afaik, you have to use cname only.

@apavamontri
Copy link
Author

@optimisticanshul But I found it in the Route 53 console. Screenshot attached

elasticbeanstalk-zone_id-1

elasticbeanstalk-zone_id-2

@dharrisio
Copy link
Contributor

@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

@apavamontri
Copy link
Author

@dharrisio Ahhh.. I shall use that in the default variable and try to that in Route 53 then. Thank you!

@BookOfGreg
Copy link

BookOfGreg commented Apr 30, 2018

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"
}

@bflad
Copy link
Contributor

bflad commented Apr 30, 2018

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.

@giuseppeborgese
Copy link

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
  }
}

@bflad
Copy link
Contributor

bflad commented Aug 2, 2018

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. 👍

@hashicorp hashicorp locked as resolved and limited conversation to collaborators Aug 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants