Skip to content

Commit

Permalink
update for terraform 0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
akerl committed Mar 19, 2020
1 parent 02219e9 commit 3e2cd01
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 27 deletions.
29 changes: 15 additions & 14 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,36 @@ data "aws_iam_policy_document" "trust" {
}

resource "aws_lambda_function" "this" {
s3_bucket = "${var.source_bucket}"
s3_bucket = var.source_bucket
s3_key = "${var.source_prefix}${var.source_version}.zip"
function_name = "${var.function_name}"
role = "${aws_iam_role.lambda.arn}"
handler = "${var.handler}"
runtime = "${var.runtime}"
timeout = "${var.timeout}"
function_name = var.function_name
role = aws_iam_role.lambda.arn
handler = var.handler
runtime = var.runtime
timeout = var.timeout

environment {
variables = "${var.environment_variables}"
variables = var.environment_variables
}
}

resource "aws_lambda_permission" "allow_source" {
function_name = "${aws_lambda_function.this.function_name}"
function_name = aws_lambda_function.this.function_name
statement_id = "AllowExecutionFrom${title(var.source_types[count.index])}"
action = "lambda:InvokeFunction"
principal = "${var.source_types[count.index]}.amazonaws.com"
source_arn = "${var.source_arns[count.index]}"
count = "${length(var.source_types)}"
source_arn = var.source_arns[count.index]
count = length(var.source_types)
}

resource "aws_iam_role_policy" "lambda_perms" {
name = "lambda_perms"
role = "${aws_iam_role.lambda.name}"
policy = "${var.access_policy_document}"
role = aws_iam_role.lambda.name
policy = var.access_policy_document
}

resource "aws_iam_role" "lambda" {
name = "${var.function_name}"
assume_role_policy = "${data.aws_iam_policy_document.trust.json}"
name = var.function_name
assume_role_policy = data.aws_iam_policy_document.trust.json
}

5 changes: 3 additions & 2 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
output "arn" {
value = "${aws_lambda_function.this.arn}"
value = aws_lambda_function.this.arn
}

output "invoke_arn" {
value = "${aws_lambda_function.this.invoke_arn}"
value = aws_lambda_function.this.invoke_arn
}

23 changes: 12 additions & 11 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,60 +1,61 @@
variable "runtime" {
description = "Language to use for Lambda"
type = "string"
type = string
default = "go1.x"
}

variable "handler" {
description = "Program entrypoint for Lambda"
type = "string"
type = string
default = "main"
}

variable "timeout" {
description = "Timeout after which Lamdba will terminate"
type = "string"
type = string
default = "10"
}

variable "source_bucket" {
description = "Bucket to use for loading Lambda source ZIP"
type = "string"
type = string
}

variable "source_prefix" {
description = "S3 prefix to use for loading Lambda ZIP"
type = "string"
type = string
default = ""
}

variable "source_version" {
description = "Version of Lambda ZIP to use"
type = "string"
type = string
}

variable "function_name" {
description = "Name for Lambda function"
type = "string"
type = string
}

variable "environment_variables" {
description = "Variables to provide for Lambda environment"
type = "map"
type = map(string)
default = {}
}

variable "access_policy_document" {
description = "IAM policy provided to Lambda role"
type = "string"
type = string
}

variable "source_types" {
description = "Source types which are allowed to invoke the Lambda. Must align with entries in source_arns variable"
type = "list"
type = list(string)
default = ["apigateway"]
}

variable "source_arns" {
description = "Source ARNs which are allowed to invoke the Lambda. Must align with entries in source_types variable"
type = "list"
type = list(string)
}

0 comments on commit 3e2cd01

Please sign in to comment.