Skip to content

Fix string interpolations for Terraform 0.12 #1

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions examples/node/lambda.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ locals {
}

data "template_file" "lambda_source_file" {
template = "${file("${path.module}/${local.lambda_source_file}")}"
template = file("${path.module}/${local.lambda_source_file}")

vars {
function_description = "text that is injected into the function"
Expand All @@ -16,18 +16,18 @@ data "archive_file" "lambda_source_file_zip" {
output_path = "${path.module}/${local.lambda_source_file}.zip"

source {
content = "${data.template_file.lambda_source_file.rendered}"
filename = "${local.lambda_source_file}"
content = data.template_file.lambda_source_file.rendered
filename = local.lambda_source_file
}
}

resource "aws_lambda_function" "lambda" {
filename = "${substr(data.archive_file.lambda_source_file_zip.output_path, length(path.cwd) + 1, -1)}"
function_name = "${local.function_name}"
role = "${aws_iam_role.lambda.arn}"
filename = substr(data.archive_file.lambda_source_file_zip.output_path, length(path.cwd) + 1, -1)
function_name = local.function_name
role = aws_iam_role.lambda.arn
handler = "${local.lambda_source_file_no_ext}.handler"
source_code_hash = "${data.archive_file.lambda_source_file_zip.output_base64sha256}"
runtime = "${local.runtime}"
source_code_hash = data.archive_file.lambda_source_file_zip.output_base64sha256
runtime = local.runtime
description = "MANAGED BY TERRAFORM"
}

Expand Down Expand Up @@ -71,6 +71,6 @@ EOF
}

resource "aws_iam_role_policy_attachment" "attach-policy" {
role = "${aws_iam_role.lambda.name}"
policy_arn = "${aws_iam_policy.lambda_can_log.arn}"
role = aws_iam_role.lambda.name
policy_arn = aws_iam_policy.lambda_can_log.arn
}
4 changes: 2 additions & 2 deletions examples/node/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This example uses locals which were introduced in Terrform 0.10
terraform {
required_version = ">=0.10.4"
required_version = ">=0.12.0"
}

provider "aws" {
Expand All @@ -15,7 +15,7 @@ locals {
module "execute" {
source = "../../"
name = "${replace(local.lambda_source_file_no_ext, "_", "-")}-example"
lambda_function_arn = "${aws_lambda_function.lambda.arn}"
lambda_function_arn = aws_lambda_function.lambda.arn

lambda_inputs = {
alphabet = "abcdefghijklmnopqrstuvwxyz"
Expand Down
2 changes: 1 addition & 1 deletion examples/node/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
output "result" {
value = "${module.execute.result}"
value = module.execute.result
}
20 changes: 10 additions & 10 deletions examples/python_get_ssm_parameter/lambda.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ locals {
}

data "template_file" "lambda_source_file" {
template = "${file("${path.module}/${local.lambda_source_file}")}"
template = file("${path.module}/${local.lambda_source_file}")

vars {
function_description = "text that is injected into the function"
Expand All @@ -16,18 +16,18 @@ data "archive_file" "lambda_source_file_zip" {
output_path = "${path.module}/${local.lambda_source_file}.zip"

source {
content = "${data.template_file.lambda_source_file.rendered}"
filename = "${local.lambda_source_file}"
content = data.template_file.lambda_source_file.rendered
filename = local.lambda_source_file
}
}

resource "aws_lambda_function" "lambda" {
filename = "${substr(data.archive_file.lambda_source_file_zip.output_path, length(path.cwd) + 1, -1)}"
function_name = "${local.function_name}"
role = "${aws_iam_role.lambda.arn}"
filename = substr(data.archive_file.lambda_source_file_zip.output_path, length(path.cwd) + 1, -1)
function_name = local.function_name
role = aws_iam_role.lambda.arn
handler = "${local.lambda_source_file_no_ext}.handler"
source_code_hash = "${data.archive_file.lambda_source_file_zip.output_base64sha256}"
runtime = "${local.runtime}"
source_code_hash = data.archive_file.lambda_source_file_zip.output_base64sha256
runtime = local.runtime
description = "MANAGED BY TERRAFORM"
}

Expand Down Expand Up @@ -78,6 +78,6 @@ EOF
#"Resource": "arn:aws:ssm:*:*:parameter/my_ssm_parameter"

resource "aws_iam_role_policy_attachment" "attach-policy" {
role = "${aws_iam_role.lambda.name}"
policy_arn = "${aws_iam_policy.lambda_can_log_and_read_params.arn}"
role = aws_iam_role.lambda.name
policy_arn = aws_iam_policy.lambda_can_log_and_read_params.arn
}
4 changes: 2 additions & 2 deletions examples/python_get_ssm_parameter/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This example uses locals which were introduced in Terrform 0.10
terraform {
required_version = ">=0.10.4"
required_version = ">=0.12.0"
}

provider "aws" {
Expand All @@ -15,7 +15,7 @@ locals {
module "execute" {
source = "../../"
name = "${replace(local.lambda_source_file_no_ext, "_", "-")}-example"
lambda_function_arn = "${aws_lambda_function.lambda.arn}"
lambda_function_arn = aws_lambda_function.lambda.arn

lambda_inputs = {
parameter_name = "my_ssm_parameter"
Expand Down
2 changes: 1 addition & 1 deletion examples/python_get_ssm_parameter/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
output "result" {
value = "${module.execute.result}"
value = module.execute.result
}
8 changes: 4 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# ---------------------------------------------------------------------------------------------------------------------

terraform {
required_version = ">=0.9.2"
required_version = ">=0.12.0"
}

resource "aws_cloudformation_stack" "execute_lambda" {
name = "${var.name}"
tags = "${var.tags}"
timeout_in_minutes = "${var.timeout_in_minutes}"
name = var.name
tags = var.tags
timeout_in_minutes = var.timeout_in_minutes

template_body = <<EOF
{
Expand Down
2 changes: 1 addition & 1 deletion outputs.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
output "result" {
description = "A map of results returned by the Lambda, based on the input variable 'lambda_outputs'"
value = "${aws_cloudformation_stack.execute_lambda.outputs}"
value = aws_cloudformation_stack.execute_lambda.outputs
}
6 changes: 3 additions & 3 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
variable "lambda_inputs" {
default = {}
type = "map"
type = map(string)
description = "Map of inputs which are passed into the Lambda function via the event['ResourceProperties'] object."
}

variable "lambda_outputs" {
type = "list"
type = list(string)
description = "List of outputs from the Lambda function. The Lambda must ALWAYS return these outputs, and they can only be of type String. Maps/Objects will result in a CloudFormation error."
}

variable "tags" {
default = {}
type = "map"
type = map(string)
description = "Any tags to add to the CloudFormation stack."
}

Expand Down