Skip to content

Commit

Permalink
fix- hardcoded value (#28)
Browse files Browse the repository at this point in the history
* fix- hardcoded value

* fix- aws-caller-identity and tflint issue

* fix- aws-caller-identity and tflint issue

* fix- output of lambda-function-name

* fix- tflint issue
  • Loading branch information
Kasarpooja committed Nov 21, 2023
1 parent 2c5df5e commit 829161f
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 18 deletions.
2 changes: 1 addition & 1 deletion _example/basic-function/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module "lambda" {
source = "../../"
name = local.name
environment = local.environment
filename = "../../lambda_packages/index.zip"
filename = "../../lambda_packages/index.zip" # -- The content of index.py should be present in zip format
handler = "index.lambda_handler"
runtime = "python3.7"
variables = {
Expand Down
1 change: 1 addition & 0 deletions _example/complete-function/data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data "aws_caller_identity" "current" {}
6 changes: 3 additions & 3 deletions _example/complete-function/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module "lambda" {
environment = local.environment
create_layers = true
timeout = 60
filename = "../../lambda_packages/index.zip"
filename = "../../lambda_packages/index.zip" # -- The content of index.py should be present in zip format
handler = "index.lambda_handler"
runtime = "python3.8"
compatible_architectures = ["arm64"]
Expand All @@ -31,7 +31,7 @@ module "lambda" {
names = [
"python_layer"
]
layer_filenames = ["../../lambda_packages/layer.zip"]
layer_filenames = ["../../lambda_packages/layer.zip"] # -- The content of layer.py should be present in zip format
compatible_runtimes = [
["python3.8"]
]
Expand All @@ -45,7 +45,7 @@ module "lambda" {
principals = [
"events.amazonaws.com"
]
source_arns = ["arn:aws:iam::924144197303:role/alarm-lambda-role"]
source_arns = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/alarm-lambda-role"]
variables = {
foo = "bar"
}
Expand Down
9 changes: 9 additions & 0 deletions _example/complete-function/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# output "name" {
# value = aws_lambda_function.default.function_name
# description = "The name can identifying your Lambda Function."
# }
output "lambda_function_name" {
description = "The name of the Lambda Function"
value = module.lambda.name
}

output "arn" {
value = module.lambda[*].arn
description = "The ID of the Hostzone."
Expand Down
12 changes: 6 additions & 6 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ resource "aws_lambda_permission" "default" {
##-----------------------------------------------------------------------------
resource "aws_iam_role" "default" {
count = var.enable && var.create_iam_role ? 1 : 0
name = format("%s-testrole", module.labels.id)
name = format("%s-role", module.labels.id)
assume_role_policy = var.assume_role_policy
}

Expand All @@ -159,7 +159,7 @@ resource "aws_iam_role" "default" {
##-----------------------------------------------------------------------------
resource "aws_iam_policy" "default" {
count = var.enable && var.create_iam_role ? 1 : 0
name = format("%s-testlogging", module.labels.id)
name = format("%s-logging", module.labels.id)
path = var.aws_iam_policy_path
description = "IAM policy for logging from a lambda"
policy = data.aws_iam_policy_document.default[0].json
Expand Down Expand Up @@ -198,13 +198,13 @@ resource "aws_kms_key" "kms" {

resource "aws_kms_alias" "kms-alias" {
count = var.enable && var.enable_kms ? 1 : 0
name = format("alias/%s-testlambda-keys", module.labels.id)
name = format("alias/%s-lambda-keys", module.labels.id)
target_key_id = aws_kms_key.kms[0].key_id
}

resource "aws_kms_alias" "kms-alias-cloudwatch" {
count = var.enable && var.enable_kms && !var.existing_cloudwatch_log_group ? 1 : 0
name = format("alias/%s-testlambda-cloudwatch-keys", module.labels.id)
name = format("alias/%s-lambda-cloudwatch-keys", module.labels.id)
target_key_id = aws_kms_key.kms[1].key_id
}

Expand Down Expand Up @@ -286,7 +286,7 @@ data "aws_cloudwatch_log_group" "lambda" {

resource "aws_cloudwatch_log_group" "lambda" {
count = var.enable && !var.existing_cloudwatch_log_group ? 1 : 0
name = "/aws/testlambda/${module.labels.id}"
name = "/aws/lambda/${module.labels.id}"
retention_in_days = var.cloudwatch_logs_retention_in_days
kms_key_id = var.enable_kms ? aws_kms_key.kms[1].arn : var.cloudwatch_logs_kms_key_arn
tags = module.labels.tags
Expand All @@ -307,7 +307,7 @@ data "aws_iam_policy_document" "logs" {

resource "aws_iam_policy" "logs" {
count = var.enable && var.create_iam_role && var.attach_cloudwatch_logs_policy ? 1 : 0
name = var.aws_iam_policy_logs_name
name = format("%s-logs-iam-policy", module.labels.id)
path = var.policy_path
policy = data.aws_iam_policy_document.logs[0].json
tags = module.labels.tags
Expand Down
6 changes: 3 additions & 3 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Module : Lambda
# Description : Terraform Lambda function module outputs.
output "name" {
value = module.labels.name
description = "The name can identifying your Lambda Function."
description = "The name of the Lambda Function"
value = join("", aws_lambda_function.default[*].function_name)
}

output "arn" {
Expand All @@ -21,6 +21,6 @@ output "lambda_log_group_name" {
}

output "invoke_arn" {
value = join("", aws_lambda_function.default.*.invoke_arn)
value = join("", aws_lambda_function.default[*].invoke_arn)
description = "Invoke ARN"
}
7 changes: 2 additions & 5 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ variable "timeout" {

variable "runtime" {
type = string
default = "python3.7"
description = "Runtimes."
}

Expand Down Expand Up @@ -433,11 +434,7 @@ variable "assume_role_policy" {
}
EOF
}
variable "aws_iam_policy_logs_name" {
type = string
default = "aws_testlambda-logs"
description = "IAM policy name mentioned here"
}

variable "aws_iam_policy_path" {
type = string
default = "/"
Expand Down

0 comments on commit 829161f

Please sign in to comment.