Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Lambda buckets & ECS tags #4

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ecs_api.tf
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ data "template_file" "api_service_container_definitions" {
template = file("templates/api_service_task_definition.tpl")

vars = {
api_image_uri = "${aws_ecr_repository.api.repository_url}:latest"
api_image_uri = "${aws_ecr_repository.api.repository_url}:${var.api_image_tag}"
api_image_uri = "${var.api_container_repo_url != "" ? var.api_container_repo_url : aws_ecr_repository.api.repository_url}:${var.api_image_tag}"
config_var_prefix = local.config_var_prefix
migrations_image_uri = "${aws_ecr_repository.migrations.repository_url}:latest"
migrations_image_uri = "${var.migrations_container_repo_url != "" ? var.migrations_container_repo_url : aws_ecr_repository.migrations.repository_url}:${var.api_image_tag}"
listening_port = var.api_listening_port
logs_service_name = aws_cloudwatch_log_group.api.name
log_group_region = var.aws_region
Expand Down
3 changes: 2 additions & 1 deletion ecs_push.tf
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ data "template_file" "push_service_container_definitions" {

vars = {
config_var_prefix = local.config_var_prefix
image_uri = "${aws_ecr_repository.push.repository_url}:latest"

image_uri = "${var.push_container_repo_url != "" ? var.push_container_repo_url : aws_ecr_repository.push.repository_url}:${var.push_image_tag}"
listening_port = var.push_listening_port
logs_service_name = aws_cloudwatch_log_group.push.name
log_group_region = var.aws_region
Expand Down
22 changes: 22 additions & 0 deletions env-vars/deployables.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

authorizer_lambda_s3_bucket = ""
authorizer_lambda_s3_key = ""
callback_lambda_s3_bucket = ""
callback_lambda_s3_key = ""
cso_lambda_s3_bucket = ""
cso_lambda_s3_key = ""
Copy link
Contributor

@dgonzalez dgonzalez Aug 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed on a call about naming:

lambda_cso_s3_key

exposures_lambda_s3_bucket = ""
exposures_lambda_s3_key = ""
settings_lambda_s3_bucket = ""
settings_lambda_s3_key = ""
stats_lambda_s3_bucket = ""
stats_lambda_s3_key = ""
token_lambda_s3_bucket = ""
token_lambda_s3_key = ""

push_container_repo_url = ""
api_container_repo_url = ""
migrations_container_repo_url = ""

push_container_tag = "latest"
api_container_tag = "latest"
11 changes: 9 additions & 2 deletions lambda-authorizer.tf
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,17 @@ data "aws_secretsmanager_secret_version" "jwt_secret" {
secret_id = "${data.aws_secretsmanager_secret.jwt_secret.id}"
}

resource "aws_s3_bucket_object" "authorizer_s3_file" {
bucket = aws_s3_bucket.lambdas.id
key = "lambdas/${module.labels.id}_authorizer.zip"
source = "${path.module}/.zip/${module.labels.id}_authorizer.zip"
}

resource "aws_lambda_function" "authorizer" {
filename = "${path.module}/.zip/${module.labels.id}_authorizer.zip"
s3_bucket = (var.lambda_authorizer_s3_bucket != "" ? var.lambda_authorizer_s3_bucket : aws_s3_bucket_object.authorizer_s3_file.bucket)
s3_key = (var.lambda_authorizer_s3_key != "" ? var.lambda_authorizer_s3_key : aws_s3_bucket_object.authorizer_s3_file.key)
function_name = "${module.labels.id}-authorizer"
source_code_hash = data.archive_file.authorizer.output_base64sha256
source_code_hash = (var.lambda_authorizer_s3_key != "" ? "" : data.archive_file.authorizer.output_base64sha256)
role = aws_iam_role.authorizer.arn
runtime = "nodejs10.x"
handler = "authorizer.handler"
Expand Down
11 changes: 9 additions & 2 deletions lambda-callback.tf
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,17 @@ resource "aws_iam_role_policy_attachment" "callback_logs" {
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}

resource "aws_s3_bucket_object" "callback_s3_file" {
bucket = aws_s3_bucket.lambdas.id
key = "lambdas/${module.labels.id}_callback.zip"
source = "${path.module}/.zip/${module.labels.id}_callback.zip"
}

resource "aws_lambda_function" "callback" {
filename = "${path.module}/.zip/${module.labels.id}_callback.zip"
s3_bucket = (var.lambda_callback_s3_bucket != "" ? var.lambda_callback_s3_bucket : aws_s3_bucket_object.callback_s3_file.bucket)
s3_key = (var.lambda_callback_s3_key != "" ? var.lambda_callback_s3_key : aws_s3_bucket_object.callback_s3_file.key)
function_name = "${module.labels.id}-callback"
source_code_hash = data.archive_file.callback.output_base64sha256
source_code_hash = (var.lambda_callback_s3_key != "" ? "" : data.archive_file.callback.output_base64sha256)
role = aws_iam_role.callback.arn
runtime = "nodejs10.x"
handler = "callback.handler"
Expand Down
11 changes: 9 additions & 2 deletions lambda-cso.tf
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,18 @@ resource "aws_iam_role_policy_attachment" "cso_logs" {
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}

resource "aws_s3_bucket_object" "cso_s3_file" {
bucket = aws_s3_bucket.lambdas.id
key = "lambdas/${module.labels.id}_cso.zip"
source = "${path.module}/.zip/${module.labels.id}_cso.zip"
}

resource "aws_lambda_function" "cso" {
count = local.lambda_cso_count
filename = "${path.module}/.zip/${module.labels.id}_cso.zip"
s3_bucket = (var.lambda_cso_s3_bucket != "" ? var.lambda_cso_s3_bucket : aws_s3_bucket_object.cso_s3_file.bucket)
s3_key = (var.lambda_cso_s3_key != "" ? var.lambda_cso_s3_key : aws_s3_bucket_object.cso_s3_file.key)
function_name = "${module.labels.id}-cso"
source_code_hash = data.archive_file.cso.output_base64sha256
source_code_hash = (var.lambda_cso_s3_key != "" ? "" : data.archive_file.cso.output_base64sha256)
role = aws_iam_role.cso[0].arn
runtime = "nodejs10.x"
handler = "cso.handler"
Expand Down
11 changes: 9 additions & 2 deletions lambda-exposures.tf
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,17 @@ resource "aws_iam_role_policy_attachment" "exposures_logs" {
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}

resource "aws_s3_bucket_object" "exposures_s3_file" {
bucket = aws_s3_bucket.lambdas.id
key = "lambdas/${module.labels.id}_exposures.zip"
source = "${path.module}/.zip/${module.labels.id}_exposures.zip"
}

resource "aws_lambda_function" "exposures" {
filename = "${path.module}/.zip/${module.labels.id}_exposures.zip"
s3_bucket = (var.lambda_exposures_s3_bucket != "" ? var.lambda_exposures_s3_bucket : aws_s3_bucket_object.exposures_s3_file.bucket)
s3_key = (var.lambda_exposures_s3_key != "" ? var.lambda_exposures_s3_key : aws_s3_bucket_object.exposures_s3_file.key)
function_name = "${module.labels.id}-exposures"
source_code_hash = data.archive_file.exposures.output_base64sha256
source_code_hash = (var.lambda_exposures_s3_key != "" ? "" : data.archive_file.exposures.output_base64sha256)
role = aws_iam_role.exposures.arn
runtime = "nodejs10.x"
handler = "exposures.handler"
Expand Down
11 changes: 9 additions & 2 deletions lambda-settings.tf
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,17 @@ resource "aws_iam_role_policy_attachment" "settings_logs" {
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}

resource "aws_s3_bucket_object" "settings_s3_file" {
bucket = aws_s3_bucket.lambdas.id
key = "lambdas/${module.labels.id}_settings.zip"
source = "${path.module}/.zip/${module.labels.id}_settings.zip"
}

resource "aws_lambda_function" "settings" {
filename = "${path.module}/.zip/${module.labels.id}_settings.zip"
s3_bucket = (var.lambda_settings_s3_bucket != "" ? var.lambda_settings_s3_bucket : aws_s3_bucket_object.settings_s3_file.bucket)
s3_key = (var.lambda_settings_s3_key != "" ? var.lambda_settings_s3_key : aws_s3_bucket_object.settings_s3_file.key)
function_name = "${module.labels.id}-settings"
source_code_hash = data.archive_file.settings.output_base64sha256
source_code_hash = (var.lambda_settings_s3_key != "" ? "" : data.archive_file.settings.output_base64sha256)
role = aws_iam_role.settings.arn
runtime = "nodejs10.x"
handler = "settings.handler"
Expand Down
11 changes: 9 additions & 2 deletions lambda-stats.tf
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,17 @@ resource "aws_iam_role_policy_attachment" "stats_logs" {
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}

resource "aws_s3_bucket_object" "stats_s3_file" {
bucket = aws_s3_bucket.lambdas.id
key = "lambdas/${module.labels.id}_stats.zip"
source = "${path.module}/.zip/${module.labels.id}_stats.zip"
}

resource "aws_lambda_function" "stats" {
filename = "${path.module}/.zip/${module.labels.id}_stats.zip"
s3_bucket = (var.lambda_stats_s3_bucket != "" ? var.lambda_stats_s3_bucket : aws_s3_bucket_object.stats_s3_file.bucket)
s3_key = (var.lambda_stats_s3_key != "" ? var.lambda_stats_s3_key : aws_s3_bucket_object.stats_s3_file.key)
function_name = "${module.labels.id}-stats"
source_code_hash = data.archive_file.stats.output_base64sha256
source_code_hash = (var.lambda_stats_s3_key != "" ? "" : data.archive_file.stats.output_base64sha256)
role = aws_iam_role.stats.arn
runtime = "nodejs10.x"
handler = "stats.handler"
Expand Down
11 changes: 9 additions & 2 deletions lambda-token.tf
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,17 @@ resource "aws_iam_role_policy_attachment" "token_logs" {
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}

resource "aws_s3_bucket_object" "token_s3_file" {
bucket = aws_s3_bucket.lambdas.id
key = "lambdas/${module.labels.id}_token.zip"
source = "${path.module}/.zip/${module.labels.id}_token.zip"
}

resource "aws_lambda_function" "token" {
filename = "${path.module}/.zip/${module.labels.id}_token.zip"
s3_bucket = (var.lambda_token_s3_bucket != "" ? var.lambda_token_s3_bucket : aws_s3_bucket_object.token_s3_file.bucket)
s3_key = (var.lambda_token_s3_key != "" ? var.lambda_token_s3_key : aws_s3_bucket_object.token_s3_file.key)
function_name = "${module.labels.id}-token"
source_code_hash = data.archive_file.token.output_base64sha256
source_code_hash = (var.lambda_token_s3_key != "" ? "" : data.archive_file.token.output_base64sha256)
role = aws_iam_role.token.arn
runtime = "nodejs10.x"
handler = "token.handler"
Expand Down
18 changes: 18 additions & 0 deletions s3-lambdas.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
resource "aws_s3_bucket" "lambdas" {
bucket = module.labels.id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this name - should we have a suffix

acl = "private"
tags = module.labels.tags

versioning {
enabled = true
}
}

resource "aws_s3_bucket_public_access_block" "lambdas" {
bucket = aws_s3_bucket.assets.id

block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
113 changes: 113 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -315,3 +315,116 @@ variable "sms_sender" {
variable "sms_region" {
default = ""
}
variable "lambda_authorizer_s3_bucket" {
description = "S3 bucket name where the lambda content will be found"
type = string
default = ""
}

variable "lambda_authorizer_s3_key" {
description = "S3 key where the lambda archive will be found. This should be a path relative to the bucket root."
type = string
default = ""
}

variable "lambda_callback_s3_bucket" {
description = "S3 bucket name where the lambda content will be found"
type = string
default = ""
}

variable "lambda_callback_s3_key" {
description = "S3 key where the lambda archive will be found. This should be a path relative to the bucket root."
type = string
default = ""
}

variable "lambda_cso_s3_bucket" {
description = "S3 bucket name where the lambda content will be found"
type = string
default = ""
}

variable "lambda_cso_s3_key" {
description = "S3 key where the lambda archive will be found. This should be a path relative to the bucket root."
type = string
default = ""
}

variable "lambda_token_s3_bucket" {
description = "S3 bucket name where the lambda content will be found"
type = string
default = ""
}

variable "lambda_token_s3_key" {
description = "S3 key where the lambda archive will be found. This should be a path relative to the bucket root."
type = string
default = ""
}

variable "lambda_settings_s3_bucket" {
description = "S3 bucket name where the lambda content will be found"
type = string
default = ""
}

variable "lambda_settings_s3_key" {
description = "S3 key where the lambda archive will be found. This should be a path relative to the bucket root."
type = string
default = ""
}

variable "lambda_exposures_s3_key" {
description = "S3 key where the lambda archive will be found. This should be a path relative to the bucket root."
type = string
default = ""
}

variable "lambda_exposures_s3_bucket" {
description = "S3 bucket name where the lambda content will be found"
type = string
default = ""
}

variable "lambda_stats_s3_key" {
description = "S3 key where the lambda archive will be found. This should be a path relative to the bucket root."
type = string
default = ""
}

variable "lambda_stats_s3_bucket" {
description = "S3 bucket name where the lambda content will be found"
type = string
default = ""
}

variable "api_container_repo_url" {
description = "ECR repo to be deployed into ECS for the API container"
type = string
default = ""
}

variable "migrations_container_repo_url" {
description = "ECR repo to be deployed into ECS for the Migration container"
type = string
default = ""
}

variable "api_image_tag" {
description = "ECR image tag to be deployed into ECS for the API & Migration containers"
type = string
default = "latest"
}

variable "push_container_repo_url" {
description = "ECR repo to be deployed into ECS for the Push API container"
type = string
default = ""
}

variable "push_image_tag" {
description = "ECR image tag to be deployed into ECS for the Push API container"
type = string
default = "latest"
}