Skip to content

Commit d3f4805

Browse files
author
Nikita Dugar
authored
Merge pull request #4 from clouddrove/AL-1
Al 1
2 parents 17e3dec + dab2d16 commit d3f4805

File tree

6 files changed

+18
-15
lines changed

6 files changed

+18
-15
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Here are some examples of how you can use this module in your inventory structur
7272
### Basic Function
7373
```hcl
7474
module "lambda" {
75-
source = "git::https://github.com/clouddrove/terraform-aws-lambda.git?ref=tags/0.12.0"
75+
source = "git::https://github.com/clouddrove/terraform-aws-lambda.git?ref=tags/0.12.2"
7676
name = "lambda"
7777
application = "clouddrove"
7878
environment = "test"
@@ -89,7 +89,7 @@ Here are some examples of how you can use this module in your inventory structur
8989
### Basic S3 Function
9090
```hcl
9191
module "lambda" {
92-
source = "git::https://github.com/clouddrove/terraform-aws-lambda.git?ref=tags/0.12.0"
92+
source = "git::https://github.com/clouddrove/terraform-aws-lambda.git?ref=tags/0.12.2"
9393
name = "lambda"
9494
application = "clouddrove"
9595
environment = "test"
@@ -107,7 +107,7 @@ Here are some examples of how you can use this module in your inventory structur
107107
### Complete Function
108108
```hcl
109109
module "lambda" {
110-
source = "git::https://github.com/clouddrove/terraform-aws-lambda.git?ref=tags/0.12.0"
110+
source = "git::https://github.com/clouddrove/terraform-aws-lambda.git?ref=tags/0.12.2"
111111
name = "lambda"
112112
application = "clouddrove"
113113
environment = "test"

README.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ usage : |-
3737
### Basic Function
3838
```hcl
3939
module "lambda" {
40-
source = "git::https://github.com/clouddrove/terraform-aws-lambda.git?ref=tags/0.12.0"
40+
source = "git::https://github.com/clouddrove/terraform-aws-lambda.git?ref=tags/0.12.2"
4141
name = "lambda"
4242
application = "clouddrove"
4343
environment = "test"
@@ -54,7 +54,7 @@ usage : |-
5454
### Basic S3 Function
5555
```hcl
5656
module "lambda" {
57-
source = "git::https://github.com/clouddrove/terraform-aws-lambda.git?ref=tags/0.12.0"
57+
source = "git::https://github.com/clouddrove/terraform-aws-lambda.git?ref=tags/0.12.2"
5858
name = "lambda"
5959
application = "clouddrove"
6060
environment = "test"
@@ -72,7 +72,7 @@ usage : |-
7272
### Complete Function
7373
```hcl
7474
module "lambda" {
75-
source = "git::https://github.com/clouddrove/terraform-aws-lambda.git?ref=tags/0.12.0"
75+
source = "git::https://github.com/clouddrove/terraform-aws-lambda.git?ref=tags/0.12.2"
7676
name = "lambda"
7777
application = "clouddrove"
7878
environment = "test"

_example/basic-function/example.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ provider "aws" {
33
}
44

55
module "lambda" {
6-
source = "git::https://github.com/clouddrove/terraform-aws-lambda.git?ref=tags/0.12.0"
6+
source = "git::https://github.com/clouddrove/terraform-aws-lambda.git?ref=tags/0.12.2"
77

88
name = "lambda"
99
application = "clouddrove"

_example/basic-s3-function/example.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ provider "aws" {
33
}
44

55
module "lambda" {
6-
source = "git::https://github.com/clouddrove/terraform-aws-lambda.git?ref=tags/0.12.0"
6+
source = "git::https://github.com/clouddrove/terraform-aws-lambda.git?ref=tags/0.12.2"
77

88
name = "lambda"
99
application = "clouddrove"

_example/complete-function/example.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ provider "aws" {
33
}
44

55
module "lambda" {
6-
source = "git::https://github.com/clouddrove/terraform-aws-lambda.git?ref=tags/0.12.0"
6+
source = "git::https://github.com/clouddrove/terraform-aws-lambda.git?ref=tags/0.12.2"
77

88
name = "lambda"
99
application = "clouddrove"

main.tf

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ module "labels" {
1717
# Module : Iam role
1818
# Description : Terraform module to create Iam role resource on AWS for lambda.
1919
resource "aws_iam_role" "default" {
20-
name = format("%s-role", module.labels.id)
20+
count = var.enabled ? 1 : 0
21+
name = format("%s-role", module.labels.id)
2122

2223
assume_role_policy = <<EOF
2324
{
@@ -39,6 +40,7 @@ EOF
3940
# Module : Iam policy
4041
# Description : Terraform module to create Iam policy resource on AWS for lambda.
4142
resource "aws_iam_policy" "default" {
43+
count = var.enabled ? 1 : 0
4244
name = format("%s-logging", module.labels.id)
4345
path = "/"
4446
description = "IAM policy for logging from a lambda"
@@ -57,8 +59,9 @@ data "aws_iam_policy_document" "default" {
5759
# Module : Iam Role Policy Attachment
5860
# Description : Terraform module to attach Iam policy with role resource on AWS for lambda.
5961
resource "aws_iam_role_policy_attachment" "default" {
60-
role = aws_iam_role.default.name
61-
policy_arn = aws_iam_policy.default.arn
62+
count = var.enabled ? 1 : 0
63+
role = join("", aws_iam_role.default.*.name)
64+
policy_arn = join("", aws_iam_policy.default.*.arn)
6265
}
6366

6467
# Module : Archive file
@@ -101,7 +104,7 @@ resource "aws_lambda_function" "default" {
101104

102105
function_name = module.labels.id
103106
description = var.description
104-
role = aws_iam_role.default.arn
107+
role = join("", aws_iam_role.default.*.arn)
105108
filename = var.filename != null ? format("%s.zip", module.labels.id) : null
106109
s3_bucket = var.s3_bucket
107110
s3_key = var.s3_key
@@ -137,11 +140,11 @@ resource "aws_lambda_function" "default" {
137140
# Description : Terraform module to create Lambda permission resource on AWS to create
138141
# trigger for function.
139142
resource "aws_lambda_permission" "default" {
140-
count = length(var.actions) > 0 ? length(var.actions) : 0
143+
count = length(var.actions) > 0 && var.enabled ? length(var.actions) : 0
141144
statement_id = length(var.statement_ids) > 0 ? element(var.statement_ids, count.index) : ""
142145
event_source_token = length(var.event_source_tokens) > 0 ? element(var.event_source_tokens, count.index) : null
143146
action = element(var.actions, count.index)
144-
function_name = aws_lambda_function.default.*.function_name[0]
147+
function_name = join("", aws_lambda_function.default.*.function_name)
145148
principal = element(var.principals, count.index)
146149
qualifier = length(var.qualifiers) > 0 ? element(var.qualifiers, count.index) : null
147150
source_account = length(var.source_accounts) > 0 ? element(var.source_accounts, count.index) : null

0 commit comments

Comments
 (0)