Skip to content

Commit 747853d

Browse files
chore: fix cors config
1 parent ebe506e commit 747853d

File tree

14 files changed

+239
-154
lines changed

14 files changed

+239
-154
lines changed

infrastructure/api/alb.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
locals {
2-
common_tags = var.common_tags
2+
common_tags = var.common_tags
33
}
44

55
resource "aws_alb" "app-alb" {

infrastructure/api/api-gateway.tf

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,9 @@ resource "aws_apigatewayv2_api" "app" {
2323
for_each = var.enable_cors ? [1] : []
2424

2525
content {
26-
allow_origins = [
27-
"https://${data.terraform_remote_state.frontend.outputs.cloudfront.domain_name}",
28-
"https://sitesandtrailsbc.ca",
29-
"https://beta.sitesandtrailsbc.ca"
30-
]
26+
allow_origins = local.cors_allowed_origins
3127
allow_methods = var.cors_allowed_methods
32-
allow_headers = var.cors_allowed_headers
28+
allow_headers = local.cors_headers
3329
allow_credentials = var.cors_allow_credentials
3430
max_age = 3600
3531
}

infrastructure/api/autoscaling.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ resource "aws_appautoscaling_target" "api_target" {
88

99
# Automatically scale capacity up by one
1010
resource "aws_appautoscaling_policy" "api_up" {
11-
name = "${var.app_name}-scale-up"
11+
name = "${var.app_name}-scale-up"
1212
service_namespace = "ecs"
1313
resource_id = "service/${aws_ecs_cluster.ecs_cluster.name}/${aws_ecs_service.node_api_service.name}"
1414
scalable_dimension = "ecs:service:DesiredCount"
@@ -28,7 +28,7 @@ resource "aws_appautoscaling_policy" "api_up" {
2828
}
2929
# Automatically scale capacity down by one
3030
resource "aws_appautoscaling_policy" "api_down" {
31-
name = "${var.app_name}-scale-down"
31+
name = "${var.app_name}-scale-down"
3232
service_namespace = "ecs"
3333
resource_id = "service/${aws_ecs_cluster.ecs_cluster.name}/${aws_ecs_service.node_api_service.name}"
3434
scalable_dimension = "ecs:service:DesiredCount"

infrastructure/api/ecs.tf

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
locals {
2-
container_name = "${var.app_name}"
3-
rds_app_env = (contains(["dev", "test", "prod"], var.app_env) ? var.app_env : "dev") # if app_env is not dev, test, or prod, default to dev
2+
container_name = var.app_name
3+
rds_app_env = (contains(["dev", "test", "prod"], var.app_env) ? var.app_env : "dev") # if app_env is not dev, test, or prod, default to dev
44
}
55

66
data "aws_secretsmanager_secret" "db_master_creds" {
@@ -42,7 +42,7 @@ resource "aws_ecs_cluster_capacity_providers" "ecs_cluster_capacity_providers" {
4242
}
4343

4444
resource "terraform_data" "trigger_deployment" {
45-
input = "${timestamp()}"
45+
input = timestamp()
4646
}
4747

4848

@@ -56,45 +56,45 @@ module "flyway_task" {
5656
execution_role_arn = aws_iam_role.ecs_task_execution_role.arn
5757
task_role_arn = aws_iam_role.app_container_role.arn
5858
environment = [
59-
{
60-
name = "APP_ENV"
61-
value = local.rds_app_env
62-
},
63-
{
64-
name = "FLYWAY_URL"
65-
value = "jdbc:postgresql://${data.aws_rds_cluster.rds_cluster.endpoint}/${var.db_name}"
66-
},
67-
{
68-
name = "FLYWAY_USER"
69-
value = local.db_master_creds.username
70-
},
71-
{
72-
name = "FLYWAY_PASSWORD"
73-
value = local.db_master_creds.password
74-
},
75-
{
76-
name = "FLYWAY_DEFAULT_SCHEMA"
77-
value = "${var.db_schema}"
78-
},
79-
{
80-
name = "FLYWAY_CONNECT_RETRIES"
81-
value = "2"
82-
},
83-
{
84-
name = "FLYWAY_GROUP"
85-
value = "true"
86-
},
87-
{
88-
# This defaults to true, though we want to enable it only in dev to reset the database
89-
# also needs an update in migrations/rst/entrypoint.sh file for the flyaway ecs task to run correctly
90-
name = "FLYWAY_CLEAN_DISABLED"
91-
value = contains(["dev"], local.rds_app_env) ? "false" : "true"
92-
}
59+
{
60+
name = "APP_ENV"
61+
value = local.rds_app_env
62+
},
63+
{
64+
name = "FLYWAY_URL"
65+
value = "jdbc:postgresql://${data.aws_rds_cluster.rds_cluster.endpoint}/${var.db_name}"
66+
},
67+
{
68+
name = "FLYWAY_USER"
69+
value = local.db_master_creds.username
70+
},
71+
{
72+
name = "FLYWAY_PASSWORD"
73+
value = local.db_master_creds.password
74+
},
75+
{
76+
name = "FLYWAY_DEFAULT_SCHEMA"
77+
value = "${var.db_schema}"
78+
},
79+
{
80+
name = "FLYWAY_CONNECT_RETRIES"
81+
value = "2"
82+
},
83+
{
84+
name = "FLYWAY_GROUP"
85+
value = "true"
86+
},
87+
{
88+
# This defaults to true, though we want to enable it only in dev to reset the database
89+
# also needs an update in migrations/rst/entrypoint.sh file for the flyaway ecs task to run correctly
90+
name = "FLYWAY_CLEAN_DISABLED"
91+
value = contains(["dev"], local.rds_app_env) ? "false" : "true"
92+
}
9393
]
94-
aws_region = var.aws_region
95-
cluster_id = aws_ecs_cluster.ecs_cluster.id
96-
security_group = data.aws_security_group.app.id
97-
subnet = data.aws_subnets.app.ids[0]
94+
aws_region = var.aws_region
95+
cluster_id = aws_ecs_cluster.ecs_cluster.id
96+
security_group = data.aws_security_group.app.id
97+
subnet = data.aws_subnets.app.ids[0]
9898
}
9999

100100

@@ -137,7 +137,7 @@ resource "aws_ecs_task_definition" "node_api_task" {
137137
value = "8000"
138138
},
139139
{
140-
name = "FOREST_CLIENT_API_KEY"
140+
name = "FOREST_CLIENT_API_KEY"
141141
value = var.forest_client_api_key
142142
},
143143
{
@@ -193,23 +193,23 @@ resource "aws_ecs_task_definition" "node_api_task" {
193193

194194

195195
resource "aws_ecs_service" "node_api_service" {
196-
name = "${var.app_name}-service"
197-
cluster = aws_ecs_cluster.ecs_cluster.id
198-
task_definition = aws_ecs_task_definition.node_api_task.arn
199-
desired_count = var.min_capacity
196+
name = "${var.app_name}-service"
197+
cluster = aws_ecs_cluster.ecs_cluster.id
198+
task_definition = aws_ecs_task_definition.node_api_task.arn
199+
desired_count = var.min_capacity
200200
health_check_grace_period_seconds = 60
201201

202202
# fargate spot which may get interrupted
203203
#https://docs.aws.amazon.com/AmazonECS/latest/developerguide/fargate-capacity-providers.html
204204
capacity_provider_strategy {
205205
capacity_provider = "FARGATE_SPOT"
206-
weight = "${var.fargate_spot_weight}"
206+
weight = var.fargate_spot_weight
207207
}
208208
# non interrupted service by fargate, makes sure there is alaways minimum capacity
209209
capacity_provider_strategy {
210210
capacity_provider = "FARGATE"
211-
weight = "${var.fargate_base_weight}"
212-
base = "${var.fargate_base_capacity}"
211+
weight = var.fargate_base_weight
212+
base = var.fargate_base_capacity
213213
}
214214

215215

@@ -221,10 +221,10 @@ resource "aws_ecs_service" "node_api_service" {
221221

222222
load_balancer {
223223
target_group_arn = aws_alb_target_group.app.id
224-
container_name = "${local.container_name}"
224+
container_name = local.container_name
225225
container_port = var.app_port
226226
}
227227
wait_for_steady_state = true
228-
depends_on = [aws_iam_role_policy_attachment.ecs_task_execution_role]
229-
tags = local.common_tags
228+
depends_on = [aws_iam_role_policy_attachment.ecs_task_execution_role]
229+
tags = local.common_tags
230230
}

infrastructure/api/iam.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ resource "aws_iam_role_policy" "cloudwatch_metrics" {
8585
Version = "2012-10-17"
8686
Statement = [
8787
{
88-
Effect = "Allow"
89-
Action = "cloudwatch:PutMetricData"
88+
Effect = "Allow"
89+
Action = "cloudwatch:PutMetricData"
9090
Resource = "*"
9191
}
9292
]
@@ -157,7 +157,7 @@ resource "aws_iam_user_policy" "s3_upload_policy" {
157157
Effect = "Allow",
158158
Action = "iam:PassRole",
159159
Resource = [
160-
"*"
160+
"*"
161161
]
162162
},
163163
{

infrastructure/api/monitoring.tf

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ locals {
4343
client_error_threshold = 20
4444

4545
# Period and evaluation period for alarms
46-
alarm_period = 60 # 1 minute
47-
evaluation_periods = 2 # Check for 2 consecutive periods
46+
alarm_period = 60 # 1 minute
47+
evaluation_periods = 2 # Check for 2 consecutive periods
4848

4949
alarm_alert_email_recipients = split(",", var.alarm_alert_email_recipients)
5050

@@ -194,7 +194,7 @@ resource "aws_cloudwatch_dashboard" "api_dashboard" {
194194
region = local.region
195195
period = local.period
196196
view = "timeSeries"
197-
yAxis = { left = { label = "ms" } }
197+
yAxis = { left = { label = "ms" } }
198198
metrics = local.latency_tm99_metrics
199199
annotations = {
200200
horizontal = [
@@ -218,7 +218,7 @@ resource "aws_cloudwatch_dashboard" "api_dashboard" {
218218
region = local.region
219219
period = local.period
220220
view = "timeSeries"
221-
yAxis = { left = { label = "ms" } }
221+
yAxis = { left = { label = "ms" } }
222222
metrics = local.latency_tm95_metrics
223223
annotations = {
224224
horizontal = [
@@ -251,7 +251,7 @@ resource "aws_cloudwatch_metric_alarm" "latency_alarms" {
251251
statistic = "Average"
252252
threshold = each.value
253253
alarm_description = "Latency for ${each.key} exceeds ${each.value}ms in 2/${local.evaluation_periods} periods"
254-
alarm_actions = [aws_sns_topic.alarm_topic.arn]
254+
alarm_actions = [aws_sns_topic.alarm_topic.arn]
255255
treat_missing_data = "notBreaching"
256256

257257
dimensions = {
@@ -277,7 +277,7 @@ resource "aws_cloudwatch_metric_alarm" "server_error_rate_alarm" {
277277
statistic = "Sum"
278278
threshold = local.server_error_threshold
279279
alarm_description = "High server error rate (5xx) detected for operation ${each.value}."
280-
alarm_actions = [aws_sns_topic.alarm_topic.arn]
280+
alarm_actions = [aws_sns_topic.alarm_topic.arn]
281281
treat_missing_data = "notBreaching"
282282

283283
dimensions = {
@@ -303,7 +303,7 @@ resource "aws_cloudwatch_metric_alarm" "client_error_rate_alarm" {
303303
statistic = "Sum"
304304
threshold = local.client_error_threshold
305305
alarm_description = "High client error rate (4xx) detected for operation ${each.value}."
306-
alarm_actions = [aws_sns_topic.alarm_topic.arn]
306+
alarm_actions = [aws_sns_topic.alarm_topic.arn]
307307
treat_missing_data = "notBreaching"
308308

309309
dimensions = {
@@ -324,7 +324,7 @@ resource "aws_kms_key" "alarm_topic_sns_key" {
324324
}
325325

326326
resource "aws_sns_topic" "alarm_topic" {
327-
name = "${var.app_env}-api-monitoring-alarms"
327+
name = "${var.app_env}-api-monitoring-alarms"
328328
kms_master_key_id = aws_kms_key.alarm_topic_sns_key.arn
329329

330330
tags = merge(local.common_resource_tags, {

infrastructure/api/network.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ locals {
66
tools = "Tools"
77
unclass = "UnClass"
88
}
9-
environment = local.env_map[lower(var.target_env) == "test" ? "dev" : lower(var.target_env)]
9+
environment = local.env_map[lower(var.target_env) == "test" ? "dev" : lower(var.target_env)]
1010
vpc_name = "${local.environment}_vpc"
1111
availability_zones = ["a", "b"]
1212
web_subnet_names = [for az in local.availability_zones : "Web_${local.environment}_az${az}_net"]

0 commit comments

Comments
 (0)