Skip to content

Commit 37150bc

Browse files
authored
Fixes for Lambda responses CORS (#42)
* Add multi-az as an option * CORS and lifecycle delete after 1 day for lambda * Fix tf warning
1 parent 3ec0322 commit 37150bc

File tree

5 files changed

+42
-0
lines changed

5 files changed

+42
-0
lines changed

main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ module "database" {
5252
source = "./modules/database"
5353
deployment_name = var.deployment_name
5454
postgres_instance_type = var.postgres_instance_type
55+
multi_az = var.postgres_multi_az
5556
postgres_storage_size = var.postgres_storage_size
5657
postgres_max_storage_size = var.postgres_max_storage_size
5758
postgres_storage_type = var.postgres_storage_type

modules/database/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ resource "aws_db_instance" "main" {
1919
storage_type = var.postgres_storage_type
2020
storage_throughput = var.postgres_storage_throughput
2121
iops = var.postgres_storage_iops
22+
multi_az = var.multi_az
2223

2324
db_name = "postgres"
2425
username = local.postgres_username

modules/database/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,9 @@ variable "kms_key_arn" {
6161
type = string
6262
default = null
6363
}
64+
65+
variable "multi_az" {
66+
description = "Specifies if the RDS instance is multi-AZ. Increases cost but provides higher availability. Recommended for production environments."
67+
type = bool
68+
default = false
69+
}

modules/services/s3.tf

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,34 @@ resource "aws_s3_bucket" "lambda_responses_bucket" {
3636
tags = local.common_tags
3737
}
3838

39+
resource "aws_s3_bucket_lifecycle_configuration" "lambda_responses_bucket" {
40+
bucket = aws_s3_bucket.lambda_responses_bucket.id
41+
42+
rule {
43+
id = "ExpireObjectsAfterOneDay"
44+
status = "Enabled"
45+
46+
filter {
47+
prefix = ""
48+
}
49+
50+
expiration {
51+
days = 1
52+
}
53+
}
54+
}
55+
56+
resource "aws_s3_bucket_cors_configuration" "lambda_responses_bucket" {
57+
bucket = aws_s3_bucket.lambda_responses_bucket.id
58+
59+
cors_rule {
60+
allowed_headers = ["*"]
61+
allowed_methods = ["GET", "HEAD"]
62+
allowed_origins = ["*"]
63+
max_age_seconds = 3600
64+
}
65+
}
66+
3967
resource "aws_s3_bucket_server_side_encryption_configuration" "lambda_responses_bucket" {
4068
bucket = aws_s3_bucket.lambda_responses_bucket.id
4169

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ variable "postgres_version" {
158158
default = "15.7"
159159
}
160160

161+
variable "postgres_multi_az" {
162+
description = "Specifies if the RDS instance is multi-AZ. Increases cost but provides higher availability. Recommended for production environments."
163+
type = bool
164+
default = false
165+
}
166+
161167
## Redis
162168
variable "redis_instance_type" {
163169
description = "Instance type for the Redis cluster"

0 commit comments

Comments
 (0)