This file contains hidden or 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
resource "aws_s3_bucket_object" "main" { | |
bucket = var.s3_bucket_id | |
key = var.key_s3_bucket | |
source = data.archive_file.main.output_path | |
etag = data.archive_file.main.output_base64sha256 | |
depends_on = [ | |
data.archive_file.main, | |
null_resource.main, | |
] |
This file contains hidden or 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
resource "aws_lambda_layer_version" "main" { | |
layer_name = var.lambda_layer_name | |
description = var.description | |
s3_bucket = var.s3_bucket_id | |
s3_key = var.key_s3_bucket | |
source_code_hash = data.archive_file.main.output_base64sha256 | |
compatible_runtimes = [var.lambda_runtime] | |
depends_on = [ | |
aws_s3_bucket_object.main, |
This file contains hidden or 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
data "archive_file" "main" { | |
type = "zip" | |
source_dir = var.code_location | |
output_path = "${path.module}/.terraform/archive_files/${var.filename}" | |
} |
This file contains hidden or 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
resource "aws_cloudwatch_log_group" "main" { | |
name = "/aws/lambda/${var.lambda_function_name}" | |
retention_in_days = var.log_retention | |
} |
This file contains hidden or 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
resource "aws_iam_role_policy" "lambda_basic_policy" { | |
name = "lambda_${var.lambda_function_name}_basic_policy" | |
role = aws_iam_role.lambda_role.id | |
policy = <<EOF | |
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Effect": "Allow", |
This file contains hidden or 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
output "lambda_role" { | |
description = "IAM Role id to attach more policies" | |
value = aws_iam_role.lambda_role.id | |
} |
This file contains hidden or 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
resource "aws_iam_role" "lambda_role" { | |
name = "lambda-name" | |
assume_role_policy = <<EOF | |
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Action": "sts:AssumeRole", | |
"Principal": { |
This file contains hidden or 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
variable "name" { | |
default = "Some useful name" | |
} |
This file contains hidden or 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
resource "aws_lambda_function" "main" { | |
function_name = var.lambda_function_name | |
handler = var.handler_name | |
runtime = var.lambda_runtime | |
timeout = var.timeout | |
memory_size = var.memory | |
role = aws_iam_role.lambda_role.arn | |
filename = "${path.module}/.terraform/archive_files/${var.filename}" | |
source_code_hash = data.archive_file.main[count.index].output_base64sha256 |
This file contains hidden or 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
resource "aws_s3_object" "storage" { | |
for_each = fileset("${var.path_files}/", "*") | |
bucket = aws_s3_bucket.storage_bucket.id | |
key = each.value | |
source = "${var.path_files}/${each.value}" | |
etag = filemd5("${var.path_files}/${each.value}") | |
acl = "public-read" | |
} |