-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
d/elastic_beanstalk_hosted_zones - new data source #3208
Changes from 1 commit
770f360
38e5f87
f5c1a8c
67d8858
2dfb552
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
const unsupportedElasticBeanstalkRegion = "UnsupportedRegion" | ||
|
||
// See # http://docs.aws.amazon.com/general/latest/gr/rande.html#elasticbeanstalk_region | ||
var elasticBeanstalkHostedZoneIds = map[string]string{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor nitpick: can this map be arranged alphabetically please? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can do. My approach was based on mirroring the ordering in the AWS docs, but given the low-frequency at which updates will be required I prefer alphabetical too. |
||
"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", | ||
"cn-northwest-1": unsupportedElasticBeanstalkRegion, | ||
"eu-central-1": "Z1FRNW7UH4DEZJ", | ||
"eu-west-1": "Z2NYPWQ7DFZAZH", | ||
"eu-west-2": "Z1GKAAAUGATPF1", | ||
"eu-west-3": "Z5WN6GAYWG5OB", | ||
"sa-east-1": "Z10X7K2B4QSOFV", | ||
} | ||
|
||
func dataSourceAwsElasticBeanstalkHostedZone() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceAwsElasticBeanstalkHostedZoneRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"region": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAwsElasticBeanstalkHostedZoneRead(d *schema.ResourceData, meta interface{}) error { | ||
region := meta.(*AWSClient).region | ||
if v, ok := d.GetOk("region"); ok { | ||
region = v.(string) | ||
} | ||
|
||
zoneID := elasticBeanstalkHostedZoneIds[region] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While we appreciate the distinction between unknown and unsupported regions at the current moment this is being developed, I think we should simplify this so we do not need to maintain the difference in the future. Recently we switched the provider so AWS SDK updates with new regions will automatically validate them. We can add manually checking the Regions and Endpoints documentation for this EB Hosted Zone data source to the zoneID, ok := elasticBeanstalkHostedZoneIds[region]
if !ok {
return fmt.Errorf("Unsupported region: %s", region)
} |
||
|
||
if zoneID == unsupportedElasticBeanstalkRegion { | ||
return fmt.Errorf("Unsupported region (%q)", region) | ||
} | ||
|
||
if zoneID == "" { | ||
return fmt.Errorf("Unknown region (%q)", region) | ||
} | ||
|
||
d.SetId(zoneID) | ||
d.Set("region", region) | ||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package aws | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccAwsDataSourceElasticBeanstalkHostedZone(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccCheckAwsElasticBeanstalkHostedZoneDataSource_currentRegion, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please add a check for an unsupported region please? {
Config: testAccCheckAwsElasticBeanstalkHostedZoneDataSource_region("does-not-exist"),
ExpectError: regexp.MustCompile(`Unsupported region`),
}, |
||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.aws_elastic_beanstalk_hosted_zone.current", "id", "Z2PCDNR3VC2G1N"), | ||
), | ||
}, | ||
{ | ||
Config: testAccCheckAwsElasticBeanstalkHostedZoneDataSource_sydney, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.aws_elastic_beanstalk_hosted_zone.sydney", "id", "Z2PCDNR3VC2G1N"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const testAccCheckAwsElasticBeanstalkHostedZoneDataSource_currentRegion = ` | ||
provider "aws" { | ||
region = "ap-southeast-2" | ||
} | ||
data "aws_elastic_beanstalk_hosted_zone" "current" {} | ||
` | ||
|
||
const testAccCheckAwsElasticBeanstalkHostedZoneDataSource_sydney = ` | ||
data "aws_elastic_beanstalk_hosted_zone" "sydney" { | ||
region = "ap-southeast-2" | ||
} | ||
` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
layout: "aws" | ||
page_title: "AWS: aws_elastic_beanstalk_hosted_zone" | ||
sidebar_current: "docs-aws-datasource-elastic-beanstalk-hosted-zone" | ||
description: |- | ||
Get an elastic beanstalk hosted zone. | ||
--- | ||
|
||
# Data Source: aws_elastic_beanstalk_hosted_zone | ||
|
||
Use this data source to get the ID of an elastic beanstalk hosted zone. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you mean to use the link at the bottom? If not, could you use it please? 😄 |
||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "aws_elastic_beanstalk_hosted_zone" "current" {} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `region` - (Optional) The region you'd like the zone for. By default, fetches the current region. | ||
|
||
## Attributes Reference | ||
|
||
* `id` - The ID of the hosted zone. | ||
|
||
* `region` - The region of the hosted zone. | ||
|
||
[elastic-beanstalk-hosted-zones]: http://docs.aws.amazon.com/general/latest/gr/rande.html#elasticbeanstalk_region "AWS Elastic Beanstalk Hosted Zones documentation" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can skip something like this. 😄 I'll explain below