diff --git a/examples/complete/README.md b/examples/complete/README.md
index fbdbcb4..e67b179 100644
--- a/examples/complete/README.md
+++ b/examples/complete/README.md
@@ -24,6 +24,7 @@ Note that this example may create resources which cost money. Run `terraform des
|------|---------|
| [terraform](#requirement\_terraform) | >= 0.13.1 |
| [aws](#requirement\_aws) | >= 3.27 |
+| [null](#requirement\_null) | >= 2 |
| [random](#requirement\_random) | >= 2 |
## Providers
@@ -31,6 +32,7 @@ Note that this example may create resources which cost money. Run `terraform des
| Name | Version |
|------|---------|
| [aws](#provider\_aws) | >= 3.27 |
+| [null](#provider\_null) | >= 2 |
| [random](#provider\_random) | >= 2 |
## Modules
@@ -38,6 +40,7 @@ Note that this example may create resources which cost money. Run `terraform des
| Name | Source | Version |
|------|--------|---------|
| [disabled\_step\_function](#module\_disabled\_step\_function) | ../../ | n/a |
+| [lambda\_function](#module\_lambda\_function) | terraform-aws-modules/lambda/aws | ~> 2.0 |
| [step\_function](#module\_step\_function) | ../../ | n/a |
| [step\_function\_with\_existing\_log\_group](#module\_step\_function\_with\_existing\_log\_group) | ../../ | n/a |
@@ -47,6 +50,7 @@ Note that this example may create resources which cost money. Run `terraform des
|------|------|
| [aws_cloudwatch_log_group.external](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_group) | resource |
| [aws_sqs_queue.queue](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sqs_queue) | resource |
+| [null_resource.download_package](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
| [random_pet.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource |
## Inputs
diff --git a/examples/complete/main.tf b/examples/complete/main.tf
index 48a8916..1d7b95f 100644
--- a/examples/complete/main.tf
+++ b/examples/complete/main.tf
@@ -58,7 +58,8 @@ module "step_function" {
}
lambda = {
- lambda = ["arn:aws:lambda:eu-west-1:123456789012:function:test1", "arn:aws:lambda:eu-west-1:123456789012:function:test2"]
+ lambda = [
+ module.lambda_function.lambda_function_arn, "arn:aws:lambda:eu-west-1:123456789012:function:test2"]
}
xray = {
@@ -168,6 +169,40 @@ module "step_function_with_existing_log_group" {
depends_on = [aws_cloudwatch_log_group.external]
}
+#############################################
+# Using packaged function from Lambda module
+#############################################
+
+locals {
+ package_url = "https://raw.githubusercontent.com/terraform-aws-modules/terraform-aws-lambda/master/examples/fixtures/python3.8-zip/existing_package.zip"
+ downloaded = "downloaded_package_${md5(local.package_url)}.zip"
+}
+
+resource "null_resource" "download_package" {
+ triggers = {
+ downloaded = local.downloaded
+ }
+
+ provisioner "local-exec" {
+ command = "curl -L -o ${local.downloaded} ${local.package_url}"
+ }
+}
+
+module "lambda_function" {
+ source = "terraform-aws-modules/lambda/aws"
+ version = "~> 2.0"
+
+ function_name = "${random_pet.this.id}-lambda"
+ description = "My awesome lambda function"
+ handler = "index.lambda_handler"
+ runtime = "python3.8"
+
+ publish = true
+
+ create_package = false
+ local_existing_package = local.downloaded
+}
+
###########
# Disabled
###########
diff --git a/examples/complete/versions.tf b/examples/complete/versions.tf
index 9a622fc..d11a54a 100644
--- a/examples/complete/versions.tf
+++ b/examples/complete/versions.tf
@@ -4,5 +4,6 @@ terraform {
required_providers {
aws = ">= 3.27"
random = ">= 2"
+ null = ">= 2"
}
}
diff --git a/main.tf b/main.tf
index 14677fa..d6628e6 100644
--- a/main.tf
+++ b/main.tf
@@ -82,7 +82,7 @@ resource "aws_iam_role" "this" {
##############################
data "aws_iam_policy_document" "service" {
- for_each = local.create_role && var.attach_policies_for_integrations ? try(tomap(var.service_integrations), var.service_integrations) : tomap({})
+ for_each = { for k, v in var.service_integrations : k => v if local.create_role && var.attach_policies_for_integrations }
dynamic "statement" {
for_each = each.value
@@ -106,14 +106,14 @@ data "aws_iam_policy_document" "service" {
}
resource "aws_iam_policy" "service" {
- for_each = local.create_role && var.attach_policies_for_integrations ? try(tomap(var.service_integrations), var.service_integrations) : tomap({})
+ for_each = { for k, v in var.service_integrations : k => v if local.create_role && var.attach_policies_for_integrations }
name = "${local.role_name}-${each.key}"
policy = data.aws_iam_policy_document.service[each.key].json
}
resource "aws_iam_policy_attachment" "service" {
- for_each = local.create_role && var.attach_policies_for_integrations ? try(tomap(var.service_integrations), var.service_integrations) : tomap({})
+ for_each = { for k, v in var.service_integrations : k => v if local.create_role && var.attach_policies_for_integrations }
name = "${local.role_name}-${each.key}"
roles = [aws_iam_role.this[0].name]