Skip to content

Commit

Permalink
service/costandusagereporting: Parquet, Athena and more (#12428)
Browse files Browse the repository at this point in the history
Output from acceptance testing:

```
--- PASS: TestAccAwsCurReportDefinition_overwrite (37.09s)
--- PASS: TestAccAwsCurReportDefinition_athena (37.35s)
--- PASS: TestAccAwsCurReportDefinition_refresh (38.27s)
--- PASS: TestAccAwsCurReportDefinition_textOrCsv (38.99s)
--- PASS: TestAccAwsCurReportDefinition_basic (39.75s)
--- PASS: TestAccAwsCurReportDefinition_parquet (40.34s)

--- PASS: TestAccDataSourceAwsCurReportDefinition_basic (40.55s)
--- PASS: TestAccDataSourceAwsCurReportDefinition_additional (40.62s)
```
  • Loading branch information
robbruce authored Sep 2, 2020
1 parent 147a7a7 commit 6b40959
Show file tree
Hide file tree
Showing 6 changed files with 770 additions and 37 deletions.
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

0 comments on commit 6b40959

Please sign in to comment.