Skip to content

Commit

Permalink
Revert "Upgrade to Terraform 0.12"
Browse files Browse the repository at this point in the history
This reverts commit c3e62ff.
  • Loading branch information
agassner committed Dec 5, 2019
1 parent c3e62ff commit 6e56c46
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 44 deletions.
15 changes: 5 additions & 10 deletions iam.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
resource "aws_iam_role" "iam_for_lambda" {
name_prefix = replace(
replace(var.function_name, "/(.{0,32}).*/", "$1"),
"/^-+|-+$/",
"",
)
name_prefix = "${replace(replace(var.function_name, "/(.{0,32}).*/", "$1"), "/^-+|-+$/", "")}"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
Expand All @@ -18,19 +14,18 @@ resource "aws_iam_role" "iam_for_lambda" {
]
}
EOF

}

resource "aws_iam_role_policy" "lambda_policy" {
role = aws_iam_role.iam_for_lambda.id
role = "${aws_iam_role.iam_for_lambda.id}"
name = "policy"

policy = var.lambda_role_policy
policy = "${var.lambda_role_policy}"
}

resource "aws_iam_role_policy_attachment" "vpc_permissions" {
role = aws_iam_role.iam_for_lambda.name
role = "${aws_iam_role.iam_for_lambda.name}"
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"

count = length(var.subnet_ids) != 0 ? 1 : 0
count = "${length(var.subnet_ids) != 0 ? 1 : 0}"
}
44 changes: 20 additions & 24 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,40 +1,36 @@
terraform {
required_version = ">= 0.12"
}

resource "aws_lambda_function" "lambda_function" {
s3_bucket = var.s3_bucket
s3_key = var.s3_key
function_name = var.function_name
role = aws_iam_role.iam_for_lambda.arn
handler = var.handler
runtime = var.runtime
timeout = var.timeout
memory_size = var.memory_size
reserved_concurrent_executions = var.reserved_concurrent_executions
tags = var.tags
s3_bucket = "${var.s3_bucket}"
s3_key = "${var.s3_key}"
function_name = "${var.function_name}"
role = "${aws_iam_role.iam_for_lambda.arn}"
handler = "${var.handler}"
runtime = "${var.runtime}"
timeout = "${var.timeout}"
memory_size = "${var.memory_size}"
reserved_concurrent_executions = "${var.reserved_concurrent_executions}"
tags = "${var.tags}"

vpc_config {
subnet_ids = var.subnet_ids
security_group_ids = var.security_group_ids
}
subnet_ids = ["${var.subnet_ids}"]
security_group_ids = ["${var.security_group_ids}"]
}

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

resource "aws_cloudwatch_log_group" "lambda_loggroup" {
name = "/aws/lambda/${var.function_name}"
retention_in_days = 7
depends_on = [aws_lambda_function.lambda_function]
depends_on = ["aws_lambda_function.lambda_function"]
}

resource "aws_cloudwatch_log_subscription_filter" "kinesis_log_stream" {
count = var.datadog_log_subscription_arn != "" ? 1 : 0
count = "${var.datadog_log_subscription_arn != "" ? 1 : 0}"
name = "kinesis-log-stream-${var.function_name}"
destination_arn = var.datadog_log_subscription_arn
log_group_name = aws_cloudwatch_log_group.lambda_loggroup.name
filter_pattern = var.log_subscription_filter
depends_on = [aws_lambda_function.lambda_function]
destination_arn = "${var.datadog_log_subscription_arn}"
log_group_name = "${aws_cloudwatch_log_group.lambda_loggroup.name}"
filter_pattern = "${var.log_subscription_filter}"
depends_on = ["aws_lambda_function.lambda_function"]
}
8 changes: 4 additions & 4 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
output "lambda_arn" {
value = aws_lambda_function.lambda_function.arn
value = "${aws_lambda_function.lambda_function.arn}"
}

output "lambda_function_name" {
value = aws_lambda_function.lambda_function.function_name
value = "${aws_lambda_function.lambda_function.function_name}"
}

output "lambda_iam_role_name" {
value = aws_iam_role.iam_for_lambda.name
value = "${aws_iam_role.iam_for_lambda.name}"
}

output "lambda_invoke_arn" {
value = aws_lambda_function.lambda_function.invoke_arn
value = "${aws_lambda_function.lambda_function.invoke_arn}"
}
11 changes: 5 additions & 6 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ variable "runtime" {
}

variable "subnet_ids" {
type = list(string)
type = "list"
description = "The VPC subnets in which the Lambda runs."
default = []
}

variable "security_group_ids" {
type = list(string)
type = "list"
description = "The VPC security groups assigned to the Lambda."
default = []
}
Expand All @@ -38,7 +38,7 @@ variable "datadog_log_subscription_arn" {

variable "lambda_role_policy" {
description = "The Lambda IAM Role Policy."
default = <<END
default = <<END
{
"Statement": [
{
Expand All @@ -53,7 +53,6 @@ variable "lambda_role_policy" {
]
}
END

}

variable "timeout" {
Expand All @@ -68,7 +67,7 @@ variable "memory_size" {

variable "lambda_env" {
description = "Environment parameters passed to the Lambda function."
type = map(string)
type = "map"
default = {}
}

Expand All @@ -84,6 +83,6 @@ variable "reserved_concurrent_executions" {

variable "tags" {
description = "A mapping of tags to assign to this lambda function."
type = map(string)
type = "map"
default = {}
}

0 comments on commit 6e56c46

Please sign in to comment.