@swovohq/fuel 0.2.2-alpha.88 → 0.2.2-alpha.89
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -2
- package/dist/commands/create-app.d.ts.map +1 -1
- package/dist/commands/create-app.js +9 -3
- package/dist/commands/create-app.js.map +1 -1
- package/dist/commands/infra-deploy.d.ts.map +1 -1
- package/dist/commands/infra-deploy.js +3 -0
- package/dist/commands/infra-deploy.js.map +1 -1
- package/dist/commands/infra-init.d.ts.map +1 -1
- package/dist/commands/infra-init.js +63 -6
- package/dist/commands/infra-init.js.map +1 -1
- package/dist/infra/credentials.d.ts.map +1 -1
- package/dist/infra/credentials.js +5 -2
- package/dist/infra/credentials.js.map +1 -1
- package/dist/infra/github-client.d.ts +6 -0
- package/dist/infra/github-client.d.ts.map +1 -1
- package/dist/infra/github-client.js +30 -0
- package/dist/infra/github-client.js.map +1 -1
- package/dist/infra/github-token-link.d.ts +4 -0
- package/dist/infra/github-token-link.d.ts.map +1 -0
- package/dist/infra/github-token-link.js +28 -0
- package/dist/infra/github-token-link.js.map +1 -0
- package/dist/infra/orchestrator.d.ts +4 -1
- package/dist/infra/orchestrator.d.ts.map +1 -1
- package/dist/infra/orchestrator.js +16 -7
- package/dist/infra/orchestrator.js.map +1 -1
- package/dist/infra/preflight.d.ts.map +1 -1
- package/dist/infra/preflight.js +9 -1
- package/dist/infra/preflight.js.map +1 -1
- package/dist/infra/template-engine.d.ts +0 -4
- package/dist/infra/template-engine.d.ts.map +1 -1
- package/dist/infra/template-engine.js +36 -12
- package/dist/infra/template-engine.js.map +1 -1
- package/dist/infra/types.d.ts.map +1 -1
- package/dist/infra/types.js +58 -6
- package/dist/infra/types.js.map +1 -1
- package/dist/infra-templates/TODO-azure-prod.md +119 -0
- package/dist/infra-templates/modules/azure-container-app/main.tf +124 -0
- package/dist/infra-templates/modules/azure-container-app/outputs.tf +24 -0
- package/dist/infra-templates/modules/azure-container-app/variables.tf +80 -0
- package/dist/infra-templates/modules/azure-container-apps-environment/main.tf +18 -0
- package/dist/infra-templates/modules/azure-container-apps-environment/outputs.tf +14 -0
- package/dist/infra-templates/modules/azure-container-apps-environment/variables.tf +24 -0
- package/dist/infra-templates/modules/azure-container-registry/main.tf +10 -0
- package/dist/infra-templates/modules/azure-container-registry/outputs.tf +14 -0
- package/dist/infra-templates/modules/azure-container-registry/variables.tf +20 -0
- package/dist/infra-templates/modules/azure-front-door/main.tf +80 -0
- package/dist/infra-templates/modules/azure-front-door/outputs.tf +20 -0
- package/dist/infra-templates/modules/azure-front-door/variables.tf +26 -0
- package/dist/infra-templates/modules/azure-github-oidc/main.tf +48 -0
- package/dist/infra-templates/modules/azure-github-oidc/outputs.tf +9 -0
- package/dist/infra-templates/modules/azure-github-oidc/variables.tf +69 -0
- package/dist/infra-templates/modules/azure-key-vault/main.tf +21 -0
- package/dist/infra-templates/modules/azure-key-vault/outputs.tf +11 -0
- package/dist/infra-templates/modules/azure-key-vault/variables.tf +43 -0
- package/dist/infra-templates/modules/azure-monitor/main.tf +29 -0
- package/dist/infra-templates/modules/azure-monitor/outputs.tf +17 -0
- package/dist/infra-templates/modules/azure-monitor/variables.tf +32 -0
- package/dist/infra-templates/modules/azure-network/main.tf +134 -0
- package/dist/infra-templates/modules/azure-network/outputs.tf +44 -0
- package/dist/infra-templates/modules/azure-network/variables.tf +56 -0
- package/dist/infra-templates/modules/azure-postgresql-flexible/main.tf +34 -0
- package/dist/infra-templates/modules/azure-postgresql-flexible/outputs.tf +20 -0
- package/dist/infra-templates/modules/azure-postgresql-flexible/variables.tf +54 -0
- package/dist/infra-templates/modules/azure-redis-cache/main.tf +32 -0
- package/dist/infra-templates/modules/azure-redis-cache/outputs.tf +15 -0
- package/dist/infra-templates/modules/azure-redis-cache/variables.tf +30 -0
- package/dist/infra-templates/modules/azure-resource-group/main.tf +5 -0
- package/dist/infra-templates/modules/azure-resource-group/outputs.tf +11 -0
- package/dist/infra-templates/modules/azure-resource-group/variables.tf +16 -0
- package/dist/infra-templates/modules/azure-sql-database/main.tf +63 -0
- package/dist/infra-templates/modules/azure-sql-database/outputs.tf +20 -0
- package/dist/infra-templates/modules/azure-sql-database/variables.tf +78 -0
- package/dist/infra-templates/modules/azure-storage-account/main.tf +13 -0
- package/dist/infra-templates/modules/azure-storage-account/outputs.tf +16 -0
- package/dist/infra-templates/modules/azure-storage-account/variables.tf +38 -0
- package/dist/infra-templates/modules/cloud-watch/event-bridge.tf +15 -0
- package/dist/infra-templates/modules/cloud-watch/lambda.tf +84 -0
- package/dist/infra-templates/modules/cloud-watch/lambda_function.zip +0 -0
- package/dist/infra-templates/modules/cloud-watch/lambda_function_deploy.zip +0 -0
- package/dist/infra-templates/modules/cloud-watch/main.tf +156 -0
- package/dist/infra-templates/modules/cloud-watch/sns.tf +3 -0
- package/dist/infra-templates/modules/cloud-watch/variables.tf +38 -0
- package/dist/infra-templates/modules/ecs-core/alb.tf +126 -0
- package/dist/infra-templates/modules/ecs-core/cloudwatch.tf +48 -0
- package/dist/infra-templates/modules/ecs-core/iam.tf +95 -0
- package/dist/infra-templates/modules/ecs-core/main.tf +12 -0
- package/dist/infra-templates/modules/ecs-core/outputs.tf +44 -0
- package/dist/infra-templates/modules/ecs-core/secrets.tf +9 -0
- package/dist/infra-templates/modules/ecs-core/security_groups.tf +73 -0
- package/dist/infra-templates/modules/ecs-core/variables.tf +96 -0
- package/dist/infra-templates/modules/ecs-service/ecs_autoscaling.tf +51 -0
- package/dist/infra-templates/modules/ecs-service/ecs_service.tf +39 -0
- package/dist/infra-templates/modules/ecs-service/ecs_task_definition.tf +56 -0
- package/dist/infra-templates/modules/ecs-service/variables.tf +170 -0
- package/dist/infra-templates/modules/elastic-container-registry/main.tf +32 -0
- package/dist/infra-templates/modules/elastic-container-registry/outputs.tf +9 -0
- package/dist/infra-templates/modules/elastic-container-registry/variables.tf +25 -0
- package/dist/infra-templates/modules/github-oidc-role/main.tf +46 -0
- package/dist/infra-templates/modules/github-oidc-role/outputs.tf +4 -0
- package/dist/infra-templates/modules/github-oidc-role/variables.tf +11 -0
- package/dist/infra-templates/modules/guardduty/main.tf +8 -0
- package/dist/infra-templates/modules/iam/main.tf +205 -0
- package/dist/infra-templates/modules/iam/outputs.tf +3 -0
- package/dist/infra-templates/modules/iam/variables.tf +4 -0
- package/dist/infra-templates/modules/random-key/main.tf +11 -0
- package/dist/infra-templates/modules/random-key/outputs.tf +4 -0
- package/dist/infra-templates/modules/random-key/variables.tf +10 -0
- package/dist/infra-templates/modules/redis/main.tf +47 -0
- package/dist/infra-templates/modules/redis/outputs.tf +8 -0
- package/dist/infra-templates/modules/redis/variables.tf +20 -0
- package/dist/infra-templates/modules/relational-database-service/main.tf +44 -0
- package/dist/infra-templates/modules/relational-database-service/outputs.tf +13 -0
- package/dist/infra-templates/modules/relational-database-service/security-group.tf +15 -0
- package/dist/infra-templates/modules/relational-database-service/variables.tf +50 -0
- package/dist/infra-templates/modules/secret/main.tf +14 -0
- package/dist/infra-templates/modules/secret/outputs.tf +3 -0
- package/dist/infra-templates/modules/secret/variables.tf +8 -0
- package/dist/infra-templates/modules/simple-storage-service/main.tf +28 -0
- package/dist/infra-templates/modules/simple-storage-service/variables.tf +4 -0
- package/dist/infra-templates/modules/vpc/data.tf +2 -0
- package/dist/infra-templates/modules/vpc/main.tf +76 -0
- package/dist/infra-templates/modules/vpc/outputs.tf +23 -0
- package/dist/infra-templates/modules/vpc/variables.tf +5 -0
- package/dist/infra-templates/package.json +6 -0
- package/dist/infra-templates/templates/azure/MANUAL_DEPLOY.md +168 -0
- package/dist/infra-templates/templates/azure/backend.tf +8 -0
- package/dist/infra-templates/templates/azure/data.tf +21 -0
- package/dist/infra-templates/templates/azure/default.tfvars +0 -0
- package/dist/infra-templates/templates/azure/locals.tf +116 -0
- package/dist/infra-templates/templates/azure/main.tf +421 -0
- package/dist/infra-templates/templates/azure/outputs.tf +40 -0
- package/dist/infra-templates/templates/azure/providers.tf +65 -0
- package/dist/infra-templates/templates/azure/variables.tf +69 -0
- package/dist/infra-templates/templates/azure/workflows/build_and_deploy.yml +155 -0
- package/dist/infra-templates/templates/azure/workflows/tests.yml +63 -0
- package/dist/infra-templates/templates/ecs/README.md +225 -0
- package/dist/infra-templates/templates/ecs/backend.tf +7 -0
- package/dist/infra-templates/templates/ecs/data.tf +6 -0
- package/dist/infra-templates/templates/ecs/default.tfvars +1 -0
- package/dist/infra-templates/templates/ecs/locals.tf +97 -0
- package/dist/infra-templates/templates/ecs/main.tf +185 -0
- package/dist/infra-templates/templates/ecs/outputs.tf +42 -0
- package/dist/infra-templates/templates/ecs/providers.tf +21 -0
- package/dist/infra-templates/templates/ecs/variables.tf +105 -0
- package/dist/infra-templates/templates/ecs/workflows/build_and_deploy.yml +188 -0
- package/dist/infra-templates/templates/ecs/workflows/tests.yml +65 -0
- package/package.json +2 -2
- package/schema/fuel.schema.json +78 -44
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
########################################################################################################################
|
|
2
|
+
## Application Load Balancer in public subnets with HTTP default listener that redirects traffic to HTTPS
|
|
3
|
+
########################################################################################################################
|
|
4
|
+
|
|
5
|
+
resource "aws_alb" "alb" {
|
|
6
|
+
name = "${var.project_name}-ALB"
|
|
7
|
+
security_groups = [aws_security_group.alb.id, var.default_security_group_id]
|
|
8
|
+
subnets = var.public_subnets
|
|
9
|
+
|
|
10
|
+
tags = {
|
|
11
|
+
Scenario = var.scenario
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
########################################################################################################################
|
|
16
|
+
## Default HTTPS listener that blocks all traffic without valid custom origin header
|
|
17
|
+
########################################################################################################################
|
|
18
|
+
|
|
19
|
+
resource "aws_alb_listener" "alb_default_listener_https" {
|
|
20
|
+
load_balancer_arn = aws_alb.alb.arn
|
|
21
|
+
port = "443"
|
|
22
|
+
protocol = "HTTPS"
|
|
23
|
+
certificate_arn = var.ingress_ssl_arn
|
|
24
|
+
|
|
25
|
+
default_action {
|
|
26
|
+
type = "forward"
|
|
27
|
+
target_group_arn = aws_alb_target_group.service_target_group.arn
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
tags = {
|
|
31
|
+
Scenario = var.scenario
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
resource "aws_alb_listener" "redirect" {
|
|
36
|
+
load_balancer_arn = aws_alb.alb.arn
|
|
37
|
+
port = "80"
|
|
38
|
+
protocol = "HTTP"
|
|
39
|
+
|
|
40
|
+
default_action {
|
|
41
|
+
type = "redirect"
|
|
42
|
+
|
|
43
|
+
redirect {
|
|
44
|
+
port = "443"
|
|
45
|
+
protocol = "HTTPS"
|
|
46
|
+
status_code = "HTTP_301"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
resource "aws_alb_listener_rule" "frontend_listener" {
|
|
52
|
+
for_each = {
|
|
53
|
+
for index, app in var.apps : app.app_name => app
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
listener_arn = aws_alb_listener.alb_default_listener_https.arn
|
|
57
|
+
|
|
58
|
+
action {
|
|
59
|
+
type = "forward"
|
|
60
|
+
target_group_arn = aws_alb_target_group.app_service_target_group[each.key].arn
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
condition {
|
|
64
|
+
host_header {
|
|
65
|
+
values = ["${each.value.domain}"]
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
########################################################################################################################
|
|
71
|
+
## Target Group for our service
|
|
72
|
+
########################################################################################################################
|
|
73
|
+
|
|
74
|
+
resource "aws_alb_target_group" "service_target_group" {
|
|
75
|
+
name = "${var.project_name}-TargetGroup"
|
|
76
|
+
port = var.container_port
|
|
77
|
+
protocol = "HTTP"
|
|
78
|
+
vpc_id = var.vpc_id
|
|
79
|
+
deregistration_delay = 5
|
|
80
|
+
target_type = "ip"
|
|
81
|
+
|
|
82
|
+
health_check {
|
|
83
|
+
healthy_threshold = 2
|
|
84
|
+
unhealthy_threshold = 2
|
|
85
|
+
interval = 60
|
|
86
|
+
matcher = var.healthcheck_matcher
|
|
87
|
+
path = var.healthcheck_endpoint
|
|
88
|
+
port = "traffic-port"
|
|
89
|
+
protocol = "HTTP"
|
|
90
|
+
timeout = 30
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
tags = {
|
|
94
|
+
Scenario = var.scenario
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
depends_on = [aws_alb.alb]
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
resource "aws_alb_target_group" "app_service_target_group" {
|
|
101
|
+
for_each = { for app in var.apps : app.app_name => app }
|
|
102
|
+
|
|
103
|
+
name = each.value.app_name
|
|
104
|
+
port = each.value.port
|
|
105
|
+
protocol = "HTTP"
|
|
106
|
+
vpc_id = var.vpc_id
|
|
107
|
+
deregistration_delay = 5
|
|
108
|
+
target_type = "ip"
|
|
109
|
+
|
|
110
|
+
health_check {
|
|
111
|
+
healthy_threshold = 2
|
|
112
|
+
unhealthy_threshold = 2
|
|
113
|
+
interval = 90
|
|
114
|
+
matcher = var.healthcheck_matcher
|
|
115
|
+
path = each.value.health_check_path
|
|
116
|
+
port = "traffic-port"
|
|
117
|
+
protocol = "HTTP"
|
|
118
|
+
timeout = 60
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
tags = {
|
|
122
|
+
Scenario = var.scenario
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
depends_on = [aws_alb.alb]
|
|
126
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# logs.tf
|
|
2
|
+
|
|
3
|
+
# Set up CloudWatch group and log stream and retain logs for 30 days
|
|
4
|
+
resource "aws_cloudwatch_log_group" "cb_log_group" {
|
|
5
|
+
name = var.log_group_name
|
|
6
|
+
retention_in_days = 30
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
resource "aws_cloudwatch_log_stream" "cb_log_stream" {
|
|
10
|
+
name = var.project_name
|
|
11
|
+
log_group_name = aws_cloudwatch_log_group.cb_log_group.name
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
resource "aws_cloudwatch_metric_alarm" "targetResponseTime" {
|
|
15
|
+
actions_enabled = true
|
|
16
|
+
alarm_name = "TargetResponseTimeALB"
|
|
17
|
+
comparison_operator = "GreaterThanThreshold"
|
|
18
|
+
datapoints_to_alarm = 1
|
|
19
|
+
|
|
20
|
+
dimensions = {
|
|
21
|
+
DBInstanceIdentifier = aws_alb.alb.arn_suffix
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
evaluation_periods = 1
|
|
25
|
+
metric_name = "TargetResponseTime"
|
|
26
|
+
namespace = "AWS/ApplicationELB"
|
|
27
|
+
period = 300
|
|
28
|
+
statistic = "Maximum"
|
|
29
|
+
threshold = 4
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
resource "aws_cloudwatch_metric_alarm" "httpCodeTarget5XXCount" {
|
|
33
|
+
actions_enabled = true
|
|
34
|
+
alarm_name = "HTTPCode_Target_5XX_Count"
|
|
35
|
+
comparison_operator = "GreaterThanThreshold"
|
|
36
|
+
datapoints_to_alarm = 1
|
|
37
|
+
|
|
38
|
+
dimensions = {
|
|
39
|
+
DBInstanceIdentifier = aws_alb.alb.arn_suffix
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
evaluation_periods = 1
|
|
43
|
+
metric_name = "HTTPCode_Target_5XX_Count"
|
|
44
|
+
namespace = "AWS/ApplicationELB"
|
|
45
|
+
period = 300
|
|
46
|
+
statistic = "Maximum"
|
|
47
|
+
threshold = 1
|
|
48
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
########################################################################################################################
|
|
2
|
+
## IAM Role for ECS Task execution
|
|
3
|
+
########################################################################################################################
|
|
4
|
+
|
|
5
|
+
resource "aws_iam_role" "ecs_task_execution_role" {
|
|
6
|
+
name = "${var.project_name}_ECS_TaskExecutionRole"
|
|
7
|
+
assume_role_policy = data.aws_iam_policy_document.task_assume_role_policy.json
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
tags = {
|
|
11
|
+
Scenario = var.scenario
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
data "aws_iam_policy_document" "task_assume_role_policy" {
|
|
16
|
+
statement {
|
|
17
|
+
actions = ["sts:AssumeRole"]
|
|
18
|
+
|
|
19
|
+
principals {
|
|
20
|
+
type = "Service"
|
|
21
|
+
identifiers = ["ecs-tasks.amazonaws.com"]
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
resource "aws_iam_role_policy_attachment" "ecs_task_execution_secrets_role_policy" {
|
|
28
|
+
role = aws_iam_role.ecs_task_execution_role.name
|
|
29
|
+
policy_arn = "arn:aws:iam::aws:policy/SecretsManagerReadWrite"
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
resource "aws_iam_role_policy_attachment" "ecs_task_execution_role_policy" {
|
|
33
|
+
role = aws_iam_role.ecs_task_execution_role.name
|
|
34
|
+
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
########################################################################################################################
|
|
38
|
+
## IAM Role for ECS Task
|
|
39
|
+
########################################################################################################################
|
|
40
|
+
|
|
41
|
+
# Create an IAM policy
|
|
42
|
+
resource "aws_iam_policy" "ecs_task_policy" {
|
|
43
|
+
name = "${var.project_name}-ecs-task-policy"
|
|
44
|
+
|
|
45
|
+
policy = jsonencode({
|
|
46
|
+
"Version": "2012-10-17",
|
|
47
|
+
"Statement": [
|
|
48
|
+
{
|
|
49
|
+
"Effect": "Allow",
|
|
50
|
+
"Action": [
|
|
51
|
+
"ecr:GetAuthorizationToken",
|
|
52
|
+
"ecr:BatchCheckLayerAvailability",
|
|
53
|
+
"ecr:GetDownloadUrlForLayer",
|
|
54
|
+
"ecr:BatchGetImage",
|
|
55
|
+
"ecs:ExecuteCommand",
|
|
56
|
+
"ssmmessages:CreateControlChannel",
|
|
57
|
+
"ssmmessages:CreateDataChannel",
|
|
58
|
+
"ssmmessages:OpenControlChannel",
|
|
59
|
+
"ssmmessages:OpenDataChannel",
|
|
60
|
+
"logs:CreateLogStream",
|
|
61
|
+
"logs:PutLogEvents"
|
|
62
|
+
],
|
|
63
|
+
"Resource": "*"
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
tags = {
|
|
69
|
+
Scenario = var.scenario
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
resource "aws_iam_role" "task_exec_role" {
|
|
74
|
+
name = "${var.project_name}-ecs-task-role"
|
|
75
|
+
|
|
76
|
+
assume_role_policy = jsonencode({
|
|
77
|
+
"Version": "2012-10-17",
|
|
78
|
+
"Statement": [
|
|
79
|
+
{
|
|
80
|
+
"Effect": "Allow",
|
|
81
|
+
"Principal": {
|
|
82
|
+
"Service": "ecs-tasks.amazonaws.com"
|
|
83
|
+
},
|
|
84
|
+
"Action": "sts:AssumeRole"
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
# Attach the IAM policy to the IAM role
|
|
91
|
+
resource "aws_iam_policy_attachment" "iam_role_policy_attachment" {
|
|
92
|
+
name = "Policy Attachement"
|
|
93
|
+
policy_arn = aws_iam_policy.ecs_task_policy.arn
|
|
94
|
+
roles = [aws_iam_role.task_exec_role.name]
|
|
95
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
########################################################################################################################
|
|
2
|
+
## Creates an ECS Cluster
|
|
3
|
+
########################################################################################################################
|
|
4
|
+
|
|
5
|
+
resource "aws_ecs_cluster" "default" {
|
|
6
|
+
name = var.project_name
|
|
7
|
+
|
|
8
|
+
tags = {
|
|
9
|
+
Name = "${var.project_name}_ECSCluster"
|
|
10
|
+
Scenario = var.scenario
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
output "alb_dns" {
|
|
2
|
+
description = "The CNAME for the ALB"
|
|
3
|
+
value = aws_alb.alb.dns_name
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
output "ecs_log_group_name" {
|
|
7
|
+
description = "The name of the cloudwatch log group for ECS"
|
|
8
|
+
value = aws_cloudwatch_log_group.cb_log_group.name
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
output "ecs_task_execution_role_arn" {
|
|
12
|
+
description = "The ARN of the IAM execution role"
|
|
13
|
+
value = aws_iam_role.ecs_task_execution_role.arn
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
output "ecs_task_role_arn" {
|
|
17
|
+
description = "The ARN of the IAM rask role"
|
|
18
|
+
value = aws_iam_role.task_exec_role.arn
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
output "ecs_cluster_id" {
|
|
22
|
+
description = "The ARN of the IAM execution role"
|
|
23
|
+
value = aws_ecs_cluster.default.id
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
output "ecs_container_security_group_id" {
|
|
27
|
+
description = "ECS Container Security Group ID"
|
|
28
|
+
value = aws_security_group.ecs_container_instance.id
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
output "ecs_cluster_name" {
|
|
32
|
+
description = "The name of the cluster"
|
|
33
|
+
value = aws_ecs_cluster.default.name
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
output "ecs_secret_arn" {
|
|
37
|
+
description = "ARN of the secrets for the app"
|
|
38
|
+
value = aws_secretsmanager_secret.secret.arn
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
output "aws_alb_target_groups" {
|
|
42
|
+
description = "ALB target groups"
|
|
43
|
+
value = aws_alb_target_group.app_service_target_group
|
|
44
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
resource "aws_security_group" "ecs_container_instance" {
|
|
2
|
+
name = "${var.project_name}_ECS_Task_SecurityGroup"
|
|
3
|
+
description = "Security group for ECS task running on Fargate"
|
|
4
|
+
vpc_id = var.vpc_id
|
|
5
|
+
|
|
6
|
+
ingress {
|
|
7
|
+
description = "Allow ingress traffic from ALB on HTTP only"
|
|
8
|
+
from_port = var.container_port
|
|
9
|
+
to_port = var.container_port
|
|
10
|
+
protocol = "tcp"
|
|
11
|
+
security_groups = [aws_security_group.alb.id]
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
egress {
|
|
15
|
+
description = "Allow all egress traffic"
|
|
16
|
+
from_port = 0
|
|
17
|
+
to_port = 0
|
|
18
|
+
protocol = -1
|
|
19
|
+
cidr_blocks = ["0.0.0.0/0"]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
tags = {
|
|
23
|
+
Name = "${var.project_name}_ECS_Task_SecurityGroup"
|
|
24
|
+
Scenario = var.scenario
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
resource "aws_security_group" "alb" {
|
|
29
|
+
name = "${var.project_name}_ALB_SecurityGroup"
|
|
30
|
+
description = "Security group for ALB"
|
|
31
|
+
vpc_id = var.vpc_id
|
|
32
|
+
revoke_rules_on_delete = true
|
|
33
|
+
|
|
34
|
+
tags = {
|
|
35
|
+
Name = "${var.project_name}_ALB_SecurityGroup"
|
|
36
|
+
Scenario = var.scenario
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
# ------------------------------------------------------------------------------
|
|
41
|
+
# Alb Security Group Rules - INBOUND
|
|
42
|
+
# ------------------------------------------------------------------------------
|
|
43
|
+
resource "aws_security_group_rule" "alb_http_ingress" {
|
|
44
|
+
type = "ingress"
|
|
45
|
+
from_port = 80
|
|
46
|
+
to_port = 80
|
|
47
|
+
protocol = "TCP"
|
|
48
|
+
description = "Allow http inbound traffic from internet"
|
|
49
|
+
security_group_id = aws_security_group.alb.id
|
|
50
|
+
cidr_blocks = ["0.0.0.0/0"]
|
|
51
|
+
}
|
|
52
|
+
resource "aws_security_group_rule" "alb_https_ingress" {
|
|
53
|
+
type = "ingress"
|
|
54
|
+
from_port = 443
|
|
55
|
+
to_port = 443
|
|
56
|
+
protocol = "TCP"
|
|
57
|
+
description = "Allow https inbound traffic from internet"
|
|
58
|
+
security_group_id = aws_security_group.alb.id
|
|
59
|
+
cidr_blocks = ["0.0.0.0/0"]
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
# ------------------------------------------------------------------------------
|
|
63
|
+
# Alb Security Group Rules - OUTBOUND
|
|
64
|
+
# ------------------------------------------------------------------------------
|
|
65
|
+
resource "aws_security_group_rule" "alb_egress" {
|
|
66
|
+
type = "egress"
|
|
67
|
+
from_port = 0
|
|
68
|
+
to_port = 0
|
|
69
|
+
protocol = "-1"
|
|
70
|
+
description = "Allow outbound traffic from alb"
|
|
71
|
+
security_group_id = aws_security_group.alb.id
|
|
72
|
+
cidr_blocks = ["0.0.0.0/0"]
|
|
73
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
|
|
2
|
+
########################################################################################################################
|
|
3
|
+
## Service variables
|
|
4
|
+
########################################################################################################################
|
|
5
|
+
|
|
6
|
+
variable "ingress_ssl_arn" {
|
|
7
|
+
description = "ACM ARN"
|
|
8
|
+
type = string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
variable "namespace" {
|
|
12
|
+
description = "Namespace for resource names"
|
|
13
|
+
type = string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
variable "project_name" {
|
|
17
|
+
description = "A Docker image-compatible name for the service"
|
|
18
|
+
type = string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
variable "scenario" {
|
|
22
|
+
description = "Scenario name for tags"
|
|
23
|
+
default = "scenario-ecs-fargate"
|
|
24
|
+
type = string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
########################################################################################################################
|
|
28
|
+
## Cloudwatch
|
|
29
|
+
########################################################################################################################
|
|
30
|
+
|
|
31
|
+
variable "retention_in_days" {
|
|
32
|
+
description = "Retention period for Cloudwatch logs"
|
|
33
|
+
default = 7
|
|
34
|
+
type = number
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
########################################################################################################################
|
|
38
|
+
## ALB
|
|
39
|
+
########################################################################################################################
|
|
40
|
+
|
|
41
|
+
variable "healthcheck_endpoint" {
|
|
42
|
+
description = "Endpoint for ALB healthcheck"
|
|
43
|
+
type = string
|
|
44
|
+
default = "/"
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
variable "healthcheck_matcher" {
|
|
48
|
+
description = "HTTP status code matcher for healthcheck"
|
|
49
|
+
type = string
|
|
50
|
+
default = "200-299"
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
variable "aws_region" {
|
|
54
|
+
description = "AWS Region"
|
|
55
|
+
type = string
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
variable "vpc_id" {
|
|
59
|
+
description = "VPC id"
|
|
60
|
+
type = string
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
variable "public_subnets" {
|
|
64
|
+
description = "The public subnets for ingress resources."
|
|
65
|
+
default = ""
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
variable "private_subnets" {
|
|
69
|
+
description = "The private subnets for ingress resources."
|
|
70
|
+
default = ""
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
variable "default_security_group_id" {
|
|
74
|
+
description = "VPC Security Group"
|
|
75
|
+
type = string
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
variable "container_port" {
|
|
79
|
+
description = "Port of the container"
|
|
80
|
+
type = number
|
|
81
|
+
default = 3000
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
variable "apps" {
|
|
85
|
+
description = "An array of apps from config.json"
|
|
86
|
+
type = set(object({
|
|
87
|
+
app_name = string
|
|
88
|
+
domain = string
|
|
89
|
+
port = number
|
|
90
|
+
health_check_path = string
|
|
91
|
+
}))
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
variable "log_group_name" {
|
|
95
|
+
description = "CloudWatch log group name"
|
|
96
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
########################################################################################################################
|
|
2
|
+
## Define Target Tracking on ECS Cluster Task level
|
|
3
|
+
########################################################################################################################
|
|
4
|
+
|
|
5
|
+
resource "aws_appautoscaling_target" "ecs_target" {
|
|
6
|
+
max_capacity = var.ecs_task_max_count
|
|
7
|
+
min_capacity = var.ecs_task_min_count
|
|
8
|
+
resource_id = "service/${var.ecs_cluster_name}/${aws_ecs_service.backend_service.name}"
|
|
9
|
+
scalable_dimension = "ecs:service:DesiredCount"
|
|
10
|
+
service_namespace = "ecs"
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
########################################################################################################################
|
|
14
|
+
## Policy for CPU tracking
|
|
15
|
+
########################################################################################################################
|
|
16
|
+
|
|
17
|
+
resource "aws_appautoscaling_policy" "ecs_cpu_policy" {
|
|
18
|
+
name = "${var.app_name}_CPUTargetTrackingScaling"
|
|
19
|
+
policy_type = "TargetTrackingScaling"
|
|
20
|
+
resource_id = aws_appautoscaling_target.ecs_target.resource_id
|
|
21
|
+
scalable_dimension = aws_appautoscaling_target.ecs_target.scalable_dimension
|
|
22
|
+
service_namespace = aws_appautoscaling_target.ecs_target.service_namespace
|
|
23
|
+
|
|
24
|
+
target_tracking_scaling_policy_configuration {
|
|
25
|
+
target_value = var.cpu_target_tracking_desired_value
|
|
26
|
+
|
|
27
|
+
predefined_metric_specification {
|
|
28
|
+
predefined_metric_type = "ECSServiceAverageCPUUtilization"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
########################################################################################################################
|
|
34
|
+
## Policy for memory tracking
|
|
35
|
+
########################################################################################################################
|
|
36
|
+
|
|
37
|
+
resource "aws_appautoscaling_policy" "ecs_memory_policy" {
|
|
38
|
+
name = "${var.app_name}_MemoryTargetTrackingScaling"
|
|
39
|
+
policy_type = "TargetTrackingScaling"
|
|
40
|
+
resource_id = aws_appautoscaling_target.ecs_target.resource_id
|
|
41
|
+
scalable_dimension = aws_appautoscaling_target.ecs_target.scalable_dimension
|
|
42
|
+
service_namespace = aws_appautoscaling_target.ecs_target.service_namespace
|
|
43
|
+
|
|
44
|
+
target_tracking_scaling_policy_configuration {
|
|
45
|
+
target_value = var.memory_target_tracking_desired_value
|
|
46
|
+
|
|
47
|
+
predefined_metric_specification {
|
|
48
|
+
predefined_metric_type = "ECSServiceAverageMemoryUtilization"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
resource "aws_ecs_service" "backend_service" {
|
|
2
|
+
name = "${var.app_name}"
|
|
3
|
+
cluster = var.ecs_cluster_id
|
|
4
|
+
task_definition = aws_ecs_task_definition.backend_task_definition.arn
|
|
5
|
+
desired_count = var.ecs_task_desired_count
|
|
6
|
+
deployment_minimum_healthy_percent = var.ecs_task_deployment_minimum_healthy_percent
|
|
7
|
+
deployment_maximum_percent = var.ecs_task_deployment_maximum_percent
|
|
8
|
+
launch_type = "FARGATE"
|
|
9
|
+
enable_execute_command = true
|
|
10
|
+
|
|
11
|
+
dynamic "load_balancer" {
|
|
12
|
+
for_each = var.connect_to_alb == true ? [1]: []
|
|
13
|
+
|
|
14
|
+
content {
|
|
15
|
+
target_group_arn = var.aws_alb_target_group_arn
|
|
16
|
+
container_name = var.app_name
|
|
17
|
+
container_port = var.container_port
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
network_configuration {
|
|
22
|
+
security_groups = [var.ecs_container_security_group_id, var.default_security_group_id]
|
|
23
|
+
subnets = var.private_subnets
|
|
24
|
+
assign_public_ip = false
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
deployment_circuit_breaker {
|
|
28
|
+
enable = var.ecs_circuit_breaker
|
|
29
|
+
rollback = var.ecs_rollback
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
tags = {
|
|
33
|
+
Scenario = var.scenario
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
lifecycle {
|
|
37
|
+
ignore_changes = [task_definition]
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
########################################################################################################################
|
|
2
|
+
## Creates ECS Task Definition
|
|
3
|
+
########################################################################################################################
|
|
4
|
+
|
|
5
|
+
locals {
|
|
6
|
+
secretKeys = keys(var.env_vars)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
locals {
|
|
10
|
+
secrets_list = [
|
|
11
|
+
for name in local.secretKeys : {
|
|
12
|
+
name = name
|
|
13
|
+
valueFrom = "${var.ecs_secret_arn}:${name}::"
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
resource "aws_ecs_task_definition" "backend_task_definition" {
|
|
19
|
+
family = var.app_name
|
|
20
|
+
network_mode = "awsvpc"
|
|
21
|
+
requires_compatibilities = ["FARGATE"]
|
|
22
|
+
execution_role_arn = var.ecs_task_execution_role_arn
|
|
23
|
+
task_role_arn = var.ecs_task_role_arn
|
|
24
|
+
cpu = var.cpu_units
|
|
25
|
+
memory = var.memory
|
|
26
|
+
|
|
27
|
+
container_definitions = jsonencode([
|
|
28
|
+
{
|
|
29
|
+
name = var.app_name
|
|
30
|
+
image = var.repository_url
|
|
31
|
+
cpu = var.cpu_units
|
|
32
|
+
memory = var.memory
|
|
33
|
+
essential = true
|
|
34
|
+
portMappings = [
|
|
35
|
+
{
|
|
36
|
+
containerPort = var.container_port
|
|
37
|
+
hostPort = var.container_port
|
|
38
|
+
protocol = "tcp"
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
secrets = local.secrets_list
|
|
42
|
+
logConfiguration = {
|
|
43
|
+
logDriver = "awslogs"
|
|
44
|
+
options = {
|
|
45
|
+
"awslogs-group" = var.ecs_log_group_name
|
|
46
|
+
"awslogs-region" = var.aws_region
|
|
47
|
+
"awslogs-stream-prefix" = "${var.app_name}-log-stream"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
])
|
|
52
|
+
|
|
53
|
+
tags = {
|
|
54
|
+
Scenario = var.scenario
|
|
55
|
+
}
|
|
56
|
+
}
|