Skip to content

Commit 9f8c111

Browse files
authoredJan 14, 2022
fix: True/false results had different types (terraform-aws-modules#30)
1 parent 2364631 commit 9f8c111

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed
 

‎examples/complete/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,23 @@ Note that this example may create resources which cost money. Run `terraform des
2424
|------|---------|
2525
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
2626
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.27 |
27+
| <a name="requirement_null"></a> [null](#requirement\_null) | >= 2 |
2728
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2 |
2829

2930
## Providers
3031

3132
| Name | Version |
3233
|------|---------|
3334
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.27 |
35+
| <a name="provider_null"></a> [null](#provider\_null) | >= 2 |
3436
| <a name="provider_random"></a> [random](#provider\_random) | >= 2 |
3537

3638
## Modules
3739

3840
| Name | Source | Version |
3941
|------|--------|---------|
4042
| <a name="module_disabled_step_function"></a> [disabled\_step\_function](#module\_disabled\_step\_function) | ../../ | n/a |
43+
| <a name="module_lambda_function"></a> [lambda\_function](#module\_lambda\_function) | terraform-aws-modules/lambda/aws | ~> 2.0 |
4144
| <a name="module_step_function"></a> [step\_function](#module\_step\_function) | ../../ | n/a |
4245
| <a name="module_step_function_with_existing_log_group"></a> [step\_function\_with\_existing\_log\_group](#module\_step\_function\_with\_existing\_log\_group) | ../../ | n/a |
4346

@@ -47,6 +50,7 @@ Note that this example may create resources which cost money. Run `terraform des
4750
|------|------|
4851
| [aws_cloudwatch_log_group.external](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_group) | resource |
4952
| [aws_sqs_queue.queue](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sqs_queue) | resource |
53+
| [null_resource.download_package](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
5054
| [random_pet.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource |
5155

5256
## Inputs

‎examples/complete/main.tf

+36-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ module "step_function" {
5858
}
5959

6060
lambda = {
61-
lambda = ["arn:aws:lambda:eu-west-1:123456789012:function:test1", "arn:aws:lambda:eu-west-1:123456789012:function:test2"]
61+
lambda = [
62+
module.lambda_function.lambda_function_arn, "arn:aws:lambda:eu-west-1:123456789012:function:test2"]
6263
}
6364

6465
xray = {
@@ -168,6 +169,40 @@ module "step_function_with_existing_log_group" {
168169
depends_on = [aws_cloudwatch_log_group.external]
169170
}
170171

172+
#############################################
173+
# Using packaged function from Lambda module
174+
#############################################
175+
176+
locals {
177+
package_url = "https://raw.githubusercontent.com/terraform-aws-modules/terraform-aws-lambda/master/examples/fixtures/python3.8-zip/existing_package.zip"
178+
downloaded = "downloaded_package_${md5(local.package_url)}.zip"
179+
}
180+
181+
resource "null_resource" "download_package" {
182+
triggers = {
183+
downloaded = local.downloaded
184+
}
185+
186+
provisioner "local-exec" {
187+
command = "curl -L -o ${local.downloaded} ${local.package_url}"
188+
}
189+
}
190+
191+
module "lambda_function" {
192+
source = "terraform-aws-modules/lambda/aws"
193+
version = "~> 2.0"
194+
195+
function_name = "${random_pet.this.id}-lambda"
196+
description = "My awesome lambda function"
197+
handler = "index.lambda_handler"
198+
runtime = "python3.8"
199+
200+
publish = true
201+
202+
create_package = false
203+
local_existing_package = local.downloaded
204+
}
205+
171206
###########
172207
# Disabled
173208
###########

‎examples/complete/versions.tf

+1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ terraform {
44
required_providers {
55
aws = ">= 3.27"
66
random = ">= 2"
7+
null = ">= 2"
78
}
89
}

‎main.tf

+3-3
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ resource "aws_iam_role" "this" {
8282
##############################
8383

8484
data "aws_iam_policy_document" "service" {
85-
for_each = local.create_role && var.attach_policies_for_integrations ? try(tomap(var.service_integrations), var.service_integrations) : tomap({})
85+
for_each = { for k, v in var.service_integrations : k => v if local.create_role && var.attach_policies_for_integrations }
8686

8787
dynamic "statement" {
8888
for_each = each.value
@@ -106,14 +106,14 @@ data "aws_iam_policy_document" "service" {
106106
}
107107

108108
resource "aws_iam_policy" "service" {
109-
for_each = local.create_role && var.attach_policies_for_integrations ? try(tomap(var.service_integrations), var.service_integrations) : tomap({})
109+
for_each = { for k, v in var.service_integrations : k => v if local.create_role && var.attach_policies_for_integrations }
110110

111111
name = "${local.role_name}-${each.key}"
112112
policy = data.aws_iam_policy_document.service[each.key].json
113113
}
114114

115115
resource "aws_iam_policy_attachment" "service" {
116-
for_each = local.create_role && var.attach_policies_for_integrations ? try(tomap(var.service_integrations), var.service_integrations) : tomap({})
116+
for_each = { for k, v in var.service_integrations : k => v if local.create_role && var.attach_policies_for_integrations }
117117

118118
name = "${local.role_name}-${each.key}"
119119
roles = [aws_iam_role.this[0].name]

0 commit comments

Comments
 (0)
Please sign in to comment.