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

[Feature Request] Provide beanstalk zoneids lookup. Either as data source or resource attribute. #2952

Closed
beanaroo opened this issue Jan 11, 2018 · 8 comments
Labels
new-data-source Introduces a new data source. service/elasticbeanstalk Issues and PRs that pertain to the elasticbeanstalk service.
Milestone

Comments

@beanaroo
Copy link
Contributor

Terraform Version

v0.11.1

Affected Resource(s)

  • aws_elastic_beanstalk_environment
  • aws_route53_record

Terraform Configuration Files

variable "beanstalk_zoneids" {
  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-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"
  }
}

resource "aws_route53_record" "example_api_elb_alias_a" {
  provider = "aws.invenco"
  zone_id  = "${data.aws_route53_zone.example_api_elb.zone_id}"
  name     = "api.example.com"
  type     = "A"

  alias {
    name                   = "${aws_elastic_beanstalk_environment.example_api.cname}"
    zone_id                = "${var.beanstalk_zoneids["us-east-1"]}"
    evaluate_target_health = false
  }
}

Description

I find myself repeating the above variable in many places, across multiple environments and stacks. The zone_id data source doesn't work because they are not owned by the account(s). They are static and it would be great if we could look them up programmatically.

Maybe a data source? Or even better, as an attribute of an environment?

References

@apparentlymart apparentlymart added the enhancement Requests to existing resources that expand the functionality or scope. label Jan 18, 2018
@apparentlymart
Copy link
Contributor

Hi @beanaroo!

Since this table of zone ids is included in the AWS documentation, it seems reasonable to encode it into Terraform, though of course this would (just as with the other similar tables we have hard-coded in the provider) require a provider upgrade each time a new region is added to the table.

As you say, the usual way we've exposed this sort of thing in the past is via a combination of a data source for ad-hoc lookups and a zone_id attribute on the relevant resource to allow for a more readable expression in the common case where you want the zone associated with a particular environment.

In this case, the latter might look like this:

resource "aws_route53_record" "example_api_elb_alias_a" {
  provider = "aws.invenco"
  zone_id  = "${data.aws_route53_zone.example_api_elb.zone_id}"
  name     = "api.example.com"
  type     = "A"

  alias {
    name                   = "${aws_elastic_beanstalk_environment.example_api.cname}"
    zone_id                = "${aws_elastic_beanstalk_environment.example_api.zone_id}"
    evaluate_target_health = false
  }
}

The Terraform team at HashiCorp probably won't be able to work on this in the near future, but we'd be happy to review a pull request if you or someone else has the time and motivation to implement it. There are some existing zone id lookup tables for other services that could serve as examples.

Alternatively, if others would also like to see this implemented I'd encourage adding a 👍 upvote reaction to the original issue comment (not to this comment), which we use as one of the inputs to prioritize work for the Terraform team.

@beanaroo
Copy link
Contributor Author

Thanks, @apparentlymart! That makes sense. Unfortunately the data source doesn't work because those zones are outside of the account and the API throws a permission error.

I do think hardcoding this in terraform based on aws documentation isn't sustainable and it would be better if AWS exposed these programmatically somehow.

I'll close this until there is a better option for sourcing the zone ids

@bflad
Copy link
Contributor

bflad commented Feb 5, 2018

Hi @beanaroo! I'm actually going to reopen this temporarily since there was a PR (#3208) submitted to resolve it. It saves everyone from maintaining their own variables or hardcoding themselves, which is a better user experience.

I think for now we should allow this as a hardcoded region-ID mapping in the provider, even if it is not ideally automated, as we already maintain some other mappings like ELB hosted zone IDs. We already have this maintenance burden and luckily AWS is not spinning up new regions too often. 😄

@bflad bflad reopened this Feb 5, 2018
@bflad bflad added new-data-source Introduces a new data source. service/elasticbeanstalk Issues and PRs that pertain to the elasticbeanstalk service. and removed enhancement Requests to existing resources that expand the functionality or scope. labels Feb 5, 2018
@bflad bflad added this to the v1.9.0 milestone Feb 5, 2018
@bflad
Copy link
Contributor

bflad commented Feb 5, 2018

The new datasource aws_elastic_beanstalk_hosted_zone has been merged into master and will be released in v1.9.0 of the AWS provider, expected at the end of the week. Happy Terraform'ing! 🎉

@bflad bflad closed this as completed Feb 5, 2018
@bflad
Copy link
Contributor

bflad commented Feb 9, 2018

This has been released in terraform-provider-aws version 1.9.0. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@beanaroo
Copy link
Contributor Author

beanaroo commented Mar 1, 2018

Fantastic! Thank you @sjauld and @bflad !!! We have updated our providers and this is a very convenient addition.

@Vadim-Zenin
Copy link

Vadim-Zenin commented Feb 28, 2019

@bflad , could you please check/add eu-north-1 please?
#7763

@ghost
Copy link

ghost commented Mar 31, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
new-data-source Introduces a new data source. service/elasticbeanstalk Issues and PRs that pertain to the elasticbeanstalk service.
Projects
None yet
Development

No branches or pull requests

4 participants