-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deploy vengeful vineyard to AWS Lambda/API Gateway (#662)
See dotkom/vengeful-vineyard#267 Depends on #661
- Loading branch information
Showing
11 changed files
with
213 additions
and
24 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,32 @@ | ||
data "doppler_secrets" "monoweb" { | ||
config = terraform.workspace | ||
project = "monoweb" | ||
|
||
provider = doppler.monoweb | ||
} | ||
|
||
locals { | ||
aws_safe_doppler_secrets = { | ||
for key, value in data.doppler_secrets.monoweb.map : key => value if !contains(["AWS_REGION", "AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY"], key) | ||
forbidden_aws_lambda_keys = [ | ||
"AWS_REGION", | ||
"AWS_DEFAULT_REGION", | ||
"AWS_ACCESS_KEY", | ||
"AWS_ACCESS_KEY_ID", | ||
"AWS_SECRET_ACCESS_KEY", | ||
"AWS_SESSION_TOKEN" | ||
] | ||
|
||
monoweb_aws_safe_doppler_secrets = { | ||
for key, value in data.doppler_secrets.monoweb.map : key => value if !contains(local.forbidden_aws_lambda_keys, key) | ||
} | ||
|
||
vengeful_aws_safe_doppler_secrets = { | ||
for key, value in data.doppler_secrets.vengeful.map : key => value if !contains(local.forbidden_aws_lambda_keys, key) | ||
} | ||
} | ||
|
||
data "doppler_secrets" "vengeful" { | ||
project = "vengeful-vineyard" | ||
config = terraform.workspace | ||
|
||
provider = doppler.vengeful | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
output "domain_name" { | ||
value = aws_cloudfront_distribution.this.domain_name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,136 @@ | ||
locals { | ||
vengeful_project_name = "vengeful-vineyard-${terraform.workspace}" | ||
vengeful_project_name = "vengeful-vineyard-${terraform.workspace}" | ||
vengeful_domain_name = "${terraform.workspace}.redwine.online.ntnu.no" | ||
vengeful_cdn_domain_name = "${terraform.workspace}.redwine-static.online.ntnu.no" | ||
} | ||
|
||
module "vengeful_database" { | ||
source = "./modules/neon-project" | ||
source = "./modules/neon-project" | ||
|
||
project_name = local.vengeful_project_name | ||
role_name = "vengeful" | ||
} | ||
|
||
module "vengeful_lambda" { | ||
source = "./modules/aws-docker-lambda" | ||
|
||
ecr_repository_name = "vengeful-vineyard-${terraform.workspace}" | ||
function_name = "vengeful-vineyard-${terraform.workspace}" | ||
execution_role_name = "VengefulVineyardExecutionRole${title(terraform.workspace)}" | ||
iam_inline_policies = [] | ||
environment_variables = local.vengeful_aws_safe_doppler_secrets | ||
memory = 1024 | ||
|
||
tags = { | ||
Project = "vengeful-vineyard" | ||
Environment = terraform.workspace | ||
} | ||
} | ||
|
||
module "vengeful_gateway_domain_certificate" { | ||
source = "./modules/aws-acm-certificate" | ||
|
||
domain = local.vengeful_domain_name | ||
zone_id = local.zone_id | ||
|
||
tags = { | ||
Project = "vengeful-vineyard" | ||
Environment = terraform.workspace | ||
} | ||
|
||
providers = { | ||
aws.regional = aws.eu-north-1 | ||
} | ||
} | ||
|
||
module "vengeful_gateway_proxy" { | ||
source = "./modules/aws-api-gateway" | ||
|
||
domain = local.vengeful_domain_name | ||
zone_id = local.zone_id | ||
certificate_arn = module.vengeful_gateway_domain_certificate.certificate_arn | ||
|
||
tags = { | ||
Project = "vengeful-vineyard" | ||
Environment = terraform.workspace | ||
} | ||
} | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# Connect backend lambda to API Gateway | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
resource "aws_apigatewayv2_integration" "vengeful_backend_lambda" { | ||
api_id = module.vengeful_gateway_proxy.api_gateway_id | ||
integration_type = "AWS_PROXY" | ||
integration_method = "POST" | ||
integration_uri = module.vengeful_lambda.lambda_invoke_arn | ||
payload_format_version = "1.0" | ||
} | ||
|
||
resource "aws_apigatewayv2_route" "vengeful_backend_lambda" { | ||
api_id = module.vengeful_gateway_proxy.api_gateway_id | ||
route_key = "ANY /api/{proxy+}" | ||
target = "integrations/${aws_apigatewayv2_integration.vengeful_backend_lambda.id}" | ||
} | ||
|
||
resource "aws_lambda_permission" "vengeful_backend_gateway_lambda" { | ||
statement_id = "APIGatewayExecuteLambda" | ||
action = "lambda:InvokeFunction" | ||
principal = "apigateway.amazonaws.com" | ||
function_name = module.vengeful_lambda.lambda_name | ||
source_arn = "${module.vengeful_gateway_proxy.api_gateway_execution_arn}/*/*" | ||
} | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# Define static bucket for frontend Vite app | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
module "vengeful_cdn_domain_certificate" { | ||
source = "./modules/aws-acm-certificate" | ||
|
||
domain = local.vengeful_cdn_domain_name | ||
zone_id = local.zone_id | ||
|
||
tags = { | ||
Project = "vengeful-vineyard" | ||
Environment = terraform.workspace | ||
} | ||
|
||
providers = { | ||
aws.regional = aws.us-east-1 | ||
} | ||
} | ||
|
||
module "vengeful_cdn_bucket" { | ||
source = "./modules/aws-s3-public-bucket" | ||
|
||
certificate_arn = module.vengeful_cdn_domain_certificate.certificate_arn | ||
domain_name = local.vengeful_cdn_domain_name | ||
zone_id = local.zone_id | ||
|
||
tags = { | ||
Project = "vengeful-vineyard" | ||
Environment = terraform.workspace | ||
} | ||
|
||
depends_on = [module.vengeful_cdn_domain_certificate] | ||
} | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# Connect static bucket CDN to API Gateway | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
resource "aws_apigatewayv2_integration" "vengeful_cdn" { | ||
api_id = module.vengeful_gateway_proxy.api_gateway_id | ||
integration_type = "HTTP_PROXY" | ||
integration_method = "GET" | ||
integration_uri = "https://${module.vengeful_cdn_bucket.domain_name}" | ||
passthrough_behavior = "WHEN_NO_MATCH" | ||
} | ||
|
||
resource "aws_apigatewayv2_route" "vengeful_cdn" { | ||
api_id = module.vengeful_gateway_proxy.api_gateway_id | ||
route_key = "$default" | ||
target = "integrations/${aws_apigatewayv2_integration.vengeful_cdn.id}" | ||
} |
f1f4c58
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
web – ./apps/web
web-git-main-dotkom.vercel.app
web-pi-umber.vercel.app
dev.web.online.ntnu.no
web-dotkom.vercel.app