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

aws_cur_report_definition - Parquet, Athena and more #12428

Merged
merged 13 commits into from
Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions aws/data_source_aws_cur_report_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ func dataSourceAwsCurReportDefinition() *schema.Resource {
Set: schema.HashString,
Computed: true,
},
"refresh_closed_reports": {
Type: schema.TypeBool,
Computed: true,
},
"report_versioning": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down
112 changes: 110 additions & 2 deletions aws/data_source_aws_cur_report_definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,42 @@ func TestAccDataSourceAwsCurReportDefinition_basic(t *testing.T) {
})
}

func TestAccDataSourceAwsCurReportDefinition_additional(t *testing.T) {
oldvar := os.Getenv("AWS_DEFAULT_REGION")
os.Setenv("AWS_DEFAULT_REGION", "us-east-1")
defer os.Setenv("AWS_DEFAULT_REGION", oldvar)

resourceName := "aws_cur_report_definition.test"
datasourceName := "data.aws_cur_report_definition.test"

reportName := acctest.RandomWithPrefix("tf_acc_test")
bucketName := fmt.Sprintf("tf-test-bucket-%d", acctest.RandInt())

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSCur(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsCurReportDefinitionDestroy,
Steps: []resource.TestStep{
{
Config: testAccDataSourceAwsCurReportDefinitionConfig_additional(reportName, bucketName),
Check: resource.ComposeTestCheckFunc(
testAccDataSourceAwsCurReportDefinitionCheckExists(datasourceName, resourceName),
resource.TestCheckResourceAttrPair(datasourceName, "report_name", resourceName, "report_name"),
resource.TestCheckResourceAttrPair(datasourceName, "time_unit", resourceName, "time_unit"),
resource.TestCheckResourceAttrPair(datasourceName, "compression", resourceName, "compression"),
resource.TestCheckResourceAttrPair(datasourceName, "additional_schema_elements.#", resourceName, "additional_schema_elements.#"),
resource.TestCheckResourceAttrPair(datasourceName, "s3_bucket", resourceName, "s3_bucket"),
resource.TestCheckResourceAttrPair(datasourceName, "s3_prefix", resourceName, "s3_prefix"),
resource.TestCheckResourceAttrPair(datasourceName, "s3_region", resourceName, "s3_region"),
resource.TestCheckResourceAttrPair(datasourceName, "additional_artifacts.#", resourceName, "additional_artifacts.#"),
resource.TestCheckResourceAttrPair(datasourceName, "refresh_closed_reports", resourceName, "refresh_closed_reports"),
resource.TestCheckResourceAttrPair(datasourceName, "report_versioning", resourceName, "report_versioning"),
),
},
},
})
}

func testAccDataSourceAwsCurReportDefinitionCheckExists(datasourceName, resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
_, ok := s.RootModule().Resources[datasourceName]
Expand Down Expand Up @@ -85,13 +121,13 @@ resource "aws_s3_bucket_policy" "test" {
"Sid": "AllowCURBillingACLPolicy",
"Effect": "Allow",
"Principal": {
"AWS": data.aws_billing_service_account.test.arn
"AWS": "${data.aws_billing_service_account.test.arn}"
},
"Action": [
"s3:GetBucketAcl",
"s3:GetBucketPolicy"
],
"Resource": aws_s3_bucket.test.arn
"Resource": "${aws_s3_bucket.test.arn}"
},
{
"Sid": "AllowCURPutObject",
Expand All @@ -108,6 +144,76 @@ POLICY
}

resource "aws_cur_report_definition" "test" {
depends_on = [aws_s3_bucket_policy.test] # needed to avoid "ValidationException: Failed to verify customer bucket permission."

report_name = "%[1]s"
time_unit = "DAILY"
format = "textORcsv"
compression = "GZIP"
additional_schema_elements = ["RESOURCES"]
s3_bucket = aws_s3_bucket.test.id
s3_prefix = ""
s3_region = aws_s3_bucket.test.region
additional_artifacts = ["REDSHIFT", "QUICKSIGHT"]
}

data "aws_cur_report_definition" "test" {
report_name = aws_cur_report_definition.test.report_name
}
`, reportName, bucketName)
}

func testAccDataSourceAwsCurReportDefinitionConfig_additional(reportName string, bucketName string) string {
return fmt.Sprintf(`
provider "aws" {
region = "us-east-1"
}

data "aws_billing_service_account" "test" {}

resource "aws_s3_bucket" "test" {
bucket = "%[2]s"
acl = "private"
force_destroy = true
}

resource "aws_s3_bucket_policy" "test" {
bucket = aws_s3_bucket.test.id

policy = <<POLICY
{
"Version": "2008-10-17",
"Id": "s3policy",
"Statement": [
{
"Sid": "AllowCURBillingACLPolicy",
"Effect": "Allow",
"Principal": {
"AWS": "${data.aws_billing_service_account.test.arn}"
},
"Action": [
"s3:GetBucketAcl",
"s3:GetBucketPolicy"
],
"Resource": "${aws_s3_bucket.test.arn}"
},
{
"Sid": "AllowCURPutObject",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::386209384616:root"
},
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::${aws_s3_bucket.test.id}/*"
}
]
}
POLICY
}

resource "aws_cur_report_definition" "test" {
depends_on = [aws_s3_bucket_policy.test] # needed to avoid "ValidationException: Failed to verify customer bucket permission."

report_name = "%[1]s"
time_unit = "DAILY"
format = "textORcsv"
Expand All @@ -117,6 +223,8 @@ resource "aws_cur_report_definition" "test" {
s3_prefix = ""
s3_region = aws_s3_bucket.test.region
additional_artifacts = ["REDSHIFT", "QUICKSIGHT"]
refresh_closed_reports = true
report_versioning = "CREATE_NEW_REPORT"
}

data "aws_cur_report_definition" "test" {
Expand Down
Loading