Skip to content

Commit

Permalink
Merge pull request #4 from clouddrove/AL-1
Browse files Browse the repository at this point in the history
Al 1
  • Loading branch information
Nikita Dugar authored Dec 26, 2019
2 parents 17e3dec + dab2d16 commit d3f4805
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 15 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Here are some examples of how you can use this module in your inventory structur
### Basic Function
```hcl
module "lambda" {
source = "git::https://github.com/clouddrove/terraform-aws-lambda.git?ref=tags/0.12.0"
source = "git::https://github.com/clouddrove/terraform-aws-lambda.git?ref=tags/0.12.2"
name = "lambda"
application = "clouddrove"
environment = "test"
Expand All @@ -89,7 +89,7 @@ Here are some examples of how you can use this module in your inventory structur
### Basic S3 Function
```hcl
module "lambda" {
source = "git::https://github.com/clouddrove/terraform-aws-lambda.git?ref=tags/0.12.0"
source = "git::https://github.com/clouddrove/terraform-aws-lambda.git?ref=tags/0.12.2"
name = "lambda"
application = "clouddrove"
environment = "test"
Expand All @@ -107,7 +107,7 @@ Here are some examples of how you can use this module in your inventory structur
### Complete Function
```hcl
module "lambda" {
source = "git::https://github.com/clouddrove/terraform-aws-lambda.git?ref=tags/0.12.0"
source = "git::https://github.com/clouddrove/terraform-aws-lambda.git?ref=tags/0.12.2"
name = "lambda"
application = "clouddrove"
environment = "test"
Expand Down
6 changes: 3 additions & 3 deletions README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ usage : |-
### Basic Function
```hcl
module "lambda" {
source = "git::https://github.com/clouddrove/terraform-aws-lambda.git?ref=tags/0.12.0"
source = "git::https://github.com/clouddrove/terraform-aws-lambda.git?ref=tags/0.12.2"
name = "lambda"
application = "clouddrove"
environment = "test"
Expand All @@ -54,7 +54,7 @@ usage : |-
### Basic S3 Function
```hcl
module "lambda" {
source = "git::https://github.com/clouddrove/terraform-aws-lambda.git?ref=tags/0.12.0"
source = "git::https://github.com/clouddrove/terraform-aws-lambda.git?ref=tags/0.12.2"
name = "lambda"
application = "clouddrove"
environment = "test"
Expand All @@ -72,7 +72,7 @@ usage : |-
### Complete Function
```hcl
module "lambda" {
source = "git::https://github.com/clouddrove/terraform-aws-lambda.git?ref=tags/0.12.0"
source = "git::https://github.com/clouddrove/terraform-aws-lambda.git?ref=tags/0.12.2"
name = "lambda"
application = "clouddrove"
environment = "test"
Expand Down
2 changes: 1 addition & 1 deletion _example/basic-function/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ provider "aws" {
}

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

name = "lambda"
application = "clouddrove"
Expand Down
2 changes: 1 addition & 1 deletion _example/basic-s3-function/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ provider "aws" {
}

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

name = "lambda"
application = "clouddrove"
Expand Down
2 changes: 1 addition & 1 deletion _example/complete-function/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ provider "aws" {
}

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

name = "lambda"
application = "clouddrove"
Expand Down
15 changes: 9 additions & 6 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ module "labels" {
# Module : Iam role
# Description : Terraform module to create Iam role resource on AWS for lambda.
resource "aws_iam_role" "default" {
name = format("%s-role", module.labels.id)
count = var.enabled ? 1 : 0
name = format("%s-role", module.labels.id)

assume_role_policy = <<EOF
{
Expand All @@ -39,6 +40,7 @@ EOF
# Module : Iam policy
# Description : Terraform module to create Iam policy resource on AWS for lambda.
resource "aws_iam_policy" "default" {
count = var.enabled ? 1 : 0
name = format("%s-logging", module.labels.id)
path = "/"
description = "IAM policy for logging from a lambda"
Expand All @@ -57,8 +59,9 @@ data "aws_iam_policy_document" "default" {
# Module : Iam Role Policy Attachment
# Description : Terraform module to attach Iam policy with role resource on AWS for lambda.
resource "aws_iam_role_policy_attachment" "default" {
role = aws_iam_role.default.name
policy_arn = aws_iam_policy.default.arn
count = var.enabled ? 1 : 0
role = join("", aws_iam_role.default.*.name)
policy_arn = join("", aws_iam_policy.default.*.arn)
}

# Module : Archive file
Expand Down Expand Up @@ -101,7 +104,7 @@ resource "aws_lambda_function" "default" {

function_name = module.labels.id
description = var.description
role = aws_iam_role.default.arn
role = join("", aws_iam_role.default.*.arn)
filename = var.filename != null ? format("%s.zip", module.labels.id) : null
s3_bucket = var.s3_bucket
s3_key = var.s3_key
Expand Down Expand Up @@ -137,11 +140,11 @@ resource "aws_lambda_function" "default" {
# Description : Terraform module to create Lambda permission resource on AWS to create
# trigger for function.
resource "aws_lambda_permission" "default" {
count = length(var.actions) > 0 ? length(var.actions) : 0
count = length(var.actions) > 0 && var.enabled ? length(var.actions) : 0
statement_id = length(var.statement_ids) > 0 ? element(var.statement_ids, count.index) : ""
event_source_token = length(var.event_source_tokens) > 0 ? element(var.event_source_tokens, count.index) : null
action = element(var.actions, count.index)
function_name = aws_lambda_function.default.*.function_name[0]
function_name = join("", aws_lambda_function.default.*.function_name)
principal = element(var.principals, count.index)
qualifier = length(var.qualifiers) > 0 ? element(var.qualifiers, count.index) : null
source_account = length(var.source_accounts) > 0 ? element(var.source_accounts, count.index) : null
Expand Down

0 comments on commit d3f4805

Please sign in to comment.