-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8221 from TimeIncOSS/f-aws-elb-accid
aws: Add elb_account_id data source
- Loading branch information
Showing
5 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
// See http://docs.aws.amazon.com/elasticloadbalancing/latest/classic/enable-access-logs.html#attach-bucket-policy | ||
var elbAccountIdPerRegionMap = map[string]string{ | ||
"ap-northeast-1": "582318560864", | ||
"ap-northeast-2": "600734575887", | ||
"ap-south-1": "718504428378", | ||
"ap-southeast-1": "114774131450", | ||
"ap-southeast-2": "783225319266", | ||
"cn-north-1": "638102146993", | ||
"eu-central-1": "054676820928", | ||
"eu-west-1": "156460612806", | ||
"sa-east-1": "507241528517", | ||
"us-east-1": "127311923021", | ||
"us-gov-west": "048591011584", | ||
"us-west-1": "027434742980", | ||
"us-west-2": "797873946194", | ||
} | ||
|
||
func dataSourceAwsElbAccountId() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceAwsElbAccountIdRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"region": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAwsElbAccountIdRead(d *schema.ResourceData, meta interface{}) error { | ||
region := meta.(*AWSClient).region | ||
if v, ok := d.GetOk("region"); ok { | ||
region = v.(string) | ||
} | ||
|
||
if accid, ok := elbAccountIdPerRegionMap[region]; ok { | ||
d.SetId(accid) | ||
return nil | ||
} | ||
|
||
return fmt.Errorf("Unknown region (%q)", region) | ||
} |
38 changes: 38 additions & 0 deletions
38
builtin/providers/aws/data_source_aws_elb_account_id_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package aws | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccAWSElbAccountId_basic(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccCheckAwsElbAccountIdConfig, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.aws_elb_account_id.main", "id", "797873946194"), | ||
), | ||
}, | ||
resource.TestStep{ | ||
Config: testAccCheckAwsElbAccountIdExplicitRegionConfig, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.aws_elb_account_id.regional", "id", "156460612806"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const testAccCheckAwsElbAccountIdConfig = ` | ||
data "aws_elb_account_id" "main" { } | ||
` | ||
|
||
const testAccCheckAwsElbAccountIdExplicitRegionConfig = ` | ||
data "aws_elb_account_id" "regional" { | ||
region = "eu-west-1" | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
website/source/docs/providers/aws/d/elb_account_id.html.markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
--- | ||
layout: "aws" | ||
page_title: "AWS: aws_elb_account_id" | ||
sidebar_current: "docs-aws-datasource-elb-account-id" | ||
description: |- | ||
Get AWS Elastic Load Balancing Account ID | ||
--- | ||
|
||
# aws\_elb\_account\_id | ||
|
||
Use this data source to get the Account ID of the [AWS Elastic Load Balancing Account](http://docs.aws.amazon.com/elasticloadbalancing/latest/classic/enable-access-logs.html#attach-bucket-policy) | ||
in a given region for the purpose of whitelisting in S3 bucket policy. | ||
|
||
## Example Usage | ||
|
||
``` | ||
data "aws_elb_account_id" "main" { } | ||
resource "aws_s3_bucket" "elb_logs" { | ||
bucket = "my-elb-tf-test-bucket" | ||
acl = "private" | ||
policy = <<POLICY | ||
{ | ||
"Id": "Policy", | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Action": [ | ||
"s3:PutObject" | ||
], | ||
"Effect": "Allow", | ||
"Resource": "arn:aws:s3:::my-elb-tf-test-bucket/AWSLogs/*", | ||
"Principal": { | ||
"AWS": [ | ||
"${data.aws_elb_account_id.main.id}" | ||
] | ||
} | ||
} | ||
] | ||
} | ||
POLICY | ||
} | ||
resource "aws_elb" "bar" { | ||
name = "my-foobar-terraform-elb" | ||
availability_zones = ["us-west-2a"] | ||
access_logs { | ||
bucket = "${aws_s3_bucket.elb_logs.bucket}" | ||
interval = 5 | ||
} | ||
listener { | ||
instance_port = 8000 | ||
instance_protocol = "http" | ||
lb_port = 80 | ||
lb_protocol = "http" | ||
} | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `region` - (Optional) Region of a given AWS ELB Account | ||
|
||
|
||
## Attributes Reference | ||
|
||
* `id` - Account ID |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters