forked from Ensono/terraform-aws-lambda
-
Notifications
You must be signed in to change notification settings - Fork 0
Fork and add TF12, Codebuild, and layer support #2
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f7df746
tf12 fixes
bac3fb1
add codebuild
24d5a0b
Merge pull request #1 from PatientPing/add_codebuild
e8f4f07
init support lambda layers
39159ea
readme updates and ci conditionals
90f9c6f
python/provided placeholders
4e50856
variable for codebuild image
443ac68
add priv mode
8a1d1ae
adjust token
28b2b41
adjust token
940de77
adjust token
a9c1174
fmt
e697385
update readme; move cb creds to variable
6524218
construct codebuild credential arn and add iam role output and clarif…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| resource "aws_s3_bucket_notification" "bucket_notification" { | ||
| count = "${var.bucket_trigger["enabled"] ? 1 : 0}" | ||
| bucket = "${var.bucket_trigger["bucket"]}" | ||
| count = var.bucket_trigger["enabled"] ? 1 : 0 | ||
| bucket = var.bucket_trigger["bucket"] | ||
|
|
||
| lambda_function { | ||
| lambda_function_arn = "${aws_lambda_function.lambda.arn}" | ||
| lambda_function_arn = aws_lambda_function.lambda.arn | ||
| events = ["s3:ObjectCreated:*"] | ||
| } | ||
| } |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| data "aws_region" "current" {} | ||
| data "aws_caller_identity" "current" {} | ||
|
|
||
| resource "aws_iam_role" "codebuild" { | ||
| count = var.github_url == "" ? 0 : 1 | ||
|
|
||
| name = "codebuild_${var.function_name}" | ||
|
|
||
| assume_role_policy = <<EOF | ||
| { | ||
| "Version": "2012-10-17", | ||
| "Statement": [ | ||
| { | ||
| "Effect": "Allow", | ||
| "Principal": { | ||
| "Service": "codebuild.amazonaws.com" | ||
| }, | ||
| "Action": "sts:AssumeRole" | ||
| } | ||
| ] | ||
| } | ||
| EOF | ||
| } | ||
|
|
||
| resource "aws_iam_role_policy" "codebuild" { | ||
| count = var.github_url == "" ? 0 : 1 | ||
|
|
||
| role = aws_iam_role.codebuild[0].name | ||
|
|
||
| policy = <<EOF | ||
| { | ||
| "Version": "2012-10-17", | ||
| "Statement": [ | ||
| { | ||
| "Effect": "Allow", | ||
| "Resource": [ | ||
| "*" | ||
| ], | ||
| "Action": [ | ||
| "logs:CreateLogGroup", | ||
| "logs:CreateLogStream", | ||
| "logs:PutLogEvents" | ||
| ] | ||
| }, | ||
| { | ||
| "Effect": "Allow", | ||
| "Resource": "${aws_lambda_function.lambda.arn}", | ||
| "Action": "lambda:UpdateFunctionCode" | ||
| } | ||
| ] | ||
| } | ||
| EOF | ||
| } | ||
|
|
||
| resource "aws_codebuild_project" "lambda" { | ||
| count = var.github_url == "" ? 0 : 1 | ||
|
|
||
| name = var.function_name | ||
| build_timeout = "5" | ||
| service_role = aws_iam_role.codebuild[0].arn | ||
|
|
||
| artifacts { | ||
| type = "NO_ARTIFACTS" | ||
| } | ||
|
|
||
| environment { | ||
| compute_type = "BUILD_GENERAL1_SMALL" | ||
| image = "aws/codebuild/standard:1.0" | ||
| type = "LINUX_CONTAINER" | ||
| image_pull_credentials_type = "CODEBUILD" | ||
| } | ||
|
|
||
| source { | ||
| type = "GITHUB" | ||
| location = var.github_url | ||
| git_clone_depth = 1 | ||
|
|
||
| auth { | ||
| type = "OAUTH" | ||
| resource = var.codebuild_credential_arn == "" ? "arn:aws:codebuild:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:token/github" : var.codebuild_credential_arn | ||
| } | ||
| } | ||
| } | ||
|
|
||
| resource "aws_codebuild_webhook" "lambda" { | ||
| count = var.github_url == "" ? 0 : 1 | ||
|
|
||
| project_name = aws_codebuild_project.lambda[0].name | ||
|
|
||
| filter_group { | ||
| filter { | ||
| type = "EVENT" | ||
| pattern = "PUSH" | ||
| } | ||
|
|
||
| filter { | ||
| type = "HEAD_REF" | ||
| pattern = "master" | ||
| } | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| # Process events from SQS queue, DynamoDB, Kinesis | ||
| resource "aws_lambda_event_source_mapping" "lambda" { | ||
| count = "${length(var.source_mappings)}" | ||
| batch_size = "${lookup(var.source_mappings[count.index], "batch_size")}" | ||
| event_source_arn = "${lookup(var.source_mappings[count.index], "event_source_arn")}" | ||
| enabled = "${lookup(var.source_mappings[count.index], "enabled")}" | ||
| function_name = "${aws_lambda_function.lambda.arn}" | ||
| count = length(var.source_mappings) | ||
| batch_size = lookup(var.source_mappings[count.index], "batch_size") | ||
| event_source_arn = lookup(var.source_mappings[count.index], "event_source_arn") | ||
| enabled = lookup(var.source_mappings[count.index], "enabled") | ||
| function_name = aws_lambda_function.lambda.arn | ||
| } |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,30 @@ | ||
| resource "aws_lambda_function" "lambda" { | ||
| function_name = "${var.function_name}" | ||
| description = "${var.description}" | ||
| role = "${aws_iam_role.lambda.arn}" | ||
| handler = "${var.handler}" | ||
| runtime = "${var.runtime}" | ||
| filename = "${var.create_empty_function ? "${path.module}/placeholder.zip" : var.filename}" | ||
| timeout = "${var.timeout}" | ||
| memory_size = "${var.memory_size}" | ||
| reserved_concurrent_executions = "${var.reserved_concurrent_executions}" | ||
| publish = "${var.publish}" | ||
| function_name = var.function_name | ||
| description = var.description | ||
| role = aws_iam_role.lambda.arn | ||
| handler = var.handler | ||
| runtime = var.runtime | ||
| filename = var.create_empty_function ? "${path.module}/placeholder.zip" : var.filename | ||
| timeout = var.timeout | ||
| memory_size = var.memory_size | ||
| reserved_concurrent_executions = var.reserved_concurrent_executions | ||
| publish = var.publish | ||
| layers = var.layers | ||
|
|
||
| vpc_config { | ||
| subnet_ids = ["${var.vpc_config["subnet_ids"]}"] | ||
| security_group_ids = ["${var.vpc_config["security_group_ids"]}"] | ||
| subnet_ids = var.vpc_config["subnet_ids"] | ||
| security_group_ids = var.vpc_config["security_group_ids"] | ||
| } | ||
|
|
||
| environment { | ||
| variables = "${var.environment_variables}" | ||
| variables = var.environment_variables | ||
| } | ||
|
|
||
| tags = "${var.tags}" | ||
| tags = var.tags | ||
|
|
||
| lifecycle { | ||
| ignore_changes = [ | ||
| "filename", | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| output "lambda_arn" { | ||
| value = "${aws_lambda_function.lambda.arn}" | ||
| output "arn" { | ||
| value = aws_lambda_function.lambda.arn | ||
| } | ||
|
|
||
| output "role" { | ||
| value = aws_iam_role.lambda | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| resource "aws_lambda_permission" "permission" { | ||
| count = "${var.permissions["enabled"] ? 1 : 0}" | ||
| statement_id = "${var.permissions["statement_id"]}" | ||
| action = "${var.permissions["action"]}" | ||
| function_name = "${aws_lambda_function.lambda.arn}" | ||
| principal = "${var.permissions["principal"]}" | ||
| source_arn = "${var.permissions["source_arn"]}" | ||
| } | ||
| count = var.permissions["enabled"] ? 1 : 0 | ||
| statement_id = var.permissions["statement_id"] | ||
| action = var.permissions["action"] | ||
| function_name = aws_lambda_function.lambda.arn | ||
| principal = var.permissions["principal"] | ||
| source_arn = var.permissions["source_arn"] | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,25 @@ | ||
| resource "aws_cloudwatch_event_rule" "lambda" { | ||
| count = "${var.trigger_schedule["enabled"] ? 1 : 0}" | ||
| count = var.trigger_schedule["enabled"] ? 1 : 0 | ||
|
|
||
| name = "${var.function_name}-schedule" | ||
| description = "Schedule - ${var.trigger_schedule["schedule_expression"]}" | ||
| schedule_expression = "${var.trigger_schedule["schedule_expression"]}" | ||
| schedule_expression = var.trigger_schedule["schedule_expression"] | ||
| } | ||
|
|
||
| resource "aws_cloudwatch_event_target" "lambda" { | ||
| count = "${var.trigger_schedule["enabled"] ? 1 : 0}" | ||
| count = var.trigger_schedule["enabled"] ? 1 : 0 | ||
|
|
||
| rule = "${aws_cloudwatch_event_rule.lambda.name}" | ||
| rule = aws_cloudwatch_event_rule.lambda[count.index].name | ||
| target_id = "${var.function_name}-target" | ||
| arn = "${aws_lambda_function.lambda.arn}" | ||
| arn = aws_lambda_function.lambda.arn | ||
| } | ||
|
|
||
| resource "aws_lambda_permission" "lambda_cloudwatch" { | ||
| count = "${var.trigger_schedule["enabled"] ? 1 : 0}" | ||
| count = var.trigger_schedule["enabled"] ? 1 : 0 | ||
|
|
||
| statement_id = "${var.function_name}-permission" | ||
| action = "lambda:InvokeFunction" | ||
| function_name = "${aws_lambda_function.lambda.function_name}" | ||
| function_name = aws_lambda_function.lambda.function_name | ||
| principal = "events.amazonaws.com" | ||
| source_arn = "${aws_cloudwatch_event_rule.lambda.arn}" | ||
| source_arn = aws_cloudwatch_event_rule.lambda[count.index].arn | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,17 @@ | ||
| # SNS | ||
| resource "aws_sns_topic_subscription" "lambda" { | ||
| count = "${var.sns_topic_subscription["enabled"] ? 1 : 0}" | ||
| topic_arn = "${lookup(var.sns_topic_subscription, "sns_topic_arn")}" | ||
| count = var.sns_topic_subscription["enabled"] ? 1 : 0 | ||
| topic_arn = lookup(var.sns_topic_subscription, "sns_topic_arn") | ||
| protocol = "lambda" | ||
| endpoint = "${aws_lambda_function.lambda.arn}" | ||
| endpoint = aws_lambda_function.lambda.arn | ||
| } | ||
|
|
||
| resource "aws_lambda_permission" "lambda_sns" { | ||
| count = "${var.sns_topic_subscription["enabled"] ? 1 : 0}" | ||
| count = var.sns_topic_subscription["enabled"] ? 1 : 0 | ||
|
|
||
| statement_id = "AllowExecutionFromSNS-${count.index}" | ||
| action = "lambda:InvokeFunction" | ||
| function_name = "${aws_lambda_function.lambda.arn}" | ||
| function_name = aws_lambda_function.lambda.arn | ||
| principal = "sns.amazonaws.com" | ||
| source_arn = "${lookup(var.sns_topic_subscription, "sns_topic_arn")}" | ||
| source_arn = lookup(var.sns_topic_subscription, "sns_topic_arn") | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.