How to get the load balancer when creating an EB, so I can point my domain to it using an A-record

120 views
Skip to first unread message

gitted

unread,
Feb 14, 2017, 12:07:40 PM2/14/17
to Terraform
I am creating a Elastic Beanstalk application, and I will have multiple environments (STAGING, PROD).

For my production environment, I want to point my domain name to the Load balancer that my EB creates.  How can I do this?

So my DNS would be like:

resource "aws_route53_record" "naked" {
  zone_id = "${aws_route53_zone.main.zone_id}"
  name    = "naked"
  type    = "A"

  alias {
    name                   = "${aws_route53_record.www.name}"
    zone_id                = "${aws_route53_record.www.zone_id}"
    evaluate_target_health = true
  }
}

resource "aws_route53_record" "www" {
  zone_id = "${aws_route53_zone.main.zone_id}"
  name    = "www"
  type    = "A"

  alias {
    name                   = ""
    zone_id                = ""
    evaluate_target_health = true
  }
}


But for the "www" record, how do I get the Load balancer name/zone_id from the EB?

resource "aws_elastic_beanstalk_application" "app_web" {
  name = "EB-${var.prefix}-${var.app_web}"
}

resource "aws_elastic_beanstalk_environment" "app-prod" {
.....
}

gitted

unread,
Feb 14, 2017, 5:23:32 PM2/14/17
to Terraform
I am trying this, but it isn't working:

alias {
    name                   = "${aws_elastic_beanstalk_environment.myapp.load_balancers[0].id}"
    zone_id                = "${aws_elastic_beanstalk_environment.myapp.load_balancers[0].zone_id}"
    evaluate_target_health = true
  }

Error:

 parse error at 1:67: expected "}" but found "."

Stuart Robertson

unread,
Feb 15, 2017, 5:08:07 PM2/15/17
to Terraform
Here is how I do it:

resource "aws_route53_record" "beanstalk-env-dns-record" {
  zone_id = "${var.route_53_zone_id}"
  name = "${var.domain_name}"
  type = "CNAME"
  ttl = "300"
  records = ["${aws_elastic_beanstalk_environment.prod.cname}"]
Reply all
Reply to author
Forward
0 new messages