Skip to content

Commit

Permalink
Merge pull request #20457 from drewmullen/f-aws_athena_requester_pays…
Browse files Browse the repository at this point in the history
…_enabled

f athena request pays enabled
  • Loading branch information
ewbankkit committed Aug 9, 2021
2 parents 5cfa3b5 + d48074c commit 50f31ec
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .changelog/20457.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_athena_workgroup: Add `requester_pays_enabled` argument
```
35 changes: 21 additions & 14 deletions aws/resource_aws_athena_workgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,9 @@ func resourceAwsAthenaWorkgroup() *schema.Resource {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"encryption_option": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
athena.EncryptionOptionCseKms,
athena.EncryptionOptionSseKms,
athena.EncryptionOptionSseS3,
}, false),
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice(athena.EncryptionOption_Values(), false),
},
"kms_key_arn": {
Type: schema.TypeString,
Expand All @@ -89,6 +85,11 @@ func resourceAwsAthenaWorkgroup() *schema.Resource {
},
},
},
"requester_pays_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
},
},
Expand All @@ -107,13 +108,10 @@ func resourceAwsAthenaWorkgroup() *schema.Resource {
),
},
"state": {
Type: schema.TypeString,
Optional: true,
Default: athena.WorkGroupStateEnabled,
ValidateFunc: validation.StringInSlice([]string{
athena.WorkGroupStateDisabled,
athena.WorkGroupStateEnabled,
}, false),
Type: schema.TypeString,
Optional: true,
Default: athena.WorkGroupStateEnabled,
ValidateFunc: validation.StringInSlice(athena.WorkGroupState_Values(), false),
},
"force_destroy": {
Type: schema.TypeBool,
Expand Down Expand Up @@ -323,6 +321,10 @@ func expandAthenaWorkGroupConfiguration(l []interface{}) *athena.WorkGroupConfig
configuration.ResultConfiguration = expandAthenaWorkGroupResultConfiguration(v.([]interface{}))
}

if v, ok := m["requester_pays_enabled"]; ok {
configuration.RequesterPaysEnabled = aws.Bool(v.(bool))
}

return configuration
}

Expand Down Expand Up @@ -353,6 +355,10 @@ func expandAthenaWorkGroupConfigurationUpdates(l []interface{}) *athena.WorkGrou
configurationUpdates.ResultConfigurationUpdates = expandAthenaWorkGroupResultConfigurationUpdates(v.([]interface{}))
}

if v, ok := m["requester_pays_enabled"]; ok {
configurationUpdates.RequesterPaysEnabled = aws.Bool(v.(bool))
}

return configurationUpdates
}

Expand Down Expand Up @@ -430,6 +436,7 @@ func flattenAthenaWorkGroupConfiguration(configuration *athena.WorkGroupConfigur
"enforce_workgroup_configuration": aws.BoolValue(configuration.EnforceWorkGroupConfiguration),
"publish_cloudwatch_metrics_enabled": aws.BoolValue(configuration.PublishCloudWatchMetricsEnabled),
"result_configuration": flattenAthenaWorkGroupResultConfiguration(configuration.ResultConfiguration),
"requester_pays_enabled": aws.BoolValue(configuration.RequesterPaysEnabled),
}

return []interface{}{m}
Expand Down
52 changes: 52 additions & 0 deletions aws/resource_aws_athena_workgroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func TestAccAWSAthenaWorkGroup_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "configuration.#", "1"),
resource.TestCheckResourceAttr(resourceName, "configuration.0.enforce_workgroup_configuration", "true"),
resource.TestCheckResourceAttr(resourceName, "configuration.0.publish_cloudwatch_metrics_enabled", "true"),
resource.TestCheckResourceAttr(resourceName, "configuration.0.requester_pays_enabled", "false"),
resource.TestCheckResourceAttr(resourceName, "description", ""),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "state", athena.WorkGroupStateEnabled),
Expand Down Expand Up @@ -295,6 +296,45 @@ func TestAccAWSAthenaWorkGroup_Configuration_ResultConfiguration_OutputLocation(
})
}

func TestAccAWSAthenaWorkGroup_Configuration_RequesterPaysEnabled(t *testing.T) {
var workgroup1 athena.WorkGroup
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_athena_workgroup.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ErrorCheck: testAccErrorCheck(t, athena.EndpointsID),
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSAthenaWorkGroupDestroy,
Steps: []resource.TestStep{
{
Config: testAccAthenaWorkGroupConfigConfigurationRequesterPaysEnabled(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAthenaWorkGroupExists(resourceName, &workgroup1),
testAccCheckResourceAttrRegionalARN(resourceName, "arn", "athena", fmt.Sprintf("workgroup/%s", rName)),
resource.TestCheckResourceAttr(resourceName, "configuration.#", "1"),
resource.TestCheckResourceAttr(resourceName, "configuration.0.requester_pays_enabled", "true"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"force_destroy"},
},
{
Config: testAccAthenaWorkGroupConfig(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAthenaWorkGroupExists(resourceName, &workgroup1),
testAccCheckResourceAttrRegionalARN(resourceName, "arn", "athena", fmt.Sprintf("workgroup/%s", rName)),
resource.TestCheckResourceAttr(resourceName, "configuration.#", "1"),
resource.TestCheckResourceAttr(resourceName, "configuration.0.requester_pays_enabled", "false"),
),
},
},
})
} //

func TestAccAWSAthenaWorkGroup_Configuration_ResultConfiguration_OutputLocation_ForceDestroy(t *testing.T) {
var workgroup1, workgroup2 athena.WorkGroup
rName := acctest.RandomWithPrefix("tf-acc-test")
Expand Down Expand Up @@ -652,6 +692,18 @@ resource "aws_athena_workgroup" "test" {
`, rName, bucketName)
}

func testAccAthenaWorkGroupConfigConfigurationRequesterPaysEnabled(rName string) string {
return fmt.Sprintf(`
resource "aws_athena_workgroup" "test" {
name = %[1]q
configuration {
requester_pays_enabled = true
}
}
`, rName)
}

func testAccAthenaWorkGroupConfigConfigurationResultConfigurationOutputLocationForceDestroy(rName string, bucketName string) string {
return fmt.Sprintf(`
resource "aws_s3_bucket" "test" {
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/athena_workgroup.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ The `configuration` configuration block supports the following arguments:
* `enforce_workgroup_configuration` - (Optional) Boolean whether the settings for the workgroup override client-side settings. For more information, see [Workgroup Settings Override Client-Side Settings](https://docs.aws.amazon.com/athena/latest/ug/workgroups-settings-override.html). Defaults to `true`.
* `publish_cloudwatch_metrics_enabled` - (Optional) Boolean whether Amazon CloudWatch metrics are enabled for the workgroup. Defaults to `true`.
* `result_configuration` - (Optional) Configuration block with result settings. Documented below.
* `requester_pays_enabled` - (Optional) If set to true , allows members assigned to a workgroup to reference Amazon S3 Requester Pays buckets in queries. If set to false , workgroup members cannot query data from Requester Pays buckets, and queries that retrieve data from Requester Pays buckets cause an error. The default is false . For more information about Requester Pays buckets, see [Requester Pays Buckets](https://docs.aws.amazon.com/AmazonS3/latest/dev/RequesterPaysBuckets.html) in the Amazon Simple Storage Service Developer Guide.

#### result_configuration Argument Reference

Expand Down

0 comments on commit 50f31ec

Please sign in to comment.