Skip to content

Commit 86cb6ac

Browse files
Merge pull request #8 from appcd-dev/stackgen_af552d97-908a-404b-bd9b-bad1c2eebdf0
creating iac for storage component
2 parents 51fdf88 + 75c840c commit 86cb6ac

14 files changed

Lines changed: 610 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Source: https://github.com/github/gitignore/blob/main/Terraform.gitignore
2+
# Local .terraform directories
3+
**/.terraform/*
4+
5+
# .tfstate files
6+
*.tfstate
7+
*.tfstate.*
8+
9+
# Crash log files
10+
crash.log
11+
crash.*.log
12+
13+
# Ignore override files as they are usually used to override resources locally and so
14+
# are not checked in
15+
override.tf
16+
override.tf.json
17+
*_override.tf
18+
*_override.tf.json
19+
20+
# Ignore transient lock info files created by terraform apply
21+
.terraform.tfstate.lock.info
22+
23+
# Include override files you do wish to add to version control using negated pattern
24+
# !example_override.tf
25+
26+
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
27+
# example: *tfplan*
28+
29+
# Ignore CLI configuration files
30+
.terraformrc
31+
terraform.rc
32+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"app_stack_name": "untitled-appStack-02989a07",
3+
"iac_type": "Terraform",
4+
"provider": "aws",
5+
"multi_env": false,
6+
"exporter": "terraform"
7+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# README
2+
This is a readme file for IaC generated with StackGen.
3+
You can modify your appStack -> [here](http://stage.dev.stackgen.com/appstacks/12f6711b-680f-4bf3-b106-91c7c817fd02)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
terraform {
2+
backend "local" {
3+
path = "/Users/gauravchavan/Documents/terraform.tfstate"
4+
}
5+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
module "stackgen_0f83e604-227d-494f-9477-1735ce19eebf" {
2+
source = "./modules/aws_s3"
3+
block_public_access = true
4+
bucket_name = "sg-bucket-sales-demo"
5+
bucket_policy = ""
6+
enable_versioning = true
7+
enable_website_configuration = false
8+
sse_algorithm = "aws:kms"
9+
tags = {}
10+
website_error_document = "404.html"
11+
website_index_document = "index.html"
12+
}
13+
14+
module "stackgen_31ac0045-76ab-4587-951d-bab58037d7db" {
15+
source = "./modules/aws_athena"
16+
athena_engine_version = "AUTO"
17+
bucket_name = module.stackgen_0f83e604-227d-494f-9477-1735ce19eebf.bucket_name
18+
bytes_scanned_cutoff_per_query = 10485760
19+
database_force_destroy = false
20+
database_name = "sg-sales-demo"
21+
encrypt_query_results = true
22+
encryption_option = "SSE_KMS"
23+
expected_bucket_owner = null
24+
kms_key = null
25+
query = "sg-query"
26+
query_description = null
27+
query_name = "sg-name"
28+
query_results_encryption_option = "SSE_KMS"
29+
require_encryption_configuration = false
30+
result_output_location = null
31+
set_acl_configuration = false
32+
tags = {}
33+
workgroup_description = null
34+
workgroup_force_destroy = false
35+
workgroup_name = "sg-work"
36+
workgroup_state = "ENABLED"
37+
}
38+
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# named query resource
2+
resource "aws_athena_named_query" "this" {
3+
name = var.query_name
4+
description = var.query_description
5+
query = var.query
6+
workgroup = aws_athena_workgroup.this.id
7+
database = aws_athena_database.this.name
8+
}
9+
10+
# database resource
11+
resource "aws_athena_database" "this" {
12+
name = var.database_name
13+
bucket = var.bucket_name
14+
dynamic "acl_configuration" {
15+
for_each = var.set_acl_configuration ? [1] : []
16+
content {
17+
s3_acl_option = "BUCKET_OWNER_FULL_CONTROL"
18+
}
19+
}
20+
21+
dynamic "encryption_configuration" {
22+
for_each = var.require_encryption_configuration ? [1] : []
23+
content {
24+
encryption_option = var.encryption_option
25+
kms_key = var.kms_key
26+
}
27+
}
28+
29+
expected_bucket_owner = var.expected_bucket_owner
30+
force_destroy = var.database_force_destroy
31+
}
32+
33+
resource "aws_kms_key" "aws_athena-result" {
34+
deletion_window_in_days = 7
35+
description = "Athena KMS Key"
36+
}
37+
38+
resource "aws_kms_key" "athena_result_encryption" {
39+
count = var.encrypt_query_results && var.query_results_encryption_option != "SSE_S3" ? 1 : 0
40+
description = "Custom KMS key for Athena query result encryption."
41+
enable_key_rotation = true
42+
}
43+
44+
# workgroup resource
45+
resource "aws_athena_workgroup" "this" {
46+
name = var.workgroup_name
47+
description = var.workgroup_description
48+
state = var.workgroup_state
49+
force_destroy = var.workgroup_force_destroy
50+
tags = var.tags
51+
52+
configuration {
53+
bytes_scanned_cutoff_per_query = var.bytes_scanned_cutoff_per_query
54+
engine_version {
55+
selected_engine_version = var.athena_engine_version
56+
}
57+
result_configuration {
58+
dynamic "encryption_configuration" {
59+
for_each = var.encrypt_query_results ? [1] : []
60+
content {
61+
encryption_option = var.query_results_encryption_option
62+
kms_key_arn = aws_kms_key.athena_result_encryption[0].arn
63+
}
64+
}
65+
dynamic "acl_configuration" {
66+
for_each = var.set_acl_configuration ? [1] : []
67+
content {
68+
s3_acl_option = "BUCKET_OWNER_FULL_CONTROL"
69+
}
70+
}
71+
output_location = var.result_output_location
72+
}
73+
}
74+
}
75+
76+
77+
78+
79+
80+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"output": {
3+
"arn": {
4+
"description": "The value of the wg_arn output",
5+
"sensitive": false,
6+
"value": "${aws_athena_workgroup.this.arn}"
7+
},
8+
"database_id": {
9+
"description": "The value of the database_id output",
10+
"sensitive": false,
11+
"value": "${aws_athena_database.this.id}"
12+
},
13+
"query_id": {
14+
"description": "The value of the query_id output",
15+
"sensitive": false,
16+
"value": "${aws_athena_named_query.this.id}"
17+
}
18+
}
19+
}
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
{
2+
"variable": {
3+
"athena_engine_version": [
4+
{
5+
"default": "AUTO",
6+
"description": "Requested Athena engine version.",
7+
"nullable": false,
8+
"type": "string"
9+
}
10+
],
11+
"bucket_name": [
12+
{
13+
"description": "Name of S3 bucket to save the results of the query execution.",
14+
"nullable": false,
15+
"type": "string"
16+
}
17+
],
18+
"bytes_scanned_cutoff_per_query": [
19+
{
20+
"default": 10485760,
21+
"description": "The upper data usage limit (cutoff) for the amount of bytes a single query in a workgroup is allowed to scan.",
22+
"nullable": false,
23+
"type": "number"
24+
}
25+
],
26+
"database_force_destroy": [
27+
{
28+
"default": false,
29+
"description": "Whether to destroy all tables in the database when destroying the database resource.",
30+
"nullable": false,
31+
"type": "bool"
32+
}
33+
],
34+
"database_name": [
35+
{
36+
"description": "Name of the database to create.",
37+
"nullable": false,
38+
"type": "string"
39+
}
40+
],
41+
"encrypt_query_results": [
42+
{
43+
"default": true,
44+
"description": "Specifies whether query results must be encrypted, for all queries that run in this workgroup.",
45+
"nullable": false,
46+
"type": "bool"
47+
}
48+
],
49+
"encryption_option": [
50+
{
51+
"default": "SSE_KMS",
52+
"description": "Type of key.",
53+
"nullable": false,
54+
"type": "string"
55+
}
56+
],
57+
"expected_bucket_owner": [
58+
{
59+
"description": "AWS account ID that you expect to be the owner of the Amazon S3 bucket.",
60+
"nullable": true,
61+
"type": "string"
62+
}
63+
],
64+
"kms_key": [
65+
{
66+
"description": "The ARN of the KMS key to be used to decrypt the data in S3.",
67+
"nullable": true,
68+
"type": "string"
69+
}
70+
],
71+
"query": [
72+
{
73+
"description": "The query string.",
74+
"nullable": false,
75+
"type": "string"
76+
}
77+
],
78+
"query_description": [
79+
{
80+
"description": "The description for the named query.",
81+
"nullable": true,
82+
"type": "string"
83+
}
84+
],
85+
"query_name": [
86+
{
87+
"description": "The name of the query.",
88+
"type": "string"
89+
}
90+
],
91+
"query_results_encryption_option": [
92+
{
93+
"default": "SSE_KMS",
94+
"description": "Type of encryption.",
95+
"nullable": false,
96+
"type": "string"
97+
}
98+
],
99+
"require_encryption_configuration": [
100+
{
101+
"default": false,
102+
"description": "Encryption key block AWS Athena uses to decrypt the data in S3.",
103+
"nullable": false,
104+
"type": "bool"
105+
}
106+
],
107+
"result_output_location": [
108+
{
109+
"description": "The location in Amazon S3 where your query results are stored, such as s3://path/to/query/bucket/.",
110+
"nullable": true,
111+
"type": "string"
112+
}
113+
],
114+
"set_acl_configuration": [
115+
{
116+
"default": false,
117+
"description": "Should an Amazon S3 canned ACL be set to control ownership of stored query results.",
118+
"nullable": false,
119+
"type": "bool"
120+
}
121+
],
122+
"workgroup_description": [
123+
{
124+
"description": "The description of the workgroup.",
125+
"nullable": true,
126+
"type": "string"
127+
}
128+
],
129+
"workgroup_force_destroy": [
130+
{
131+
"default": false,
132+
"description": "Option to delete the workgroup and its contents even if the workgroup contains any named queries.",
133+
"nullable": false,
134+
"type": "bool"
135+
}
136+
],
137+
"workgroup_name": [
138+
{
139+
"description": "The name of the workgroup.",
140+
"nullable": false,
141+
"type": "string"
142+
}
143+
],
144+
"workgroup_state": [
145+
{
146+
"default": "ENABLED",
147+
"description": "The state of the workgroup.",
148+
"nullable": false,
149+
"type": "string"
150+
}
151+
],
152+
"tags": [
153+
{
154+
"default": {},
155+
"description": "A map of tags to apply to the resources",
156+
"type": "map(string)",
157+
"nullable":true
158+
}
159+
]
160+
}
161+
}

0 commit comments

Comments
 (0)