Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to modify Athena's primary workgroup configuration using Terraform?

I have created the following resources using Terraform:

  1. aws_athena_database: Amazon Athena database

  2. aws_glue_catalog_table: A CSV table for Athena

It is easy to change my my primary workgroup's default location for query results in the AWS console:Athena console

How can I achieve this using Terraform?

I have specified a custom bucket argument for the aws_athena_database to store my query results, which works well if I'm querying outside the Athena console (like Tableau), but if I'm working in the Athena console it defaults to a generic Athena-provided S3 bucket.

like image 930
ishwr_ Avatar asked Dec 12 '25 14:12

ishwr_


1 Answers

You want to us something like this in your terraform, however; this will produce an error because the workgroup already exists, so you will need to use terraform import in order to make terraform add this pre-existing resource to your state file:

terraform import aws_athena_workgroup.primary primary
resource "aws_athena_workgroup" "primary" {
  name       = "primary"
  depends_on = [aws_s3_bucket.my-results-bucket]
  configuration {
    enforce_workgroup_configuration    = false
    publish_cloudwatch_metrics_enabled = true

    result_configuration {
      output_location = "s3://${aws_s3_bucket.my-results-bucket.bucket}/"

      encryption_configuration {
        encryption_option = "SSE_S3"
      }
    }
  }
}
like image 106
Daniel Fitzpatrick Avatar answered Dec 15 '25 14:12

Daniel Fitzpatrick