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 workgroup support for Athena named query #9383

Merged
merged 3 commits into from
Jul 18, 2019
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
10 changes: 10 additions & 0 deletions aws/resource_aws_athena_named_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ func resourceAwsAthenaNamedQuery() *schema.Resource {
Required: true,
ForceNew: true,
},
"workgroup": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
bflad marked this conversation as resolved.
Show resolved Hide resolved
Default: "primary",
},
"database": {
Type: schema.TypeString,
Required: true,
Expand All @@ -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))
}
Expand Down Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions aws/resource_aws_athena_named_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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}"
bflad marked this conversation as resolved.
Show resolved Hide resolved
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)
}
26 changes: 23 additions & 3 deletions website/docs/r/athena_named_query.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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;"
}
```

Expand All @@ -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.
Expand Down