Skip to content

Commit e141c09

Browse files
superset infra
0 parents  commit e141c09

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2066
-0
lines changed

.gitignore

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
2+
# Created by https://www.toptal.com/developers/gitignore/api/terraform,pycharm
3+
# Edit at https://www.toptal.com/developers/gitignore?templates=terraform,pycharm
4+
5+
### PyCharm ###
6+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
7+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
8+
9+
# User-specific stuff
10+
.idea/**/workspace.xml
11+
.idea/**/tasks.xml
12+
.idea/**/usage.statistics.xml
13+
.idea/**/dictionaries
14+
.idea/**/shelf
15+
16+
# Generated files
17+
.idea/**/contentModel.xml
18+
19+
# Sensitive or high-churn files
20+
.idea/**/dataSources/
21+
.idea/**/dataSources.ids
22+
.idea/**/dataSources.local.xml
23+
.idea/**/sqlDataSources.xml
24+
.idea/**/dynamic.xml
25+
.idea/**/uiDesigner.xml
26+
.idea/**/dbnavigator.xml
27+
28+
# Gradle
29+
.idea/**/gradle.xml
30+
.idea/**/libraries
31+
32+
# Gradle and Maven with auto-import
33+
# When using Gradle or Maven with auto-import, you should exclude module files,
34+
# since they will be recreated, and may cause churn. Uncomment if using
35+
# auto-import.
36+
# .idea/artifacts
37+
# .idea/compiler.xml
38+
# .idea/jarRepositories.xml
39+
# .idea/modules.xml
40+
# .idea/*.iml
41+
# .idea/modules
42+
# *.iml
43+
# *.ipr
44+
45+
# CMake
46+
cmake-build-*/
47+
48+
# Mongo Explorer plugin
49+
.idea/**/mongoSettings.xml
50+
51+
# File-based project format
52+
*.iws
53+
54+
# IntelliJ
55+
out/
56+
57+
# mpeltonen/sbt-idea plugin
58+
.idea_modules/
59+
60+
# JIRA plugin
61+
atlassian-ide-plugin.xml
62+
63+
# Cursive Clojure plugin
64+
.idea/replstate.xml
65+
66+
# Crashlytics plugin (for Android Studio and IntelliJ)
67+
com_crashlytics_export_strings.xml
68+
crashlytics.properties
69+
crashlytics-build.properties
70+
fabric.properties
71+
72+
# Editor-based Rest Client
73+
.idea/httpRequests
74+
75+
# Android studio 3.1+ serialized cache file
76+
.idea/caches/build_file_checksums.ser
77+
78+
### PyCharm Patch ###
79+
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
80+
81+
# *.iml
82+
# modules.xml
83+
# .idea/misc.xml
84+
# *.ipr
85+
86+
# Sonarlint plugin
87+
# https://plugins.jetbrains.com/plugin/7973-sonarlint
88+
.idea/**/sonarlint/
89+
90+
# SonarQube Plugin
91+
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
92+
.idea/**/sonarIssues.xml
93+
94+
# Markdown Navigator plugin
95+
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
96+
.idea/**/markdown-navigator.xml
97+
.idea/**/markdown-navigator-enh.xml
98+
.idea/**/markdown-navigator/
99+
100+
# Cache file creation bug
101+
# See https://youtrack.jetbrains.com/issue/JBR-2257
102+
.idea/$CACHE_FILE$
103+
104+
# CodeStream plugin
105+
# https://plugins.jetbrains.com/plugin/12206-codestream
106+
.idea/codestream.xml
107+
108+
### Terraform ###
109+
# Local .terraform directories
110+
**/.terraform/*
111+
.terraform.lock.hcl
112+
# .tfstate files
113+
*.tfstate
114+
*.tfstate.*
115+
*.tfvars
116+
117+
# Crash log files
118+
crash.log
119+
120+
# Ignore any .tfvars files that are generated automatically for each Terraform run. Most
121+
# .tfvars files are managed as part of configuration and so should be included in
122+
# version control.
123+
#
124+
# example.tfvars
125+
126+
# Ignore override files as they are usually used to override resources locally and so
127+
# are not checked in
128+
override.tf
129+
override.tf.json
130+
*_override.tf
131+
*_override.tf.json
132+
133+
# SNOWFLAKE
134+
135+
*snowsql*.log
136+
*idea*
137+
138+
# Include override files you do wish to add to version control using negated pattern
139+
# !example_override.tf
140+
141+
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
142+
# example: *tfplan*
143+
144+
# End of https://www.toptal.com/developers/gitignore/api/terraform,pycharm

README.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<img src="https://github.com/apache/superset/raw/master/superset-frontend/src/assets/branding/superset-logo-horiz-apache.png" alt="Superset" width="500"/>
2+
A modern, enterprise-ready business intelligence web application.
3+
4+
### Overview
5+
6+
Preparing the AWS Infrastructure for Superset
7+
8+
### Usage
9+
10+
```hcl
11+
module "superset-db" {
12+
source = "../../../stacks/aws/superset-db"
13+
prefix = local.prefix
14+
vpc_id = module.base.vpc_id
15+
identifier = var.db_identifier
16+
allocated_storage = var.allocated_storage
17+
cidr_block = module.base.cidr_block
18+
db_config = var.superset_db_config
19+
subnet_ids = module.base.private_subnet_ids
20+
kms = module.base.kms_arn
21+
instance_class = var.instance_class
22+
security_group = [
23+
module.base.default_sg_id,
24+
module.superset-core.ecs_service_security_group_id,
25+
module.superset-core.app_service_security_group_id,
26+
module.superset-core.worker_beat_service_security_group_id,
27+
data.terraform_remote_state.east1_adm.outputs.argo_sg_id
28+
]
29+
}
30+
module "superset-redis" {
31+
source = "../../../modules/aws/redis"
32+
prefix = local.prefix
33+
common_tags = local.common_tags
34+
vpc_id = module.base.vpc_id
35+
private_subnet_ids = module.base.private_subnet_ids
36+
node_type = var.node_type
37+
parameter_group_name = var.parameter_group_name
38+
engine_version = var.engine_version
39+
port = 6379
40+
allowed_security_groups = {
41+
"worker" = module.superset-core.ecs_service_security_group_id
42+
"app" = module.superset-core.app_service_security_group_id
43+
"worker_beat" = module.superset-core.worker_beat_service_security_group_id
44+
}
45+
}
46+
module "superset-core" {
47+
source = "../../../stacks/aws/superset-core-apps"
48+
repository_name = join("-", [local.prefix, "superset"])
49+
prefix = local.prefix
50+
common_tags = local.common_tags
51+
kms_arn = module.base.kms_arn
52+
vpc_id = module.base.vpc_id
53+
private_subnet_ids = module.base.private_subnet_ids
54+
service_discovery = module.base.service_discovery
55+
ecs_cluster = module.base.ecs_cluster
56+
env_vars = var.env_vars
57+
public_alb = module.base.public_alb
58+
worker_ecs_params = {
59+
desired_count = 1
60+
cpu = 512
61+
memory = 1024
62+
port = 8088
63+
container_name = "superset-wrk"
64+
}
65+
worker_beat_ecs_params = {
66+
desired_count = 1
67+
cpu = 512
68+
memory = 1024
69+
port = 8088
70+
container_name = "superset-beat"
71+
}
72+
app_ecs_params = {
73+
desired_count = 1
74+
cpu = 2048
75+
memory = 4096
76+
port = 8088
77+
container_name = "superset-app"
78+
}
79+
alb_security_group = module.base.public_alb.sg_id
80+
ssm_role_arn = data.terraform_remote_state.east1_adm.outputs.ssm_role_arn
81+
}
82+
```
83+
84+
### Requirements
85+
86+
| Name | Version |
87+
| --------- | --------- |
88+
| terraform | >= 0.15.0 |
89+
| aws | = 3.65.0 |
90+
91+
### Providers
92+
93+
| Name | Version |
94+
| ---- | -------- |
95+
| aws | = 3.65.0 |
96+
97+
### Inputs
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
resource "aws_ecr_lifecycle_policy" "this" {
2+
repository = aws_ecr_repository.this.name
3+
4+
policy = <<EOF
5+
{
6+
"rules": [
7+
{
8+
"rulePriority": 1,
9+
"description": "Keep images tagged as prod for 1 year",
10+
"selection": {
11+
"tagStatus": "tagged",
12+
"tagPrefixList": ["prod"],
13+
"countType": "sinceImagePushed",
14+
"countUnit": "days",
15+
"countNumber": 365
16+
},
17+
"action": {
18+
"type": "expire"
19+
}
20+
},
21+
{
22+
"rulePriority": 5,
23+
"description": "Expire images older than 30 days",
24+
"selection": {
25+
"tagStatus": "any",
26+
"countType": "sinceImagePushed",
27+
"countUnit": "days",
28+
"countNumber": 30
29+
},
30+
"action": {
31+
"type": "expire"
32+
}
33+
}
34+
]
35+
}
36+
EOF
37+
}

modules/aws/ecr/ecr_repository.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
resource "aws_ecr_repository" "this" {
2+
name = var.repository_name
3+
4+
image_scanning_configuration {
5+
scan_on_push = true
6+
}
7+
}

modules/aws/ecr/input.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
variable "repository_name" {
2+
type = string
3+
}

modules/aws/ecr/output.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
output "repository_url" {
2+
value = aws_ecr_repository.this.repository_url
3+
}

modules/aws/ecs/cloudwatch_logs.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
resource "aws_cloudwatch_log_group" "main" {
2+
name = "/aws/ecs/${local.prefix}"
3+
retention_in_days = local.common_tags["env"] == "prd" ? 0 : 30
4+
kms_key_id = var.kms_arn
5+
6+
tags = local.common_tags
7+
}

modules/aws/ecs/data.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
data "aws_caller_identity" "current" {
2+
}
3+
4+
data "aws_ecs_task_definition" "default" {
5+
task_definition = aws_ecs_task_definition.default.family
6+
7+
depends_on = [aws_ecs_task_definition.default]
8+
}
9+
10+
data "aws_iam_policy" "AmazonECSTaskExecutionRolePolicy" {
11+
arn = "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
12+
}

modules/aws/ecs/ecs_service.tf

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
resource "aws_ecs_service" "default" {
2+
name = local.prefix
3+
cluster = var.ecs_cluster["name"]
4+
task_definition = aws_ecs_task_definition.default.arn
5+
desired_count = var.desired_count
6+
launch_type = "FARGATE"
7+
platform_version = var.platform_version
8+
enable_execute_command = true
9+
dynamic "service_registries" {
10+
for_each = var.service_discovery != null ? var.service_discovery : {}
11+
content {
12+
registry_arn = aws_service_discovery_service._[0].arn
13+
container_name = var.container_name
14+
}
15+
}
16+
network_configuration {
17+
security_groups = [aws_security_group.ecs-service.id]
18+
subnets = var.ecs_service_subnet_ids
19+
}
20+
dynamic "load_balancer" {
21+
for_each = var.alb_target_group_id != null ? var.alb_target_group_id : {}
22+
content {
23+
container_name = load_balancer.value["container_name"]
24+
container_port = load_balancer.value["container_port"]
25+
target_group_arn = load_balancer.value["alb_target_group_id"]
26+
}
27+
}
28+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
resource "aws_ecs_task_definition" "default" {
2+
family = local.prefix
3+
network_mode = "awsvpc"
4+
cpu = var.cpu
5+
memory = var.memory
6+
requires_compatibilities = ["FARGATE"]
7+
task_role_arn = aws_iam_role.ecs-role.arn
8+
execution_role_arn = aws_iam_role.ecs-role.arn
9+
container_definitions = var.container_definitions
10+
volume {
11+
name = "superset_app"
12+
efs_volume_configuration {
13+
file_system_id = var.file_system_id
14+
15+
transit_encryption = "ENABLED"
16+
transit_encryption_port = 2999
17+
18+
authorization_config {
19+
access_point_id = var.efs_access_point_id
20+
iam = "ENABLED"
21+
}
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)