Skip to content

Commit

Permalink
fix: few adjustements
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksasiriski committed Apr 26, 2024
1 parent c23ecb0 commit ad762c7
Show file tree
Hide file tree
Showing 43 changed files with 91 additions and 103 deletions.
1 change: 1 addition & 0 deletions aws/dev/backend/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ locals {
routes = toset([
"/search",
"/proxy",
"/healthz"
])
}
17 changes: 11 additions & 6 deletions aws/dev/backend/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,19 @@ module "hearchco_cloudfront" {

paths_cache = {
"/search" = {
min_ttl = 0
default_ttl = 0
max_ttl = 1
min_ttl = 60 // 1 minute
default_ttl = 600 // 10 minutes
max_ttl = 3600 // 1 hour
},
"/proxy" = {
min_ttl = 5
default_ttl = 30
max_ttl = 60
min_ttl = 3600 // 1 hour
default_ttl = 86400 // 1 day
max_ttl = 259200 // 3 days
},
"/healthz" = {
min_ttl = 0
default_ttl = 0
max_ttl = 5
},
}

Expand Down
2 changes: 1 addition & 1 deletion aws/dev/backend/region_eu_central_1.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ provider "aws" {

module "hearchco_s3_eu_central_1" {
source = "../../modules/universal/s3_source_code"
source_name = "bootstrap"
filename = "bootstrap"
bucket_name = "hearchco-api-binary"

providers = {
Expand Down
24 changes: 6 additions & 18 deletions aws/dev/frontend/cloudfront.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,16 @@ module "hearchco_cloudfront" {

top_level_assets = module.hearchco_s3_assets.top_level_assets

default_cache = {
min_ttl = 0
default_ttl = 0
max_ttl = 1
}

default_asset_cache = {
min_ttl = 0
default_ttl = 0
max_ttl = 1
}

paths_cache = {
"/search" = {
min_ttl = 60 // 1 minute
default_ttl = 600 // 10 minutes
max_ttl = 3600 // 1 hour
},
"/healthz" = {
min_ttl = 0
default_ttl = 0
max_ttl = 1
},
"/proxy" = {
min_ttl = 5
default_ttl = 30
max_ttl = 60
max_ttl = 5
},
}

Expand Down
4 changes: 2 additions & 2 deletions aws/dev/frontend/lambda.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ module "hearchco_env_injection" {

module "hearchco_s3_source_code" {
source = "../../modules/universal/s3_source_code"
source_name = "index.mjs"
bucket_name = "hearchco-ssr-function"
path = "tmp/lambda"
filename = module.hearchco_env_injection.filename
path = module.hearchco_env_injection.path

depends_on = [module.hearchco_env_injection]

Expand Down
6 changes: 0 additions & 6 deletions aws/dev/frontend/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,4 @@ locals {
API_URI = "https://${local.api_domain_name}"
PUBLIC_API_URI = "https://${local.api_domain_name}"
})

# Cloudfront
routes = toset([
"/search",
"/proxy",
])
}
2 changes: 1 addition & 1 deletion aws/modules/backend/lambda/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ variable "memory_size" {

variable "timeout" {
type = number
default = 5
default = 4
}
5 changes: 0 additions & 5 deletions aws/modules/frontend/cloudfront/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ resource "aws_cloudfront_distribution" "sveltekit_distribution" {
viewer_protocol_policy = "redirect-to-https"
compress = true
cache_policy_id = aws_cloudfront_cache_policy.cache_policy_s3.id

function_association {
event_type = "viewer-request"
function_arn = aws_cloudfront_function.sveltekit-rewriter.arn
}
}
}

Expand Down
11 changes: 2 additions & 9 deletions aws/modules/frontend/env_injection/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
data "local_file" "source_file" {
filename = var.source_file
filename = "${var.path}/${var.source_file}"
}

locals {
Expand All @@ -8,14 +8,7 @@ locals {
substitude_source_content = replace(local.source_content, var.placeholder, local.environment_string)
}

resource "local_file" "backup_file" {
content = local.source_content
filename = "${var.source_file}.bak"
}

resource "local_file" "output_file" {
content = local.substitude_source_content
filename = var.source_file

depends_on = [local_file.backup_file]
filename = "${var.path}/injected/${var.source_file}"
}
10 changes: 8 additions & 2 deletions aws/modules/frontend/env_injection/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
output "output_file" {
value = local_file.output_file.filename
// last part of the path (divided by /)
output "filename" {
value = split("/", local_file.output_file.filename)[length(split("/", local_file.output_file.filename)) - 1]
}

// everything except the last part of the path (divided by /)
output "path" {
value = join("/", slice(split("/", local_file.output_file.filename), 0, length(split("/", local_file.output_file.filename)) - 1))
}
7 changes: 6 additions & 1 deletion aws/modules/frontend/env_injection/variables.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
variable "path" {
type = string
default = "tmp/lambda"
}

variable "source_file" {
type = string
default = "tmp/lambda/index.mjs"
default = "index.mjs"
}

variable "placeholder" {
Expand Down
3 changes: 2 additions & 1 deletion aws/modules/frontend/lambda_edge/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ variable "architectures" {
default = ["x86_64"]
}

# SvelteKit used around 114MB and crashed, so it's better to have it at least 160MB
variable "memory_size" {
type = number
default = 128
default = 160
}

variable "timeout" {
Expand Down
9 changes: 0 additions & 9 deletions aws/modules/universal/s3_source_code/locals.tf

This file was deleted.

5 changes: 4 additions & 1 deletion aws/modules/universal/s3_source_code/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
data "aws_region" "current" {}
data "aws_caller_identity" "current" {}

resource "aws_s3_bucket" "source_code" {
bucket = local.bucket_name
bucket = "${var.bucket_name}-${data.aws_region.current.name}-${data.aws_caller_identity.current.account_id}"
}

# Ownership
Expand Down
10 changes: 7 additions & 3 deletions aws/modules/universal/s3_source_code/upload.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
// Upload new file
data "archive_file" "source_code" {
type = "zip"
source_file = local.source_file
output_path = local.output_path
source_file = "${var.path}/${var.filename}"
output_path = "${var.path}/${var.filename}.zip"
}

resource "aws_s3_object" "source_code" {
key = local.source_key
key = "${var.filename}.zip"
bucket = aws_s3_bucket.source_code.id
source = data.archive_file.source_code.output_path
source_hash = data.archive_file.source_code.output_base64sha256

lifecycle {
create_before_destroy = true
}
}
4 changes: 2 additions & 2 deletions aws/modules/universal/s3_source_code/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ variable "path" {
default = "tmp"
}

variable "source_name" {
variable "filename" {
type = string

validation {
condition = var.source_name == "bootstrap" || var.source_name == "index.mjs"
condition = var.filename == "bootstrap" || var.filename == "index.mjs"
error_message = "Only 'bootstrap' or 'index.mjs' are allowed"
}
}
1 change: 1 addition & 0 deletions aws/prod/backend/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ locals {
routes = toset([
"/search",
"/proxy",
"/healthz"
])
}
7 changes: 6 additions & 1 deletion aws/prod/backend/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ module "hearchco_cloudfront" {

paths_cache = {
"/search" = {
min_ttl = 600 // 10 minutes
min_ttl = 3600 // 1 hour
default_ttl = 86400 // 1 day
max_ttl = 259200 // 3 days
},
Expand All @@ -74,6 +74,11 @@ module "hearchco_cloudfront" {
default_ttl = 1296000 // 15 days
max_ttl = 2592000 // 30 days
},
"/healthz" = {
min_ttl = 0
default_ttl = 0
max_ttl = 5
},
}

providers = {
Expand Down
2 changes: 1 addition & 1 deletion aws/prod/backend/region_af_south_1.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ provider "aws" {

module "hearchco_s3_af_south_1" {
source = "../../modules/universal/s3_source_code"
source_name = "bootstrap"
filename = "bootstrap"
bucket_name = "hearchco-api-binary"

providers = {
Expand Down
2 changes: 1 addition & 1 deletion aws/prod/backend/region_ap_east_1.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ provider "aws" {

module "hearchco_s3_ap_east_1" {
source = "../../modules/universal/s3_source_code"
source_name = "bootstrap"
filename = "bootstrap"
bucket_name = "hearchco-api-binary"

providers = {
Expand Down
2 changes: 1 addition & 1 deletion aws/prod/backend/region_ap_northeast_1.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ provider "aws" {

module "hearchco_s3_ap_northeast_1" {
source = "../../modules/universal/s3_source_code"
source_name = "bootstrap"
filename = "bootstrap"
bucket_name = "hearchco-api-binary"

providers = {
Expand Down
2 changes: 1 addition & 1 deletion aws/prod/backend/region_ap_northeast_2.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ provider "aws" {

module "hearchco_s3_ap_northeast_2" {
source = "../../modules/universal/s3_source_code"
source_name = "bootstrap"
filename = "bootstrap"
bucket_name = "hearchco-api-binary"

providers = {
Expand Down
2 changes: 1 addition & 1 deletion aws/prod/backend/region_ap_south_1.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ provider "aws" {

module "hearchco_s3_ap_south_1" {
source = "../../modules/universal/s3_source_code"
source_name = "bootstrap"
filename = "bootstrap"
bucket_name = "hearchco-api-binary"

providers = {
Expand Down
2 changes: 1 addition & 1 deletion aws/prod/backend/region_ap_southeast_1.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ provider "aws" {

module "hearchco_s3_ap_southeast_1" {
source = "../../modules/universal/s3_source_code"
source_name = "bootstrap"
filename = "bootstrap"
bucket_name = "hearchco-api-binary"

providers = {
Expand Down
2 changes: 1 addition & 1 deletion aws/prod/backend/region_ap_southeast_2.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ provider "aws" {

module "hearchco_s3_ap_southeast_2" {
source = "../../modules/universal/s3_source_code"
source_name = "bootstrap"
filename = "bootstrap"
bucket_name = "hearchco-api-binary"

providers = {
Expand Down
2 changes: 1 addition & 1 deletion aws/prod/backend/region_ca_central_1.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ provider "aws" {

module "hearchco_s3_ca_central_1" {
source = "../../modules/universal/s3_source_code"
source_name = "bootstrap"
filename = "bootstrap"
bucket_name = "hearchco-api-binary"

providers = {
Expand Down
2 changes: 1 addition & 1 deletion aws/prod/backend/region_eu_central_1.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ provider "aws" {

module "hearchco_s3_eu_central_1" {
source = "../../modules/universal/s3_source_code"
source_name = "bootstrap"
filename = "bootstrap"
bucket_name = "hearchco-api-binary"

providers = {
Expand Down
2 changes: 1 addition & 1 deletion aws/prod/backend/region_eu_central_2.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ provider "aws" {

# module "hearchco_s3_eu_central_2" {
# source = "../../modules/universal/s3_source_code"
# source_name = "bootstrap"
# filename = "bootstrap"
# bucket_name = "hearchco-api-binary"

# providers = {
Expand Down
2 changes: 1 addition & 1 deletion aws/prod/backend/region_eu_north_1.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ provider "aws" {

module "hearchco_s3_eu_north_1" {
source = "../../modules/universal/s3_source_code"
source_name = "bootstrap"
filename = "bootstrap"
bucket_name = "hearchco-api-binary"

providers = {
Expand Down
2 changes: 1 addition & 1 deletion aws/prod/backend/region_eu_south_1.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ provider "aws" {

module "hearchco_s3_eu_south_1" {
source = "../../modules/universal/s3_source_code"
source_name = "bootstrap"
filename = "bootstrap"
bucket_name = "hearchco-api-binary"

providers = {
Expand Down
2 changes: 1 addition & 1 deletion aws/prod/backend/region_eu_south_2.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ provider "aws" {

# module "hearchco_s3_eu_south_2" {
# source = "../../modules/universal/s3_source_code"
# source_name = "bootstrap"
# filename = "bootstrap"
# bucket_name = "hearchco-api-binary"

# providers = {
Expand Down
2 changes: 1 addition & 1 deletion aws/prod/backend/region_eu_west_1.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ provider "aws" {

module "hearchco_s3_eu_west_1" {
source = "../../modules/universal/s3_source_code"
source_name = "bootstrap"
filename = "bootstrap"
bucket_name = "hearchco-api-binary"

providers = {
Expand Down
2 changes: 1 addition & 1 deletion aws/prod/backend/region_eu_west_2.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ provider "aws" {

module "hearchco_s3_eu_west_2" {
source = "../../modules/universal/s3_source_code"
source_name = "bootstrap"
filename = "bootstrap"
bucket_name = "hearchco-api-binary"

providers = {
Expand Down
Loading

0 comments on commit ad762c7

Please sign in to comment.