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

Add 'arn' attribute to 'aws_redshift_service_account' data source #1775

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions aws/data_source_aws_redshift_service_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func dataSourceAwsRedshiftServiceAccount() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"arn": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand All @@ -45,6 +49,7 @@ func dataSourceAwsRedshiftServiceAccountRead(d *schema.ResourceData, meta interf

if accid, ok := redshiftServiceAccountPerRegionMap[region]; ok {
d.SetId(accid)
d.Set("arn", fmt.Sprintf("arn:%s:iam::%s:user/logs", meta.(*AWSClient).partition, accid))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should use fmt.Sprintf here - I think we should use the ARN package as part of AWS

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do

return nil
}

Expand Down
2 changes: 2 additions & 0 deletions aws/data_source_aws_redshift_service_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ func TestAccAWSRedshiftServiceAccount_basic(t *testing.T) {
Config: testAccCheckAwsRedshiftServiceAccountConfig,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.aws_redshift_service_account.main", "id", "902366379725"),
resource.TestCheckResourceAttr("data.aws_redshift_service_account.main", "arn", "arn:aws:iam::902366379725:user/logs"),
),
},
resource.TestStep{
Config: testAccCheckAwsRedshiftServiceAccountExplicitRegionConfig,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.aws_redshift_service_account.regional", "id", "307160386991"),
resource.TestCheckResourceAttr("data.aws_redshift_service_account.regional", "arn", "arn:aws:iam::307160386991:user/logs"),
),
},
},
Expand Down
15 changes: 8 additions & 7 deletions website/docs/d/redshift_service_account.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ layout: "aws"
page_title: "AWS: aws_redshift_service_account"
sidebar_current: "docs-aws-datasource-redshift-service-account"
description: |-
Get AWS Redshift Service Account ID for storing audit data in S3.
Get AWS Redshift Service Account 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)
Use this data source to get the Account ID of the [AWS Redshift Service 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
Expand All @@ -28,7 +28,7 @@ resource "aws_s3_bucket" "bucket" {
"Sid": "Put bucket policy needed for audit logging",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::${data.aws_redshift_service_account.main.id}:user/logs"
"AWS": "${data.aws_redshift_service_account.main.arn}"
},
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::tf-redshift-logging-test-bucket/*"
Expand All @@ -37,7 +37,7 @@ resource "aws_s3_bucket" "bucket" {
"Sid": "Get bucket policy needed for audit logging ",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::${data.aws_redshift_service_account.main.id}:user/logs"
"AWS": "${data.aws_redshift_service_account.main.arn}"
},
"Action": "s3:GetBucketAcl",
"Resource": "arn:aws:s3:::tf-redshift-logging-test-bucket"
Expand All @@ -50,9 +50,10 @@ 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.

* `region` - (Optional) Name of the region whose AWS Redshift account ID is desired.
Defaults to the region from the AWS provider configuration.

## Attributes Reference

* `id` - The ID of the Redshift service Account in the selected region.
* `id` - The ID of the AWS Redshift service account in the selected region.
* `arn` - The ARN of the AWS Redshift service account in the selected region.