@hasna/uptime 0.1.6 → 0.1.8
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/.dockerignore +0 -1
- package/CHANGELOG.md +35 -1
- package/Dockerfile +2 -1
- package/Dockerfile.package +22 -0
- package/README.md +13 -1
- package/dist/api.d.ts +2 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +81 -12
- package/dist/cli/index.js +148 -51
- package/dist/cloud-plan.d.ts +15 -4
- package/dist/cloud-plan.d.ts.map +1 -1
- package/dist/cloud-plan.js +55 -35
- package/dist/index.js +136 -47
- package/dist/mcp/index.js +38 -8
- package/dist/service.d.ts +1 -1
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +38 -8
- package/dist/store.d.ts +3 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +40 -9
- package/docs/aws-deployment-runbook.md +44 -22
- package/infra/aws/README.md +27 -6
- package/infra/aws/main.tf +374 -36
- package/infra/aws/outputs.tf +20 -0
- package/infra/aws/terraform.tfvars.example +13 -12
- package/infra/aws/variables.tf +48 -22
- package/package.json +2 -1
package/infra/aws/main.tf
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
terraform {
|
|
2
|
-
required_version = ">= 1.
|
|
2
|
+
required_version = ">= 1.9.0"
|
|
3
3
|
|
|
4
4
|
required_providers {
|
|
5
5
|
aws = {
|
|
@@ -13,40 +13,43 @@ provider "aws" {
|
|
|
13
13
|
region = var.region
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
data "aws_caller_identity" "current" {}
|
|
17
|
+
|
|
16
18
|
locals {
|
|
17
|
-
prefix
|
|
18
|
-
container_port
|
|
19
|
-
evidence_bucket
|
|
19
|
+
prefix = "${var.service_name}-${var.stage}"
|
|
20
|
+
container_port = 3899
|
|
21
|
+
evidence_bucket = "hasna-${var.stage}-${var.service_name}-evidence"
|
|
22
|
+
efs_uid = 10001
|
|
23
|
+
efs_gid = 10001
|
|
24
|
+
hosted_sqlite_db_path = "/data/uptime/uptime.db"
|
|
25
|
+
efs_enabled_services = toset(["web"])
|
|
26
|
+
use_alb_https = var.protected_access_mode == "alb_https_cert"
|
|
27
|
+
use_cloudfront = var.protected_access_mode == "cloudfront_default_domain"
|
|
20
28
|
services = {
|
|
21
29
|
web = {
|
|
22
30
|
desired_count = lookup(var.desired_counts, "web", 0)
|
|
23
|
-
db_access = true
|
|
24
31
|
command = ["bun", "dist/cli/index.js", "serve", "--mode", "hosted", "--host", "0.0.0.0", "--port", tostring(local.container_port)]
|
|
25
|
-
secrets = {
|
|
32
|
+
secrets = { APP_ENV = var.app_env_secret_arn, HASNA_UPTIME_HOSTED_TOKEN = var.hosted_token_secret_arn }
|
|
26
33
|
}
|
|
27
34
|
scheduler = {
|
|
28
35
|
desired_count = lookup(var.desired_counts, "scheduler", 0)
|
|
29
|
-
db_access = true
|
|
30
36
|
command = ["bun", "dist/cli/index.js", "cloud", "plan"]
|
|
31
|
-
secrets = {
|
|
37
|
+
secrets = { APP_ENV = var.app_env_secret_arn }
|
|
32
38
|
}
|
|
33
39
|
"public-probe" = {
|
|
34
40
|
desired_count = lookup(var.desired_counts, "public-probe", 0)
|
|
35
|
-
db_access = false
|
|
36
41
|
command = ["bun", "dist/cli/index.js", "cloud", "plan"]
|
|
37
42
|
secrets = { PROBE_CONFIG = var.public_probe_secret_arn }
|
|
38
43
|
}
|
|
39
44
|
reporter = {
|
|
40
45
|
desired_count = lookup(var.desired_counts, "reporter", 0)
|
|
41
|
-
db_access = true
|
|
42
46
|
command = ["bun", "dist/cli/index.js", "cloud", "plan"]
|
|
43
|
-
secrets = {
|
|
47
|
+
secrets = { REPORTING_CONFIG = var.reporting_secret_arn }
|
|
44
48
|
}
|
|
45
49
|
migration = {
|
|
46
50
|
desired_count = lookup(var.desired_counts, "migration", 0)
|
|
47
|
-
db_access = true
|
|
48
51
|
command = ["bun", "dist/cli/index.js", "cloud", "plan"]
|
|
49
|
-
secrets = {
|
|
52
|
+
secrets = { APP_ENV = var.app_env_secret_arn }
|
|
50
53
|
}
|
|
51
54
|
}
|
|
52
55
|
tags = {
|
|
@@ -61,8 +64,13 @@ data "aws_vpc" "target" {
|
|
|
61
64
|
id = var.vpc_id
|
|
62
65
|
}
|
|
63
66
|
|
|
67
|
+
data "aws_ec2_managed_prefix_list" "cloudfront_origin_facing" {
|
|
68
|
+
count = local.use_cloudfront ? 1 : 0
|
|
69
|
+
name = "com.amazonaws.global.cloudfront.origin-facing"
|
|
70
|
+
}
|
|
71
|
+
|
|
64
72
|
resource "aws_ecr_repository" "open_uptime" {
|
|
65
|
-
name =
|
|
73
|
+
name = var.ecr_repository_name
|
|
66
74
|
image_tag_mutability = "IMMUTABLE"
|
|
67
75
|
|
|
68
76
|
image_scanning_configuration {
|
|
@@ -76,6 +84,113 @@ resource "aws_ecr_repository" "open_uptime" {
|
|
|
76
84
|
tags = local.tags
|
|
77
85
|
}
|
|
78
86
|
|
|
87
|
+
resource "aws_cloudwatch_log_group" "image_builder" {
|
|
88
|
+
name = "/aws/codebuild/${local.prefix}-image-builder"
|
|
89
|
+
retention_in_days = 14
|
|
90
|
+
kms_key_id = var.kms_key_arn
|
|
91
|
+
tags = local.tags
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
data "aws_iam_policy_document" "codebuild_assume_role" {
|
|
95
|
+
statement {
|
|
96
|
+
actions = ["sts:AssumeRole"]
|
|
97
|
+
|
|
98
|
+
principals {
|
|
99
|
+
type = "Service"
|
|
100
|
+
identifiers = ["codebuild.amazonaws.com"]
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
resource "aws_iam_role" "image_builder" {
|
|
106
|
+
name = "${local.prefix}-image-builder-role"
|
|
107
|
+
assume_role_policy = data.aws_iam_policy_document.codebuild_assume_role.json
|
|
108
|
+
tags = local.tags
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
data "aws_iam_policy_document" "image_builder" {
|
|
112
|
+
statement {
|
|
113
|
+
actions = ["ecr:GetAuthorizationToken"]
|
|
114
|
+
resources = ["*"]
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
statement {
|
|
118
|
+
actions = [
|
|
119
|
+
"ecr:BatchCheckLayerAvailability",
|
|
120
|
+
"ecr:CompleteLayerUpload",
|
|
121
|
+
"ecr:DescribeImages",
|
|
122
|
+
"ecr:DescribeRepositories",
|
|
123
|
+
"ecr:InitiateLayerUpload",
|
|
124
|
+
"ecr:PutImage",
|
|
125
|
+
"ecr:UploadLayerPart",
|
|
126
|
+
]
|
|
127
|
+
resources = [aws_ecr_repository.open_uptime.arn]
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
statement {
|
|
131
|
+
actions = [
|
|
132
|
+
"logs:CreateLogStream",
|
|
133
|
+
"logs:PutLogEvents",
|
|
134
|
+
]
|
|
135
|
+
resources = ["${aws_cloudwatch_log_group.image_builder.arn}:*"]
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
resource "aws_iam_role_policy" "image_builder" {
|
|
140
|
+
name = "${local.prefix}-image-builder-policy"
|
|
141
|
+
role = aws_iam_role.image_builder.id
|
|
142
|
+
policy = data.aws_iam_policy_document.image_builder.json
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
resource "aws_codebuild_project" "image_builder" {
|
|
146
|
+
name = "${local.prefix}-image-builder"
|
|
147
|
+
description = "Build published @hasna/uptime package into the Open Uptime ECR image"
|
|
148
|
+
service_role = aws_iam_role.image_builder.arn
|
|
149
|
+
tags = local.tags
|
|
150
|
+
|
|
151
|
+
artifacts {
|
|
152
|
+
type = "NO_ARTIFACTS"
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
environment {
|
|
156
|
+
compute_type = "BUILD_GENERAL1_SMALL"
|
|
157
|
+
image = "aws/codebuild/standard:7.0"
|
|
158
|
+
type = "LINUX_CONTAINER"
|
|
159
|
+
privileged_mode = true
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
logs_config {
|
|
163
|
+
cloudwatch_logs {
|
|
164
|
+
group_name = aws_cloudwatch_log_group.image_builder.name
|
|
165
|
+
status = "ENABLED"
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
source {
|
|
170
|
+
type = "NO_SOURCE"
|
|
171
|
+
buildspec = <<-YAML
|
|
172
|
+
version: 0.2
|
|
173
|
+
phases:
|
|
174
|
+
pre_build:
|
|
175
|
+
commands:
|
|
176
|
+
- aws --version
|
|
177
|
+
- aws ecr get-login-password --region ${var.region} | docker login --username AWS --password-stdin ${data.aws_caller_identity.current.account_id}.dkr.ecr.${var.region}.amazonaws.com
|
|
178
|
+
build:
|
|
179
|
+
commands:
|
|
180
|
+
- npm pack @hasna/uptime@${var.runtime_package_version}
|
|
181
|
+
- mkdir package
|
|
182
|
+
- tar -xzf hasna-uptime-*.tgz -C package --strip-components=1
|
|
183
|
+
- cd package
|
|
184
|
+
- docker build -f Dockerfile.package -t ${aws_ecr_repository.open_uptime.repository_url}:${var.runtime_package_version} .
|
|
185
|
+
- docker push ${aws_ecr_repository.open_uptime.repository_url}:${var.runtime_package_version}
|
|
186
|
+
- IMAGE_DIGEST=$(aws ecr describe-images --region ${var.region} --repository-name ${aws_ecr_repository.open_uptime.name} --image-ids imageTag=${var.runtime_package_version} --query 'imageDetails[0].imageDigest' --output text)
|
|
187
|
+
- printf '%s@%s\n' '${aws_ecr_repository.open_uptime.repository_url}' "$IMAGE_DIGEST"
|
|
188
|
+
YAML
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
depends_on = [aws_iam_role_policy.image_builder]
|
|
192
|
+
}
|
|
193
|
+
|
|
79
194
|
resource "aws_s3_bucket" "evidence" {
|
|
80
195
|
bucket = local.evidence_bucket
|
|
81
196
|
tags = local.tags
|
|
@@ -182,7 +297,7 @@ resource "aws_security_group" "alb" {
|
|
|
182
297
|
}
|
|
183
298
|
|
|
184
299
|
resource "aws_security_group_rule" "alb_https_ingress" {
|
|
185
|
-
count = length(var.alb_ingress_cidr_blocks) > 0 ? 1 : 0
|
|
300
|
+
count = local.use_alb_https && length(var.alb_ingress_cidr_blocks) > 0 ? 1 : 0
|
|
186
301
|
type = "ingress"
|
|
187
302
|
description = "HTTPS"
|
|
188
303
|
security_group_id = aws_security_group.alb.id
|
|
@@ -192,6 +307,17 @@ resource "aws_security_group_rule" "alb_https_ingress" {
|
|
|
192
307
|
cidr_blocks = var.alb_ingress_cidr_blocks
|
|
193
308
|
}
|
|
194
309
|
|
|
310
|
+
resource "aws_security_group_rule" "alb_http_from_cloudfront" {
|
|
311
|
+
count = local.use_cloudfront ? 1 : 0
|
|
312
|
+
type = "ingress"
|
|
313
|
+
description = "HTTP from CloudFront origin-facing ranges"
|
|
314
|
+
security_group_id = aws_security_group.alb.id
|
|
315
|
+
from_port = 80
|
|
316
|
+
to_port = 80
|
|
317
|
+
protocol = "tcp"
|
|
318
|
+
prefix_list_ids = [data.aws_ec2_managed_prefix_list.cloudfront_origin_facing[0].id]
|
|
319
|
+
}
|
|
320
|
+
|
|
195
321
|
resource "aws_security_group_rule" "alb_to_web" {
|
|
196
322
|
type = "egress"
|
|
197
323
|
description = "To Open Uptime web"
|
|
@@ -221,7 +347,7 @@ resource "aws_security_group_rule" "web_from_alb" {
|
|
|
221
347
|
|
|
222
348
|
resource "aws_security_group_rule" "web_egress" {
|
|
223
349
|
type = "egress"
|
|
224
|
-
description = "Controlled egress to AWS endpoints and
|
|
350
|
+
description = "Controlled egress to AWS endpoints and EFS"
|
|
225
351
|
security_group_id = aws_security_group.web.id
|
|
226
352
|
from_port = 0
|
|
227
353
|
to_port = 0
|
|
@@ -244,7 +370,7 @@ resource "aws_security_group_rule" "worker_egress" {
|
|
|
244
370
|
for_each = aws_security_group.worker
|
|
245
371
|
|
|
246
372
|
type = "egress"
|
|
247
|
-
description = each.key == "public-probe" ? "Public probe egress for approved public targets" : "Controlled egress to AWS endpoints
|
|
373
|
+
description = each.key == "public-probe" ? "Public probe egress for approved public targets" : "Controlled egress to AWS endpoints"
|
|
248
374
|
security_group_id = each.value.id
|
|
249
375
|
from_port = 0
|
|
250
376
|
to_port = 0
|
|
@@ -252,28 +378,124 @@ resource "aws_security_group_rule" "worker_egress" {
|
|
|
252
378
|
cidr_blocks = each.key == "public-probe" ? ["0.0.0.0/0"] : [data.aws_vpc.target.cidr_block]
|
|
253
379
|
}
|
|
254
380
|
|
|
255
|
-
resource "
|
|
381
|
+
resource "aws_security_group" "efs" {
|
|
382
|
+
name = "${local.prefix}-efs-sg"
|
|
383
|
+
description = "Open Uptime EFS data store"
|
|
384
|
+
vpc_id = data.aws_vpc.target.id
|
|
385
|
+
tags = local.tags
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
resource "aws_security_group_rule" "efs_from_web" {
|
|
256
389
|
type = "ingress"
|
|
257
|
-
|
|
258
|
-
|
|
390
|
+
description = "Open Uptime web to EFS"
|
|
391
|
+
security_group_id = aws_security_group.efs.id
|
|
392
|
+
from_port = 2049
|
|
393
|
+
to_port = 2049
|
|
259
394
|
protocol = "tcp"
|
|
260
|
-
security_group_id = var.rds_security_group_id
|
|
261
395
|
source_security_group_id = aws_security_group.web.id
|
|
262
|
-
description = "Open Uptime web to RDS"
|
|
263
396
|
}
|
|
264
397
|
|
|
265
|
-
resource "
|
|
266
|
-
|
|
267
|
-
|
|
398
|
+
resource "aws_efs_file_system" "data" {
|
|
399
|
+
creation_token = "${local.prefix}-data"
|
|
400
|
+
encrypted = true
|
|
401
|
+
kms_key_id = var.kms_key_arn
|
|
402
|
+
tags = merge(local.tags, { Name = "${local.prefix}-data" })
|
|
403
|
+
|
|
404
|
+
lifecycle_policy {
|
|
405
|
+
transition_to_ia = "AFTER_30_DAYS"
|
|
268
406
|
}
|
|
407
|
+
}
|
|
269
408
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
409
|
+
resource "aws_efs_backup_policy" "data" {
|
|
410
|
+
file_system_id = aws_efs_file_system.data.id
|
|
411
|
+
|
|
412
|
+
backup_policy {
|
|
413
|
+
status = "ENABLED"
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
resource "aws_efs_access_point" "uptime" {
|
|
418
|
+
file_system_id = aws_efs_file_system.data.id
|
|
419
|
+
|
|
420
|
+
posix_user {
|
|
421
|
+
uid = local.efs_uid
|
|
422
|
+
gid = local.efs_gid
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
root_directory {
|
|
426
|
+
path = "/uptime"
|
|
427
|
+
|
|
428
|
+
creation_info {
|
|
429
|
+
owner_uid = local.efs_uid
|
|
430
|
+
owner_gid = local.efs_gid
|
|
431
|
+
permissions = "0750"
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
tags = merge(local.tags, { Name = "${local.prefix}-uptime" })
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
resource "aws_efs_mount_target" "data" {
|
|
439
|
+
for_each = toset(var.private_subnet_ids)
|
|
440
|
+
file_system_id = aws_efs_file_system.data.id
|
|
441
|
+
subnet_id = each.value
|
|
442
|
+
security_groups = [aws_security_group.efs.id]
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
resource "aws_backup_vault" "data" {
|
|
446
|
+
name = "${local.prefix}-data"
|
|
447
|
+
kms_key_arn = var.kms_key_arn
|
|
448
|
+
tags = local.tags
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
resource "aws_backup_plan" "data" {
|
|
452
|
+
name = "${local.prefix}-data"
|
|
453
|
+
|
|
454
|
+
rule {
|
|
455
|
+
rule_name = "daily"
|
|
456
|
+
target_vault_name = aws_backup_vault.data.name
|
|
457
|
+
schedule = "cron(0 5 * * ? *)"
|
|
458
|
+
|
|
459
|
+
lifecycle {
|
|
460
|
+
delete_after = 35
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
tags = local.tags
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
data "aws_iam_policy_document" "backup_assume_role" {
|
|
468
|
+
statement {
|
|
469
|
+
actions = ["sts:AssumeRole"]
|
|
470
|
+
|
|
471
|
+
principals {
|
|
472
|
+
type = "Service"
|
|
473
|
+
identifiers = ["backup.amazonaws.com"]
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
resource "aws_iam_role" "backup" {
|
|
479
|
+
name = "${local.prefix}-backup-role"
|
|
480
|
+
assume_role_policy = data.aws_iam_policy_document.backup_assume_role.json
|
|
481
|
+
tags = local.tags
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
resource "aws_iam_role_policy_attachment" "backup" {
|
|
485
|
+
role = aws_iam_role.backup.name
|
|
486
|
+
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSBackupServiceRolePolicyForBackup"
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
resource "aws_iam_role_policy_attachment" "backup_restore" {
|
|
490
|
+
role = aws_iam_role.backup.name
|
|
491
|
+
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSBackupServiceRolePolicyForRestores"
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
resource "aws_backup_selection" "data" {
|
|
495
|
+
iam_role_arn = aws_iam_role.backup.arn
|
|
496
|
+
name = "${local.prefix}-data"
|
|
497
|
+
plan_id = aws_backup_plan.data.id
|
|
498
|
+
resources = [aws_efs_file_system.data.arn]
|
|
277
499
|
}
|
|
278
500
|
|
|
279
501
|
resource "aws_lb" "open_uptime" {
|
|
@@ -302,6 +524,7 @@ resource "aws_lb_target_group" "web" {
|
|
|
302
524
|
}
|
|
303
525
|
|
|
304
526
|
resource "aws_lb_listener" "https" {
|
|
527
|
+
count = local.use_alb_https ? 1 : 0
|
|
305
528
|
load_balancer_arn = aws_lb.open_uptime.arn
|
|
306
529
|
port = 443
|
|
307
530
|
protocol = "HTTPS"
|
|
@@ -313,8 +536,73 @@ resource "aws_lb_listener" "https" {
|
|
|
313
536
|
}
|
|
314
537
|
}
|
|
315
538
|
|
|
539
|
+
resource "aws_lb_listener" "http_cloudfront" {
|
|
540
|
+
count = local.use_cloudfront ? 1 : 0
|
|
541
|
+
load_balancer_arn = aws_lb.open_uptime.arn
|
|
542
|
+
port = 80
|
|
543
|
+
protocol = "HTTP"
|
|
544
|
+
|
|
545
|
+
default_action {
|
|
546
|
+
type = "forward"
|
|
547
|
+
target_group_arn = aws_lb_target_group.web.arn
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
resource "aws_cloudfront_distribution" "open_uptime" {
|
|
552
|
+
count = local.use_cloudfront ? 1 : 0
|
|
553
|
+
enabled = true
|
|
554
|
+
is_ipv6_enabled = true
|
|
555
|
+
comment = "Open Uptime ${local.prefix} protected HTTPS edge"
|
|
556
|
+
price_class = "PriceClass_100"
|
|
557
|
+
tags = local.tags
|
|
558
|
+
|
|
559
|
+
origin {
|
|
560
|
+
domain_name = aws_lb.open_uptime.dns_name
|
|
561
|
+
origin_id = "${local.prefix}-alb"
|
|
562
|
+
|
|
563
|
+
custom_origin_config {
|
|
564
|
+
http_port = 80
|
|
565
|
+
https_port = 443
|
|
566
|
+
origin_protocol_policy = "http-only"
|
|
567
|
+
origin_ssl_protocols = ["TLSv1.2"]
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
default_cache_behavior {
|
|
572
|
+
target_origin_id = "${local.prefix}-alb"
|
|
573
|
+
viewer_protocol_policy = "redirect-to-https"
|
|
574
|
+
compress = true
|
|
575
|
+
allowed_methods = ["GET", "HEAD", "OPTIONS", "PUT", "POST", "PATCH", "DELETE"]
|
|
576
|
+
cached_methods = ["GET", "HEAD"]
|
|
577
|
+
default_ttl = 0
|
|
578
|
+
max_ttl = 0
|
|
579
|
+
min_ttl = 0
|
|
580
|
+
|
|
581
|
+
forwarded_values {
|
|
582
|
+
query_string = true
|
|
583
|
+
headers = ["Authorization", "Content-Type", "Origin", "X-Uptime-Hosted-Token"]
|
|
584
|
+
|
|
585
|
+
cookies {
|
|
586
|
+
forward = "all"
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
restrictions {
|
|
592
|
+
geo_restriction {
|
|
593
|
+
restriction_type = "none"
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
viewer_certificate {
|
|
598
|
+
cloudfront_default_certificate = true
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
depends_on = [aws_lb_listener.http_cloudfront]
|
|
602
|
+
}
|
|
603
|
+
|
|
316
604
|
resource "aws_route53_record" "open_uptime" {
|
|
317
|
-
count = var.hosted_zone_id == null ? 0 : 1
|
|
605
|
+
count = var.hosted_zone_id == null || !local.use_alb_https ? 0 : 1
|
|
318
606
|
zone_id = var.hosted_zone_id
|
|
319
607
|
name = var.hostname
|
|
320
608
|
type = "A"
|
|
@@ -395,6 +683,24 @@ data "aws_iam_policy_document" "task" {
|
|
|
395
683
|
actions = ["kms:Decrypt", "kms:GenerateDataKey"]
|
|
396
684
|
resources = [var.kms_key_arn]
|
|
397
685
|
}
|
|
686
|
+
|
|
687
|
+
dynamic "statement" {
|
|
688
|
+
for_each = contains(local.efs_enabled_services, each.key) ? [1] : []
|
|
689
|
+
|
|
690
|
+
content {
|
|
691
|
+
actions = [
|
|
692
|
+
"elasticfilesystem:ClientMount",
|
|
693
|
+
"elasticfilesystem:ClientWrite",
|
|
694
|
+
]
|
|
695
|
+
resources = [aws_efs_file_system.data.arn]
|
|
696
|
+
|
|
697
|
+
condition {
|
|
698
|
+
test = "StringEquals"
|
|
699
|
+
variable = "elasticfilesystem:AccessPointArn"
|
|
700
|
+
values = [aws_efs_access_point.uptime.arn]
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
}
|
|
398
704
|
}
|
|
399
705
|
|
|
400
706
|
resource "aws_iam_role_policy" "task" {
|
|
@@ -414,6 +720,24 @@ resource "aws_ecs_task_definition" "service" {
|
|
|
414
720
|
execution_role_arn = aws_iam_role.execution.arn
|
|
415
721
|
task_role_arn = aws_iam_role.task[each.key].arn
|
|
416
722
|
|
|
723
|
+
dynamic "volume" {
|
|
724
|
+
for_each = contains(local.efs_enabled_services, each.key) ? [1] : []
|
|
725
|
+
|
|
726
|
+
content {
|
|
727
|
+
name = "uptime-data"
|
|
728
|
+
|
|
729
|
+
efs_volume_configuration {
|
|
730
|
+
file_system_id = aws_efs_file_system.data.id
|
|
731
|
+
transit_encryption = "ENABLED"
|
|
732
|
+
|
|
733
|
+
authorization_config {
|
|
734
|
+
access_point_id = aws_efs_access_point.uptime.id
|
|
735
|
+
iam = "ENABLED"
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
|
|
417
741
|
container_definitions = jsonencode([
|
|
418
742
|
{
|
|
419
743
|
name = each.key
|
|
@@ -425,12 +749,26 @@ resource "aws_ecs_task_definition" "service" {
|
|
|
425
749
|
hostPort = local.container_port
|
|
426
750
|
protocol = "tcp"
|
|
427
751
|
}] : []
|
|
428
|
-
environment = [
|
|
752
|
+
environment = concat([
|
|
429
753
|
{ name = "HASNA_UPTIME_MODE", value = "hosted" },
|
|
430
754
|
{ name = "HASNA_UPTIME_WORKSPACE_ID", value = var.workspace_id },
|
|
431
755
|
{ name = "HASNA_UPTIME_COMPONENT", value = each.key },
|
|
432
756
|
{ name = "HASNA_UPTIME_HOSTNAME", value = var.hostname },
|
|
433
|
-
|
|
757
|
+
], each.key == "web" ? [
|
|
758
|
+
{
|
|
759
|
+
name = "HASNA_UPTIME_ALLOWED_ORIGINS"
|
|
760
|
+
value = local.use_cloudfront ? "https://${aws_cloudfront_distribution.open_uptime[0].domain_name}" : "https://${var.hostname}"
|
|
761
|
+
},
|
|
762
|
+
] : [], contains(local.efs_enabled_services, each.key) ? [
|
|
763
|
+
{ name = "HASNA_UPTIME_HOSTED_SQLITE_DB", value = local.hosted_sqlite_db_path },
|
|
764
|
+
] : [])
|
|
765
|
+
mountPoints = contains(local.efs_enabled_services, each.key) ? [
|
|
766
|
+
{
|
|
767
|
+
sourceVolume = "uptime-data"
|
|
768
|
+
containerPath = "/data/uptime"
|
|
769
|
+
readOnly = false
|
|
770
|
+
}
|
|
771
|
+
] : []
|
|
434
772
|
secrets = [
|
|
435
773
|
for name, value_from in each.value.secrets : {
|
|
436
774
|
name = name
|
|
@@ -476,7 +814,7 @@ resource "aws_ecs_service" "web" {
|
|
|
476
814
|
container_port = local.container_port
|
|
477
815
|
}
|
|
478
816
|
|
|
479
|
-
depends_on = [aws_lb_listener.https]
|
|
817
|
+
depends_on = [aws_lb_listener.https, aws_lb_listener.http_cloudfront, aws_efs_mount_target.data]
|
|
480
818
|
}
|
|
481
819
|
|
|
482
820
|
resource "aws_ecs_service" "worker" {
|
package/infra/aws/outputs.tf
CHANGED
|
@@ -2,6 +2,10 @@ output "ecr_repository_url" {
|
|
|
2
2
|
value = aws_ecr_repository.open_uptime.repository_url
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
+
output "image_builder_project_name" {
|
|
6
|
+
value = aws_codebuild_project.image_builder.name
|
|
7
|
+
}
|
|
8
|
+
|
|
5
9
|
output "ecs_cluster_name" {
|
|
6
10
|
value = aws_ecs_cluster.open_uptime.name
|
|
7
11
|
}
|
|
@@ -10,10 +14,26 @@ output "alb_dns_name" {
|
|
|
10
14
|
value = aws_lb.open_uptime.dns_name
|
|
11
15
|
}
|
|
12
16
|
|
|
17
|
+
output "cloudfront_domain_name" {
|
|
18
|
+
value = try(aws_cloudfront_distribution.open_uptime[0].domain_name, null)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
output "protected_access_url" {
|
|
22
|
+
value = var.protected_access_mode == "cloudfront_default_domain" ? "https://${aws_cloudfront_distribution.open_uptime[0].domain_name}" : "https://${var.hostname}"
|
|
23
|
+
}
|
|
24
|
+
|
|
13
25
|
output "evidence_bucket" {
|
|
14
26
|
value = aws_s3_bucket.evidence.bucket
|
|
15
27
|
}
|
|
16
28
|
|
|
29
|
+
output "efs_file_system_id" {
|
|
30
|
+
value = aws_efs_file_system.data.id
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
output "efs_access_point_id" {
|
|
34
|
+
value = aws_efs_access_point.uptime.id
|
|
35
|
+
}
|
|
36
|
+
|
|
17
37
|
output "service_names" {
|
|
18
38
|
value = concat(
|
|
19
39
|
[aws_ecs_service.web.name],
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
region = "us-east-1"
|
|
2
2
|
stage = "prod"
|
|
3
3
|
service_name = "open-uptime"
|
|
4
|
-
hostname = "uptime.
|
|
5
|
-
workspace_id = "
|
|
6
|
-
vpc_id = "vpc-
|
|
4
|
+
hostname = "uptime.example.com"
|
|
5
|
+
workspace_id = "workspace-id"
|
|
6
|
+
vpc_id = "vpc-xxxxxxxx"
|
|
7
|
+
ecr_repository_name = "open-uptime"
|
|
8
|
+
protected_access_mode = "cloudfront_default_domain"
|
|
7
9
|
public_subnet_ids = ["subnet-replace-public-a", "subnet-replace-public-b"]
|
|
8
10
|
alb_ingress_cidr_blocks = []
|
|
9
11
|
private_subnet_ids = ["subnet-replace-private-a", "subnet-replace-private-b"]
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
certificate_arn =
|
|
13
|
-
hosted_zone_id =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
reporting_secret_arn = "arn:aws:secretsmanager:us-east-1:123456789012:secret:hasna/xyz/opensource/uptime/prod/reporting"
|
|
12
|
+
container_image = "123456789012.dkr.ecr.us-east-1.amazonaws.com/open-uptime@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
|
13
|
+
runtime_package_version = "0.1.8"
|
|
14
|
+
certificate_arn = null
|
|
15
|
+
hosted_zone_id = null
|
|
16
|
+
app_env_secret_arn = "arn:aws:secretsmanager:us-east-1:123456789012:secret:open-uptime/prod/app/env"
|
|
17
|
+
hosted_token_secret_arn = "arn:aws:secretsmanager:us-east-1:123456789012:secret:open-uptime/prod/hosted-token"
|
|
18
|
+
public_probe_secret_arn = "arn:aws:secretsmanager:us-east-1:123456789012:secret:open-uptime/prod/probe/public"
|
|
19
|
+
reporting_secret_arn = "arn:aws:secretsmanager:us-east-1:123456789012:secret:open-uptime/prod/reporting"
|
|
19
20
|
kms_key_arn = "arn:aws:kms:us-east-1:123456789012:key/00000000-0000-0000-0000-000000000000"
|
|
20
21
|
alarm_actions = []
|
|
21
22
|
|