diff --git a/aws/resource_aws_athena_named_query.go b/aws/resource_aws_athena_named_query.go index e5bd43f2846..57a5c04cbae 100644 --- a/aws/resource_aws_athena_named_query.go +++ b/aws/resource_aws_athena_named_query.go @@ -29,6 +29,12 @@ func resourceAwsAthenaNamedQuery() *schema.Resource { Required: true, ForceNew: true, }, + "workgroup": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Default: "primary", + }, "database": { Type: schema.TypeString, Required: true, @@ -51,6 +57,9 @@ func resourceAwsAthenaNamedQueryCreate(d *schema.ResourceData, meta interface{}) Name: aws.String(d.Get("name").(string)), QueryString: aws.String(d.Get("query").(string)), } + if raw, ok := d.GetOk("workgroup"); ok { + input.WorkGroup = aws.String(raw.(string)) + } if raw, ok := d.GetOk("description"); ok { input.Description = aws.String(raw.(string)) } @@ -82,6 +91,7 @@ func resourceAwsAthenaNamedQueryRead(d *schema.ResourceData, meta interface{}) e d.Set("name", resp.NamedQuery.Name) d.Set("query", resp.NamedQuery.QueryString) + d.Set("workgroup", resp.NamedQuery.WorkGroup) d.Set("database", resp.NamedQuery.Database) d.Set("description", resp.NamedQuery.Description) return nil diff --git a/aws/resource_aws_athena_named_query_test.go b/aws/resource_aws_athena_named_query_test.go index dd6aba53c12..c01b3d268ff 100644 --- a/aws/resource_aws_athena_named_query_test.go +++ b/aws/resource_aws_athena_named_query_test.go @@ -27,6 +27,22 @@ func TestAccAWSAthenaNamedQuery_basic(t *testing.T) { }) } +func TestAccAWSAthenaNamedQuery_withWorkGroup(t *testing.T) { + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSAthenaNamedQueryDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAthenaNamedWorkGroupQueryConfig(acctest.RandInt(), acctest.RandString(5)), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSAthenaNamedQueryExists("aws_athena_named_query.bar"), + ), + }, + }, + }) +} + func TestAccAWSAthenaNamedQuery_import(t *testing.T) { resourceName := "aws_athena_named_query.foo" @@ -111,3 +127,29 @@ resource "aws_athena_named_query" "foo" { } `, rName, rInt, rName, rName) } + +func testAccAthenaNamedWorkGroupQueryConfig(rInt int, rName string) string { + return fmt.Sprintf(` +resource "aws_s3_bucket" "hoge" { + bucket = "tf-athena-db-%s-%d" + force_destroy = true +} + +resource "aws_athena_workgroup" "test" { + name = "tf-athena-workgroup-%s-%d" +} + +resource "aws_athena_database" "hoge" { + name = "%s" + bucket = "${aws_s3_bucket.hoge.bucket}" +} + +resource "aws_athena_named_query" "bar" { + name = "tf-athena-named-query-%s" + workgroup = "${aws_athena_workgroup.test.id}" + database = "${aws_athena_database.hoge.name}" + query = "SELECT * FROM ${aws_athena_database.hoge.name} limit 10;" + description = "tf test" +} +`, rName, rInt, rName, rInt, rName, rName) +} diff --git a/website/docs/r/athena_named_query.html.markdown b/website/docs/r/athena_named_query.html.markdown index 6593eaf28ef..333bcd27f85 100644 --- a/website/docs/r/athena_named_query.html.markdown +++ b/website/docs/r/athena_named_query.html.markdown @@ -17,15 +17,34 @@ resource "aws_s3_bucket" "hoge" { bucket = "tf-test" } +resource "aws_kms_key" "test" { + deletion_window_in_days = 7 + description = "Athena KMS Key" +} + +resource "aws_athena_workgroup" "test" { + name = "example" + + configuration { + result_configuration { + encryption_configuration { + encryption_option = "SSE_KMS" + kms_key_arn = "${aws_kms_key.test.arn}" + } + } + } +} + resource "aws_athena_database" "hoge" { name = "users" bucket = "${aws_s3_bucket.hoge.bucket}" } resource "aws_athena_named_query" "foo" { - name = "bar" - database = "${aws_athena_database.hoge.name}" - query = "SELECT * FROM ${aws_athena_database.hoge.name} limit 10;" + name = "bar" + workgroup = "${aws_athena_workgroup.test.id}" + database = "${aws_athena_database.hoge.name}" + query = "SELECT * FROM ${aws_athena_database.hoge.name} limit 10;" } ``` @@ -34,6 +53,7 @@ resource "aws_athena_named_query" "foo" { The following arguments are supported: * `name` - (Required) The plain language name for the query. Maximum length of 128. +* `workgroup` - (Optional) The workgroup to which the query belongs. Defaults to `primary` * `database` - (Required) The database to which the query belongs. * `query` - (Required) The text of the query itself. In other words, all query statements. Maximum length of 262144. * `description` - (Optional) A brief explanation of the query. Maximum length of 1024.