-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
provider/aws: DataSource for RedShift Account ID #8224
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
builtin/providers/aws/data_source_aws_redshift_service_account.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,48 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
// See http://docs.aws.amazon.com/redshift/latest/mgmt/db-auditing.html#db-auditing-enable-logging | ||
var redshiftServiceAccountPerRegionMap = map[string]string{ | ||
"us-east-1": "193672423079", | ||
"us-west-1": "262260360010", | ||
"us-west-2": "902366379725", | ||
"ap-south-1": "865932855811", | ||
"ap-northeast-2": "760740231472", | ||
"ap-southeast-1": "361669875840", | ||
"ap-southeast-2": "762762565011", | ||
"ap-northeast-1": "404641285394", | ||
"eu-central-1": "053454850223", | ||
"eu-west-1": "210876761215", | ||
} | ||
|
||
func dataSourceAwsRedshiftServiceAccount() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceAwsRedshiftServiceAccountRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"region": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAwsRedshiftServiceAccountRead(d *schema.ResourceData, meta interface{}) error { | ||
region := meta.(*AWSClient).region | ||
if v, ok := d.GetOk("region"); ok { | ||
region = v.(string) | ||
} | ||
|
||
if accid, ok := redshiftServiceAccountPerRegionMap[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_redshift_service_account_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 TestAccAWSRedshiftServiceAccount_basic(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccCheckAwsRedshiftServiceAccountConfig, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.aws_redshift_service_account.main", "id", "902366379725"), | ||
), | ||
}, | ||
resource.TestStep{ | ||
Config: testAccCheckAwsRedshiftServiceAccountExplicitRegionConfig, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.aws_redshift_service_account.regional", "id", "210876761215"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const testAccCheckAwsRedshiftServiceAccountConfig = ` | ||
data "aws_redshift_service_account" "main" { } | ||
` | ||
|
||
const testAccCheckAwsRedshiftServiceAccountExplicitRegionConfig = ` | ||
data "aws_redshift_service_account" "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
57 changes: 57 additions & 0 deletions
57
website/source/docs/providers/aws/d/redshift_service_account.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,57 @@ | ||
--- | ||
layout: "aws" | ||
page_title: "AWS: aws_redshift_account_id" | ||
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. I think the title should be updated too. 😉 |
||
sidebar_current: "docs-aws-datasource-redshift-account-id" | ||
description: |- | ||
Get AWS Redshift Service Account ID for storing audit data in S3. | ||
--- | ||
|
||
# aws\_redshift\_service\_account | ||
|
||
Use this data source to get the Service Account ID of the [AWS Redshift Account](http://docs.aws.amazon.com/redshift/latest/mgmt/db-auditing.html#db-auditing-enable-logging) | ||
in a given region for the purpose of allowing Redshift to store audit data in S3. | ||
|
||
## Example Usage | ||
|
||
``` | ||
data "aws_redshift_service_account" "main" { } | ||
|
||
resource "aws_s3_bucket" "bucket" { | ||
bucket = "tf-redshift-logging-test-bucket" | ||
force_destroy = true | ||
policy = <<EOF | ||
{ | ||
"Version": "2008-10-17", | ||
"Statement": [ | ||
{ | ||
"Sid": "Put bucket policy needed for audit logging", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"AWS": "arn:aws:iam:${data.aws_redshift_account_id.main.id}:user/logs" | ||
}, | ||
"Action": "s3:PutObject", | ||
"Resource": "arn:aws:s3:::tf-redshift-logging-test-bucket/*" | ||
}, | ||
{ | ||
"Sid": "Get bucket policy needed for audit logging ", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"AWS": "arn:aws:iam:${data.aws_redshift_account_id.main.id}:user/logs" | ||
}, | ||
"Action": "s3:GetBucketAcl", | ||
"Resource": "arn:aws:s3:::tf-redshift-logging-test-bucket" | ||
} | ||
] | ||
} | ||
EOF | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `region` - (Optional) Name of the Region whose Redshift account id is desired. If not specified, default's to the region from the AWS provider configuration. | ||
|
||
|
||
## Attributes Reference | ||
|
||
* `id` - The ID of the Redshift service Account in the selected region. |
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 |
---|---|---|
|
@@ -35,6 +35,9 @@ | |
<li<%= sidebar_current("docs-aws-datasource-ip_ranges") %>> | ||
<a href="/docs/providers/aws/d/ip_ranges.html">aws_ip_ranges</a> | ||
</li> | ||
<li<%= sidebar_current("docs-aws-datasource-redshift-account-id") %>> | ||
<a href="/docs/providers/aws/d/redshift_service_account.html">aws_redshift_servcice_account</a> | ||
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. perhaps typo? |
||
</li> | ||
<li<%= sidebar_current("docs-aws-datasource-s3-bucket-object") %>> | ||
<a href="/docs/providers/aws/d/s3_bucket_object.html">aws_s3_bucket_object</a> | ||
</li> | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Thanks for this! 😃