Skip to content

Commit

Permalink
Merge pull request #15 from jentz/add-publish
Browse files Browse the repository at this point in the history
adds support for the publish variable
  • Loading branch information
rickardl authored May 3, 2019
2 parents 22fe794 + d7874cc commit 989fae4
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/s3-publish/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## examples/s3-publish

Basic example which creates a Lambda function from s3 bucket with logging privileges using publish to increment the version number.
52 changes: 52 additions & 0 deletions examples/s3-publish/example.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
provider "aws" {
region = "eu-west-1"
}

module "lambda" {
source = "../../"

name_prefix = "example"
s3_bucket = "telia-oss"
s3_key = "hello-world/helloworld.zip"
policy = "${data.aws_iam_policy_document.lambda.json}"
runtime = "python3.6"
handler = "helloworld.handler"
publish = "true"

environment {
TEST = "TEST VALUE"
}

tags {
environment = "prod"
terraform = "True"
}
}

data "aws_iam_policy_document" "lambda" {
statement {
effect = "Allow"

actions = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
]

resources = [
"*",
]
}
}

output "lambda_arn" {
value = "${module.lambda.arn}"
}

output "lambda_invoke_arn" {
value = "${module.lambda.invoke_arn}"
}

output "lambda_qualified_arn" {
value = "${module.lambda.qualified_arn}"
}
4 changes: 4 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ resource "aws_lambda_function" "main" {
timeout = "${var.timeout}"
role = "${aws_iam_role.main.arn}"
reserved_concurrent_executions = "${var.reserved_concurrent_executions}"
publish = "${var.publish}"

environment {
variables = "${var.environment}"
Expand All @@ -33,6 +34,7 @@ resource "aws_lambda_function" "vpc" {
timeout = "${var.timeout}"
role = "${aws_iam_role.main.arn}"
reserved_concurrent_executions = "${var.reserved_concurrent_executions}"
publish = "${var.publish}"

vpc_config {
subnet_ids = ["${var.subnet_ids}"]
Expand All @@ -59,6 +61,7 @@ resource "aws_lambda_function" "main_s3" {
timeout = "${var.timeout}"
role = "${aws_iam_role.main.arn}"
reserved_concurrent_executions = "${var.reserved_concurrent_executions}"
publish = "${var.publish}"
source_code_hash = "${var.source_code_hash}"

environment {
Expand Down Expand Up @@ -86,6 +89,7 @@ resource "aws_lambda_function" "vpc_s3" {
timeout = "${var.timeout}"
role = "${aws_iam_role.main.arn}"
reserved_concurrent_executions = "${var.reserved_concurrent_executions}"
publish = "${var.publish}"
source_code_hash = "${var.source_code_hash}"

vpc_config {
Expand Down
5 changes: 5 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ output "invoke_arn" {
description = " The ARN to be used for invoking Lambda Function from API Gateway - to be used in aws_api_gateway_integration uri."
value = "${element(concat(aws_lambda_function.main.*.invoke_arn, aws_lambda_function.vpc.*.invoke_arn, aws_lambda_function.main_s3.*.invoke_arn, aws_lambda_function.vpc_s3.*.invoke_arn,), 0)}"
}

output "qualified_arn" {
description = " The Amazon Resource Name (ARN) identifying your Lambda Function Version (if versioning is enabled via publish = true)."
value = "${element(concat(aws_lambda_function.main.*.qualified_arn, aws_lambda_function.vpc.*.qualified_arn, aws_lambda_function.main_s3.*.qualified_arn, aws_lambda_function.vpc_s3.*.qualified_arn,), 0)}"
}
5 changes: 5 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ variable "reserved_concurrent_executions" {
default = -1
}

variable "publish" {
description = "Whether to publish creation/change as new Lambda Function Version. Defaults to false."
default = "false"
}

variable "source_code_hash" {
description = "Used to trigger updates. Must be set to a base64-encoded SHA256 hash of the package file specified with either filename or s3_key."
default = ""
Expand Down

0 comments on commit 989fae4

Please sign in to comment.