Skip to content

Commit c173c27

Browse files
feat: Added variable to control the create log group permission (#514)
1 parent 9562536 commit c173c27

File tree

6 files changed

+27
-1
lines changed

6 files changed

+27
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,7 @@ No modules.
742742
| <a name="input_assume_role_policy_statements"></a> [assume\_role\_policy\_statements](#input\_assume\_role\_policy\_statements) | Map of dynamic policy statements for assuming Lambda Function role (trust relationship) | `any` | `{}` | no |
743743
| <a name="input_attach_async_event_policy"></a> [attach\_async\_event\_policy](#input\_attach\_async\_event\_policy) | Controls whether async event policy should be added to IAM role for Lambda Function | `bool` | `false` | no |
744744
| <a name="input_attach_cloudwatch_logs_policy"></a> [attach\_cloudwatch\_logs\_policy](#input\_attach\_cloudwatch\_logs\_policy) | Controls whether CloudWatch Logs policy should be added to IAM role for Lambda Function | `bool` | `true` | no |
745+
| <a name="input_attach_create_log_group_permission"></a> [attach\_create\_log\_group\_permission](#input\_attach\_create\_log\_group\_permission) | Controls whether to add the create log group permission to the CloudWatch logs policy | `bool` | `true` | no |
745746
| <a name="input_attach_dead_letter_policy"></a> [attach\_dead\_letter\_policy](#input\_attach\_dead\_letter\_policy) | Controls whether SNS/SQS dead letter notification policy should be added to IAM role for Lambda Function | `bool` | `false` | no |
746747
| <a name="input_attach_network_policy"></a> [attach\_network\_policy](#input\_attach\_network\_policy) | Controls whether VPC/network policy should be added to IAM role for Lambda Function | `bool` | `false` | no |
747748
| <a name="input_attach_policies"></a> [attach\_policies](#input\_attach\_policies) | Controls whether list of policies should be added to IAM role for Lambda Function | `bool` | `false` | no |

examples/complete/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Note that this example may create resources which cost money. Run `terraform des
4040
| <a name="module_lambda_function"></a> [lambda\_function](#module\_lambda\_function) | ../../ | n/a |
4141
| <a name="module_lambda_function_existing_package_local"></a> [lambda\_function\_existing\_package\_local](#module\_lambda\_function\_existing\_package\_local) | ../../ | n/a |
4242
| <a name="module_lambda_function_for_each"></a> [lambda\_function\_for\_each](#module\_lambda\_function\_for\_each) | ../../ | n/a |
43+
| <a name="module_lambda_function_no_create_log_group_permission"></a> [lambda\_function\_no\_create\_log\_group\_permission](#module\_lambda\_function\_no\_create\_log\_group\_permission) | ../../ | n/a |
4344
| <a name="module_lambda_function_with_package_deploying_externally"></a> [lambda\_function\_with\_package\_deploying\_externally](#module\_lambda\_function\_with\_package\_deploying\_externally) | ../../ | n/a |
4445
| <a name="module_lambda_layer_local"></a> [lambda\_layer\_local](#module\_lambda\_layer\_local) | ../../ | n/a |
4546
| <a name="module_lambda_layer_s3"></a> [lambda\_layer\_s3](#module\_lambda\_layer\_s3) | ../../ | n/a |

examples/complete/main.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,23 @@ module "lambda_function_with_package_deploying_externally" {
372372
ignore_source_code_hash = true
373373
}
374374

375+
####################################################
376+
# Lambda Function no create log group permission
377+
####################################################
378+
379+
module "lambda_function_no_create_log_group_permission" {
380+
source = "../../"
381+
382+
function_name = "${random_pet.this.id}-lambda-no-create-log-group-permission"
383+
handler = "index.lambda_handler"
384+
runtime = "python3.8"
385+
386+
create_package = false
387+
local_existing_package = "../fixtures/python3.8-zip/existing_package.zip"
388+
389+
attach_create_log_group_permission = false
390+
}
391+
375392
###########
376393
# Disabled
377394
###########

iam.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ data "aws_iam_policy_document" "logs" {
122122
effect = "Allow"
123123

124124
actions = compact([
125-
!var.use_existing_cloudwatch_log_group ? "logs:CreateLogGroup" : "",
125+
!var.use_existing_cloudwatch_log_group && var.attach_create_log_group_permission ? "logs:CreateLogGroup" : "",
126126
"logs:CreateLogStream",
127127
"logs:PutLogEvents"
128128
])

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,12 @@ variable "attach_cloudwatch_logs_policy" {
494494
default = true
495495
}
496496

497+
variable "attach_create_log_group_permission" {
498+
description = "Controls whether to add the create log group permission to the CloudWatch logs policy"
499+
type = bool
500+
default = true
501+
}
502+
497503
variable "attach_dead_letter_policy" {
498504
description = "Controls whether SNS/SQS dead letter notification policy should be added to IAM role for Lambda Function"
499505
type = bool

wrappers/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module "wrapper" {
99
assume_role_policy_statements = try(each.value.assume_role_policy_statements, var.defaults.assume_role_policy_statements, {})
1010
attach_async_event_policy = try(each.value.attach_async_event_policy, var.defaults.attach_async_event_policy, false)
1111
attach_cloudwatch_logs_policy = try(each.value.attach_cloudwatch_logs_policy, var.defaults.attach_cloudwatch_logs_policy, true)
12+
attach_create_log_group_permission = try(each.value.attach_create_log_group_permission, var.defaults.attach_create_log_group_permission, true)
1213
attach_dead_letter_policy = try(each.value.attach_dead_letter_policy, var.defaults.attach_dead_letter_policy, false)
1314
attach_network_policy = try(each.value.attach_network_policy, var.defaults.attach_network_policy, false)
1415
attach_policies = try(each.value.attach_policies, var.defaults.attach_policies, false)

0 commit comments

Comments
 (0)