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

Feat: Feature AWS Athena Terraform module 🚀 #1

Merged
merged 8 commits into from
Aug 25, 2023
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ We have [*fifty plus terraform modules*][terraform_modules]. A few of them are c
## Prerequisites

This module has a few dependencies:
- [Terraform 1.4.6](https://learn.hashicorp.com/terraform/getting-started/install.html)
- [Terraform 1.5.3](https://learn.hashicorp.com/terraform/getting-started/install.html)



Expand Down
106 changes: 97 additions & 9 deletions README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,128 @@
#

# Name of this project
name : Terraform Module Template
name : Terraform Module Athena

# License of this project
license: "APACHE"

# Canonical GitHub repo
github_repo: clouddrove/terraform-module-template
github_repo: clouddrove/terraform-aws-athena

# Badges to display
badges:
- name: "Latest Release"
image: "https://img.shields.io/github/release/clouddrove/terraform-module-template.svg"
url: "https://github.com/clouddrove/terraform-module-template/releases/latest"
image: "https://img.shields.io/github/release/clouddrove/terraform-aws-athena.svg"
url: "https://github.com/clouddrove/terraform-aws-athena/releases/latest"
- name: "tfsec"
image: "https://github.com/clouddrove/terraform-module-template/actions/workflows/tfsec.yml/badge.svg"
image: "https://github.com/clouddrove/terraform-aws-athena/actions/workflows/tfsec.yml/badge.svg"
url: ""
- name: "Licence"
image: "https://img.shields.io/badge/License-APACHE-blue.svg"
url: "LICENSE.md"

prerequesties:
- name: Terraform 1.4.6
- name: Terraform 1.5.3
url: https://learn.hashicorp.com/terraform/getting-started/install.html

# description of this project
description: |-
Terraform module template to create new modules using this as baseline
Terraform Athena module to create new modules using this as baseline
# extra content
include:
- "terraform.md"

# How to use this project
# How to use this project
usage: |-
Here are some examples of how you can use this module in your inventory structure:
## Basic Example to create a basic AWS Athena without extra configs
```hcl
module "athena" {
source = "clouddrove/athena/aws"
version = "1.0.0"

name = "athena"
environment = "test"
label_order = ["name", "environment"]

enabled = true
workgroup_force_destroy = true

# S3 Bucket Configuration
bucket_force_destroy = true
s3_output_path = "accessLogs/queryresults/" # The S3 bucket path used to store query results

# Database for Athena
databases = {
database1 = {
force_destroy = true
properties = {
custom_prop_1 = "example"
}
}
}
}
```

## Complete Example to create a basic AWS Athena without extra configs
```hcl
```
locals {
name = "athena"
environment = "test"
label_order = ["name", "environment"]
}

module "s3_bucket" {
source = "clouddrove/s3/aws"
version = "1.3.0"
name = format("%s-bucket-test", local.name)
versioning = true
acl = "private"
force_destroy = true
}

module "athena" {
source = "clouddrove/athena/aws"
version = "1.0.0"
name = local.name
environment = local.environment
label_order = local.label_order
enabled = true
workgroup_force_destroy = true

# S3 Bucket Configuration
create_s3_bucket = false
athena_s3_bucket_id = module.s3_bucket.id
s3_output_path = "outputs/" # The S3 bucket path used to store query results

# Database for Athena
databases = {
database1 = {
force_destroy = true
properties = {
custom_prop_1 = "example"
}
}
}

# Data catalog to test terraform
data_catalogs = {
glue1 = {
description = "This is an example to test Terraform"
type = "GLUE"
parameters = {
catalog-id : "123456789012" # The catalog_id is the account ID of the AWS account to which the AWS Glue catalog belongs.
}
}
}

# Named Queries to test terarform
named_queries = {
query1 = {
database = "database1"
description = "This is an example query to test Terraform"
query = "SELECT * FROM %s limit 10;"
}
}
}
```
31 changes: 29 additions & 2 deletions _examples/basic/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
## examples/basic
## Basic Example to create AWS Athena

An example which shows _basic_ usage of the module.
This folder contains a basic example of how to use the terraform athena module to create an Athena workgroup, database. The table is based on a sample CSV file stored in an S3 bucket.

## Usage

To run this example you need to execute:

```bash
$ terraform init
$ terraform plan
$ terraform apply
```

## Inputs

- `name` : The name of the Athena workgroup. Required.
- `environment` : The environment of the Athena module created. Optional
- `label_order` : The label order of the module, used to create te name of Athena workgroup. e.g. ["name", "environment"] or ["name"] Optional
- `enabled` : The Bool value that refers the creation of AWS Athena resources. Optional
- `workgroup_force_destroy` : The option to delete the workgroup and its contents even if the workgroup contains any named queries. Optional
- `bucket_force_destroy` : A boolean that indicates all objects should be deleted from the bucket so that the bucket can be destroyed without error. These objects are not recoverable. Optional
- `s3_output_path` : The S3 bucket path used to store query results. Optional
- `databases` : Map of Athena databases and related configuration. Required

## Outputs

- `athena_workgroup_id` : The ID of the Athena workgroup.
- `athena_databases` : The ID of the Athena database.
- `athena_s3_bucket_id` : The ID of the S3 bucket.
41 changes: 41 additions & 0 deletions _examples/basic/example.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

# Managed By : CloudDrove
# Copyright @ CloudDrove. All Right Reserved.

##------------------------------------------------------------------------------
## Provider
##------------------------------------------------------------------------------
provider "aws" {
region = "us-east-1"
}

##------------------------------------------------------------------------------
## AWS Athena Module
##------------------------------------------------------------------------------

module "athena" {
source = "../../"
name = "athena"
environment = "test"
label_order = ["name", "environment"]
enabled = true
workgroup_force_destroy = true

# S3 Bucket Configuration
bucket_force_destroy = true
s3_output_path = "accessLogs/queryresults/" # The S3 bucket path used to store query results
bucket_versioning = true

# Database for Athena
databases = {
database1 = {
force_destroy = true
properties = {
custom_prop_1 = "example"
}
encryption_configuration = {
encryption_option = "SSE_KMS"
}
}
}
}
Comment on lines +16 to +41

Check warning

Code scanning / defsec

S3 Bucket does not have logging enabled. Warning

Bucket does not have logging enabled
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bucket Logging in the Athena's s3 bucket is not required because we are not using s3 for logging.

Comment on lines +16 to +41

Check warning

Code scanning / defsec

S3 Data should be versioned Warning

Bucket does not have versioning enabled
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Data version will have additional cost in s3 so didn't used it in example.

4 changes: 0 additions & 4 deletions _examples/basic/main.tf

This file was deleted.

30 changes: 27 additions & 3 deletions _examples/basic/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
# ------------------------------------------------------------------------------
# Outputs
# ------------------------------------------------------------------------------

# Managed By : CloudDrove
# Copyright @ CloudDrove. All Right Reserved.

##------------------------------------------------------------------------------
## Outputs
##------------------------------------------------------------------------------

output "athena_s3_bucket_id" {
description = "ID of S3 bucket used by Athena."
value = module.athena.bucket_id
}

output "athena_kms_key_arn" {
description = "ARN of KMS key used by Athena."
value = module.athena.kms_key_arn
}

output "athena_workgroup_id" {
description = "ID of newly created Athena workgroup."
value = module.athena.workgroup_id
}

output "athena_databases" {
description = "List of newly created Athena databases."
value = module.athena.databases
}
3 changes: 0 additions & 3 deletions _examples/basic/variables.auto.tfvars

This file was deleted.

3 changes: 0 additions & 3 deletions _examples/basic/variables.tf

This file was deleted.

34 changes: 32 additions & 2 deletions _examples/complete/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
## examples/complete
## Complete Example to create AWS Athena

An example which shows _complete_ usage of the module.
This folder contains a basic example of how to use the terraform athena module to create a S3 bucket, Athena workgroup, database, queries. The table is based on a sample CSV file stored in an S3 bucket.


## Usage

To run this example you need to execute:

```bash
$ terraform init
$ terraform plan
$ terraform apply
```

## Inputs

- `name` : The name of the Athena workgroup. Required.
- `environment` : The environment of the Athena module created. Optional
- `label_order` : The label order of the module, used to create te name of Athena workgroup. e.g. ["name", "environment"] or ["name"] Optional
- `enabled` : The Bool value that refers the creation of AWS Athena resources. Optional
- `workgroup_force_destroy` : The option to delete the workgroup and its contents even if the workgroup contains any named queries. Optional
- `bucket_force_destroy` : A boolean that indicates all objects should be deleted from the bucket so that the bucket can be destroyed without error. These objects are not recoverable. Optional
- `s3_output_path` : The S3 bucket path used to store query results. Optional
- `databases` : Map of Athena databases and related configuration. Required
- `data_catalogs` : Map of Athena data catalogs and related configuration. Optional
- `named_queries` : Map of Athena named queries and related configuration. Optional

## Outputs

- `athena_workgroup_id` : The ID of the Athena workgroup.
- `athena_databases` : The ID of the Athena database.
- `athena_s3_bucket_id` : The ID of the S3 bucket.
83 changes: 83 additions & 0 deletions _examples/complete/example.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@

# Managed By : CloudDrove
# Copyright @ CloudDrove. All Right Reserved.

##------------------------------------------------------------------------------
## Provider
##------------------------------------------------------------------------------
provider "aws" {
region = "us-east-1"
}

##------------------------------------------------------------------------------
## Local
##------------------------------------------------------------------------------
locals {
name = "athena"
environment = "test"
label_order = ["name", "environment"]
}

##------------------------------------------------------------------------------
## AWS S3
##------------------------------------------------------------------------------
module "s3_bucket" {
source = "clouddrove/s3/aws"
version = "1.3.0"
name = format("%s-bucket-test", local.name)
versioning = true
acl = "private"
force_destroy = true
}
Comment on lines +24 to +31

Check warning

Code scanning / defsec

S3 Bucket does not have logging enabled. Warning

Bucket does not have logging enabled
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Data version in the Athena's s3 bucket is not required because we are not using s3 for logging.

Comment on lines +24 to +31

Check warning

Code scanning / defsec

S3 Data should be versioned Warning

Bucket does not have versioning enabled
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Data version in the Athena's s3 bucket is not required because we are not using s3 for logging.


##------------------------------------------------------------------------------
## AWS Athena Module
##------------------------------------------------------------------------------

module "athena" {
source = "../../"
name = local.name
environment = local.environment
label_order = local.label_order
enabled = true
workgroup_force_destroy = true

# S3 Bucket Configuration
create_s3_bucket = false
athena_s3_bucket_id = module.s3_bucket.id
s3_output_path = "outputs/" # The S3 bucket path used to store query results
bucket_versioning = true

# Database for Athena
databases = {
database1 = {
force_destroy = true
properties = {
custom_prop_1 = "example"
}
encryption_configuration = {
encryption_option = "SSE_KMS"
}
}
}

# Data catalog to test terraform
data_catalogs = {
glue1 = {
description = "This is an example to test Terraform"
type = "GLUE"
parameters = {
catalog-id : "xxxxxxxxxxxx" # The catalog_id is the account ID of the AWS account to which the AWS Glue catalog belongs.
}
}
}

# Named Queries to test terarform
named_queries = {
query1 = {
database = "database1"
description = "This is an example query to test Terraform"
query = "SELECT * FROM %s limit 10;"
}
}
}
4 changes: 0 additions & 4 deletions _examples/complete/main.tf

This file was deleted.

Loading