-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathmain.tf
132 lines (120 loc) · 2.92 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// The ECR repository is used by CI to store the container image, which will
// then be fetched by the ECS service.
module "ecr" {
source = "../../modules/ecr-repo"
name = "rust-triagebot"
}
data "aws_ssm_parameter" "triagebot" {
for_each = toset([
"github-token",
"webhook-secret",
"zulip-token",
"zulip-api-token",
"github-app-private-key",
])
name = "/prod/ecs/triagebot/${each.value}"
}
data "aws_ssm_parameter" "database_url" {
name = "/prod/rds/shared/connection-urls/triagebot"
}
resource "aws_iam_policy" "read_database_url" {
name = "ecs--triagebot"
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Sid = "AllowReadingConnectionUrl"
Effect = "Allow"
Action = "ssm:GetParameters"
Resource = data.aws_ssm_parameter.database_url.arn
}
]
})
}
resource "aws_iam_role_policy_attachment" "read_database_url" {
role = module.ecs_task.execution_role_name
policy_arn = aws_iam_policy.read_database_url.arn
}
module "ecs_task" {
source = "../../modules/ecs-task"
name = "triagebot"
cpu = 256
memory = 512
log_retention_days = 3
ecr_repositories_arns = [
module.ecr.arn,
]
containers = <<EOF
[
{
"name": "app",
"image": "${module.ecr.url}",
"essential": true,
"portMappings": [
{
"containerPort": 80,
"hostPort": 80
}
],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/triagebot",
"awslogs-region": "us-west-1",
"awslogs-stream-prefix": "triagebot"
}
},
"environment": [
{
"name": "DISABLE_COLOR",
"value": "yes"
},
{
"name": "RUST_LOG",
"value": "triagebot=info"
}
],
"secrets": [
{
"name": "GITHUB_API_TOKEN",
"valueFrom": "${data.aws_ssm_parameter.triagebot["github-token"].arn}"
},
{
"name": "GITHUB_WEBHOOK_SECRET",
"valueFrom": "${data.aws_ssm_parameter.triagebot["webhook-secret"].arn}"
},
{
"name": "ZULIP_TOKEN",
"valueFrom": "${data.aws_ssm_parameter.triagebot["zulip-token"].arn}"
},
{
"name": "ZULIP_API_TOKEN",
"valueFrom": "${data.aws_ssm_parameter.triagebot["zulip-api-token"].arn}"
},
{
"name": "GITHUB_APP_PRIVATE_KEY",
"valueFrom": "${data.aws_ssm_parameter.triagebot["github-app-private-key"].arn}"
},
{
"name": "DATABASE_URL",
"valueFrom": "${data.aws_ssm_parameter.database_url.arn}"
}
]
}
]
EOF
}
module "ecs_service" {
source = "../../modules/ecs-service"
cluster_config = var.cluster_config
platform_version = "1.4.0"
name = "triagebot"
task_arn = module.ecs_task.arn
tasks_count = 1
http_container = "app"
http_port = 80
domains = [
var.domain_name,
"triage.rust-lang.org",
]
}