Skip to content

Commit 5e8e927

Browse files
author
Om Sharma
authored
Revert "feat: fixed hardcoded value by defined in variable file (#27)"
This reverts commit 2c5df5e.
1 parent 2c5df5e commit 5e8e927

File tree

6 files changed

+28
-62
lines changed

6 files changed

+28
-62
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/existing_package.zip"
1818
handler = "index.lambda_handler"
1919
runtime = "python3.7"
2020
variables = {

_example/complete-function/example.tf

Lines changed: 2 additions & 2 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/existing_package.zip"
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/guardduty_enabler.zip"]
3535
compatible_runtimes = [
3636
["python3.8"]
3737
]

lambda_packages/layer.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

main.tf

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,33 @@ resource "aws_lambda_permission" "default" {
149149
## Terraform module to create Iam role resource on AWS for lambda.
150150
##-----------------------------------------------------------------------------
151151
resource "aws_iam_role" "default" {
152-
count = var.enable && var.create_iam_role ? 1 : 0
153-
name = format("%s-testrole", module.labels.id)
154-
assume_role_policy = var.assume_role_policy
152+
count = var.enable && var.create_iam_role ? 1 : 0
153+
name = format("%s-role", module.labels.id)
154+
155+
assume_role_policy = <<EOF
156+
{
157+
"Version": "2012-10-17",
158+
"Statement": [
159+
{
160+
"Action": "sts:AssumeRole",
161+
"Principal": {
162+
"Service": "lambda.amazonaws.com"
163+
},
164+
"Effect": "Allow",
165+
"Sid": ""
166+
}
167+
]
168+
}
169+
EOF
155170
}
156171

157172
##-----------------------------------------------------------------------------
158173
## Terraform module to create Iam policy resource on AWS for lambda.
159174
##-----------------------------------------------------------------------------
160175
resource "aws_iam_policy" "default" {
161176
count = var.enable && var.create_iam_role ? 1 : 0
162-
name = format("%s-testlogging", module.labels.id)
163-
path = var.aws_iam_policy_path
177+
name = format("%s-logging", module.labels.id)
178+
path = "/"
164179
description = "IAM policy for logging from a lambda"
165180
policy = data.aws_iam_policy_document.default[0].json
166181
}
@@ -198,13 +213,13 @@ resource "aws_kms_key" "kms" {
198213

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

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

@@ -286,7 +301,7 @@ data "aws_cloudwatch_log_group" "lambda" {
286301

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

308323
resource "aws_iam_policy" "logs" {
309324
count = var.enable && var.create_iam_role && var.attach_cloudwatch_logs_policy ? 1 : 0
310-
name = var.aws_iam_policy_logs_name
325+
name = "aws_lambda-logs"
311326
path = var.policy_path
312327
policy = data.aws_iam_policy_document.logs[0].json
313328
tags = module.labels.tags

outputs.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
# Module : Lambda
22
# Description : Terraform Lambda function module outputs.
3-
output "name" {
4-
value = module.labels.name
5-
description = "The name can identifying your Lambda Function."
6-
}
7-
83
output "arn" {
94
value = join("", aws_lambda_function.default[*].arn)
105
description = "The Amazon Resource Name (ARN) identifying your Lambda Function."

variables.tf

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -412,34 +412,4 @@ variable "policy_path" {
412412
type = string
413413
default = null
414414
description = "Path of policies to that should be added to IAM role for Lambda Function"
415-
}
416-
417-
variable "assume_role_policy" {
418-
type = string
419-
description = "assume role policy document in JSON format"
420-
default = <<EOF
421-
{
422-
"Version": "2012-10-17",
423-
"Statement": [
424-
{
425-
"Action": "sts:AssumeRole",
426-
"Principal": {
427-
"Service": "lambda.amazonaws.com"
428-
},
429-
"Effect": "Allow",
430-
"Sid": ""
431-
}
432-
]
433-
}
434-
EOF
435-
}
436-
variable "aws_iam_policy_logs_name" {
437-
type = string
438-
default = "aws_testlambda-logs"
439-
description = "IAM policy name mentioned here"
440-
}
441-
variable "aws_iam_policy_path" {
442-
type = string
443-
default = "/"
444-
description = "IAM policy path default value"
445-
}
415+
}

0 commit comments

Comments
 (0)