Skip to content

Commit 829161f

Browse files
authored
fix- hardcoded value (#28)
* 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
1 parent 2c5df5e commit 829161f

File tree

7 files changed

+25
-18
lines changed

7 files changed

+25
-18
lines changed

_example/basic-function/example.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module "lambda" {
1414
source = "../../"
1515
name = local.name
1616
environment = local.environment
17-
filename = "../../lambda_packages/index.zip"
17+
filename = "../../lambda_packages/index.zip" # -- The content of index.py should be present in zip format
1818
handler = "index.lambda_handler"
1919
runtime = "python3.7"
2020
variables = {

_example/complete-function/data.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
data "aws_caller_identity" "current" {}

_example/complete-function/example.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module "lambda" {
1616
environment = local.environment
1717
create_layers = true
1818
timeout = 60
19-
filename = "../../lambda_packages/index.zip"
19+
filename = "../../lambda_packages/index.zip" # -- The content of index.py should be present in zip format
2020
handler = "index.lambda_handler"
2121
runtime = "python3.8"
2222
compatible_architectures = ["arm64"]
@@ -31,7 +31,7 @@ module "lambda" {
3131
names = [
3232
"python_layer"
3333
]
34-
layer_filenames = ["../../lambda_packages/layer.zip"]
34+
layer_filenames = ["../../lambda_packages/layer.zip"] # -- The content of layer.py should be present in zip format
3535
compatible_runtimes = [
3636
["python3.8"]
3737
]
@@ -45,7 +45,7 @@ module "lambda" {
4545
principals = [
4646
"events.amazonaws.com"
4747
]
48-
source_arns = ["arn:aws:iam::924144197303:role/alarm-lambda-role"]
48+
source_arns = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/alarm-lambda-role"]
4949
variables = {
5050
foo = "bar"
5151
}

_example/complete-function/outputs.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# output "name" {
2+
# value = aws_lambda_function.default.function_name
3+
# description = "The name can identifying your Lambda Function."
4+
# }
5+
output "lambda_function_name" {
6+
description = "The name of the Lambda Function"
7+
value = module.lambda.name
8+
}
9+
110
output "arn" {
211
value = module.lambda[*].arn
312
description = "The ID of the Hostzone."

main.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ resource "aws_lambda_permission" "default" {
150150
##-----------------------------------------------------------------------------
151151
resource "aws_iam_role" "default" {
152152
count = var.enable && var.create_iam_role ? 1 : 0
153-
name = format("%s-testrole", module.labels.id)
153+
name = format("%s-role", module.labels.id)
154154
assume_role_policy = var.assume_role_policy
155155
}
156156

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

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

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

@@ -286,7 +286,7 @@ data "aws_cloudwatch_log_group" "lambda" {
286286

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

308308
resource "aws_iam_policy" "logs" {
309309
count = var.enable && var.create_iam_role && var.attach_cloudwatch_logs_policy ? 1 : 0
310-
name = var.aws_iam_policy_logs_name
310+
name = format("%s-logs-iam-policy", module.labels.id)
311311
path = var.policy_path
312312
policy = data.aws_iam_policy_document.logs[0].json
313313
tags = module.labels.tags

outputs.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Module : Lambda
22
# Description : Terraform Lambda function module outputs.
33
output "name" {
4-
value = module.labels.name
5-
description = "The name can identifying your Lambda Function."
4+
description = "The name of the Lambda Function"
5+
value = join("", aws_lambda_function.default[*].function_name)
66
}
77

88
output "arn" {
@@ -21,6 +21,6 @@ output "lambda_log_group_name" {
2121
}
2222

2323
output "invoke_arn" {
24-
value = join("", aws_lambda_function.default.*.invoke_arn)
24+
value = join("", aws_lambda_function.default[*].invoke_arn)
2525
description = "Invoke ARN"
2626
}

variables.tf

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ variable "timeout" {
9999

100100
variable "runtime" {
101101
type = string
102+
default = "python3.7"
102103
description = "Runtimes."
103104
}
104105

@@ -433,11 +434,7 @@ variable "assume_role_policy" {
433434
}
434435
EOF
435436
}
436-
variable "aws_iam_policy_logs_name" {
437-
type = string
438-
default = "aws_testlambda-logs"
439-
description = "IAM policy name mentioned here"
440-
}
437+
441438
variable "aws_iam_policy_path" {
442439
type = string
443440
default = "/"

0 commit comments

Comments
 (0)