Skip to content

Commit b52e870

Browse files
authored
chore: update foreach to count (#14)
* (update): for_each to count * (update): CHANGELOG
1 parent d273363 commit b52e870

File tree

6 files changed

+21
-93
lines changed

6 files changed

+21
-93
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33
All notable changes to this module will be documented in this file.
44

5+
## [v1.1.3] - 2022-11-23
6+
7+
### Added
8+
9+
### Changed
10+
11+
- Update example usage for `examples/complete/*` and `examples/simple/*`
12+
- Update meta-argument of resource `aws_iam_role_policy_attachment.this` from `for_each` to `count`
13+
- Update variable `additional_lambda_role_policy_arns` from type `map(string)` to `list(string)`
14+
15+
### Removed
16+
517
## [v1.1.2] - 2022-10-21
618

719
### Changed

README.md

Lines changed: 2 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,4 @@
1-
# terraform-aws-lambda-edge
2-
3-
## Usage
4-
5-
```terraform
6-
module "lambda" {
7-
source = "git@github.com:oozou/terraform-aws-lambda.git?ref=v1.1.0"
8-
9-
prefix = "oozou"
10-
environment = "dev"
11-
name = "demo"
12-
13-
is_edge = true # Defautl is `fault`, If you want to publish to the edge don't forget to override aws's provider to virgina
14-
15-
# If is_edge is `false`, ignore this config
16-
is_create_lambda_bucket = true # Default is `false`; plz use false, if not 1 lambda: 1 bucket
17-
bucket_name = "" # If `is_create_lambda_bucket` is `false`; specified this, default is `""`
18-
19-
# Source code
20-
source_code_dir = "./src"
21-
file_globs = ["main.py"]
22-
compressed_local_file_dir = "./outputs"
23-
24-
# Lambda Env
25-
runtime = "python3.9"
26-
handler = "main.lambda_handler"
27-
28-
# Lambda Specification
29-
timeout = 3 # Default is `3` seconds
30-
memory_size = 128 # Default is `128` MB, the more mem size increase, the performance is better
31-
reserved_concurrent_executions = -1
32-
# Optional to connect Lambda to VPC
33-
vpc_config = {
34-
security_group_ids = ["sg-028f637312eea735e"]
35-
subnet_ids_to_associate = ["subnet-0b853f8c85796d72d", "subnet-07c068b4b51262793", "subnet-0362f68c559ef7716"]
36-
}
37-
dead_letter_target_arn = "arn:aws:sns:ap-southeast-1:557291035693:demo" # To send failed processing to target, Default is `""`
38-
39-
# IAM
40-
is_create_lambda_role = true # Default is `true`
41-
lambda_role_arn = "" # If `is_create_lambda_role` is `false`
42-
# The policies that you want to attach to IAM Role created by only this module
43-
additional_lambda_role_policy_arns = {
44-
allow_lambda_to_read_s3 = "arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess"
45-
}
46-
47-
# Resource policy
48-
lambda_permission_configurations = {
49-
lambda_on_my_account = {
50-
pricipal = "apigateway.amazonaws.com"
51-
source_arn = "arn:aws:execute-api:ap-southeast-1:557291035693:lk36vflbha/*/*/"
52-
}
53-
lambda_on_my_another_account_wrong = {
54-
pricipal = "apigateway.amazonaws.com"
55-
source_arn = "arn:aws:execute-api:ap-southeast-1:562563527952:q6pwa6wgr6/*/*/"
56-
source_account = "557291035693" # Optional just to restrict the permission
57-
}
58-
lambda_on_my_another_account_correct = {
59-
pricipal = "apigateway.amazonaws.com"
60-
source_arn = "arn:aws:execute-api:ap-southeast-1:557291035693:wpj4t3scmb/*/*/"
61-
}
62-
}
63-
64-
# Logging
65-
is_create_cloudwatch_log_group = true # Default is `true`
66-
cloudwatch_log_retention_in_days = 30 # Default is `90`
67-
68-
# Env
69-
ssm_params = {}
70-
plaintext_params = {
71-
region = "ap-southeast-1"
72-
cluster_name = "oozou-dev-test-schedule-cluster"
73-
nodegroup_name = "oozou-dev-test-schedule-custom-nodegroup"
74-
min = 1,
75-
max = 1,
76-
desired = 1
77-
}
78-
79-
tags = var.generics_info["custom_tags"]
80-
}
81-
```
1+
# terraform-aws-lambda
822

833
<!-- BEGIN_TF_DOCS -->
844
## Requirements
@@ -127,7 +47,7 @@ module "lambda" {
12747

12848
| Name | Description | Type | Default | Required |
12949
|--------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------|:--------:|
130-
| <a name="input_additional_lambda_role_policy_arns"></a> [additional\_lambda\_role\_policy\_arns](#input\_additional\_lambda\_role\_policy\_arns) | Map of policies ARNs to attach to the lambda | `map(string)` | `{}` | no |
50+
| <a name="input_additional_lambda_role_policy_arns"></a> [additional\_lambda\_role\_policy\_arns](#input\_additional\_lambda\_role\_policy\_arns) | Map of policies ARNs to attach to the lambda | `list(string)` | `[]` | no |
13151
| <a name="input_bucket_name"></a> [bucket\_name](#input\_bucket\_name) | Name of the bucket to put the file in. Alternatively, an S3 access point ARN can be specified. | `string` | `""` | no |
13252
| <a name="input_cloudwatch_log_kms_key_id"></a> [cloudwatch\_log\_kms\_key\_id](#input\_cloudwatch\_log\_kms\_key\_id) | The ARN for the KMS encryption key. | `string` | `null` | no |
13353
| <a name="input_cloudwatch_log_retention_in_days"></a> [cloudwatch\_log\_retention\_in\_days](#input\_cloudwatch\_log\_retention\_in\_days) | Retention day for cloudwatch log group | `number` | `90` | no |

examples/complete/main.tf

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ module "lambda" {
3636
is_create_lambda_role = true # Default is `true`
3737
lambda_role_arn = "" # If `is_create_lambda_role` is `false`
3838
# The policies that you want to attach to IAM Role created by only this module # If `is_create_lambda_role` is `false`
39-
additional_lambda_role_policy_arns = {
40-
allow_lambda_to_read_s3 = "arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess"
41-
}
39+
additional_lambda_role_policy_arns = ["arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess"]
4240

4341
# Resource policy
4442
lambda_permission_configurations = {

examples/simple/main.tf

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ module "lambda" {
1212
runtime = "nodejs12.x"
1313
handler = "index.handler"
1414

15-
additional_lambda_role_policy_arns = {
16-
allow_lambda_to_read_s3 = "arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess"
17-
}
15+
additional_lambda_role_policy_arns = ["arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess"]
1816
lambda_permission_configurations = {
1917
lambda_on_my_account = {
2018
pricipal = "apigateway.amazonaws.com"

main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,10 @@ resource "aws_iam_role_policy" "logs_role_policy" {
193193
}
194194

195195
resource "aws_iam_role_policy_attachment" "this" {
196-
for_each = var.is_create_lambda_role ? var.additional_lambda_role_policy_arns : {}
196+
count = var.is_create_lambda_role ? length(var.additional_lambda_role_policy_arns) : 0
197197

198198
role = aws_iam_role.this[0].name
199-
policy_arn = each.value
199+
policy_arn = var.additional_lambda_role_policy_arns[count.index]
200200
}
201201

202202
/* -------------------------------------------------------------------------- */

variables.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ variable "lambda_role_arn" {
9292
}
9393

9494
variable "additional_lambda_role_policy_arns" {
95-
description = "Map of policies ARNs to attach to the lambda"
96-
type = map(string)
97-
default = {}
95+
description = "List of policies ARNs to attach to the lambda's created role"
96+
type = list(string)
97+
default = []
9898
}
9999

100100
/* -------------------------------------------------------------------------- */

0 commit comments

Comments
 (0)