Skip to content

Commit c2365af

Browse files
authored
clean: we should only need tags here (#55)
* chore: we should only need tags here * fix: adding the exclusion on the trivy secuirty scanning
1 parent 63b3ebf commit c2365af

File tree

8 files changed

+51
-110
lines changed

8 files changed

+51
-110
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ todo.md
3434
*.swp
3535
*.swo
3636

37-
# Irgnore meld diff files
37+
# Ignore meld diff files
3838
*.orig
3939
*.backup
4040
*.rej
4141

42+
# Ignore lambda zip files and build directories
43+
*.zip
44+
builds/

.trivyignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ AVD-DS-0015 # (Dockerfile) Purge Yum Package Cache - https://avd.aquasec.com/mis
33
AVD-DS-0002 # (Dockerfile) Least Privilege User - https://avd.aquasec.com/misconfig/dockerfile/general/avd-ds-0002/
44
AVD-DS-0026 # (Dockerfile) No Healthcheck - https://avd.aquasec.com/misconfig/dockerfile/general/avd-ds-0026/
55
AVD-DS-0013 # (Dockerfile) Use Workdir Over Cd - https://avd.aquasec.com/misconfig/dockerfile/general/avd-ds-0013/
6+
AVD-AWS-0095 # https://avd.aquasec.com/misconfig/aws/sns/avd-aws-0095/

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ init:
7171
@echo "--> Running terraform init"
7272
@terraform init -backend=false
7373

74-
security:
74+
security: init
7575
@echo "--> Running Security checks"
7676
@trivy config .
7777
$(MAKE) security-modules
@@ -81,13 +81,15 @@ security-modules:
8181
@echo "--> Running Security checks on modules"
8282
@find . -type d -regex '.*/modules/[a-zA-Z\-_$$]*' -not -path '*.terraform*' 2>/dev/null | while read -r dir; do \
8383
echo "--> Validating $$dir"; \
84+
terraform init -backend=false; \
8485
trivy config --format table --exit-code 1 --severity CRITICAL,HIGH --ignorefile .trivyignore $$dir; \
8586
done;
8687

8788
security-examples:
8889
@echo "--> Running Security checks on examples"
8990
@find . -type d -path '*/examples/*' -not -path '*.terraform*' 2>/dev/null | while read -r dir; do \
9091
echo "--> Validating $$dir"; \
92+
terraform init -backend=false; \
9193
trivy config --format table --exit-code 1 --severity CRITICAL,HIGH --ignorefile .trivyignore $$dir; \
9294
done;
9395

main.tf

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,15 @@ module "notify" {
4747
accounts_id_to_name = var.accounts_id_to_name
4848
cloudwatch_log_group_kms_key_id = var.cloudwatch_log_group_kms_key_id
4949
cloudwatch_log_group_retention_in_days = var.cloudwatch_log_group_retention
50-
cloudwatch_log_group_tags = var.tags
5150
create_sns_topic = false
5251
delivery_channels = local.channels_config
5352
enable_slack = var.enable_slack
5453
enable_teams = var.enable_teams
55-
iam_role_tags = var.tags
5654
identity_center_role = var.identity_center_role
5755
identity_center_start_url = var.identity_center_start_url
58-
lambda_function_tags = var.tags
5956
post_icons_url = var.post_icons_url
6057
recreate_missing_package = false
6158
sns_topic_name = var.sns_topic_name
62-
sns_topic_tags = var.tags
6359
tags = var.tags
6460

6561
depends_on = [module.sns]

modules/notify/README.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,19 @@ Subsumed by appvia's GNU V3 license; [see license](../../LICENSE).
9494
| Name | Version |
9595
|------|---------|
9696
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.8 |
97-
| <a name="provider_local"></a> [local](#provider\_local) | n/a |
97+
| <a name="provider_local"></a> [local](#provider\_local) | >= 2.5.0 |
9898

9999
## Inputs
100100

101101
| Name | Description | Type | Default | Required |
102102
|------|-------------|------|---------|:--------:|
103103
| <a name="input_sns_topic_name"></a> [sns\_topic\_name](#input\_sns\_topic\_name) | The name of the SNS topic to create | `string` | n/a | yes |
104+
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | n/a | yes |
104105
| <a name="input_accounts_id_to_name"></a> [accounts\_id\_to\_name](#input\_accounts\_id\_to\_name) | A mapping of account id and account name - used by notification lamdba to map an account ID to a human readable name | `map(string)` | `{}` | no |
105106
| <a name="input_architecture"></a> [architecture](#input\_architecture) | Instruction set architecture for your Lambda function. Valid values are "x86\_64" or "arm64". | `string` | `"arm64"` | no |
106107
| <a name="input_aws_powertools_service_name"></a> [aws\_powertools\_service\_name](#input\_aws\_powertools\_service\_name) | The service name to use | `string` | `"appvia-notifications"` | no |
107108
| <a name="input_cloudwatch_log_group_kms_key_id"></a> [cloudwatch\_log\_group\_kms\_key\_id](#input\_cloudwatch\_log\_group\_kms\_key\_id) | The ARN of the KMS Key to use when encrypting log data for Lambda | `string` | `null` | no |
108109
| <a name="input_cloudwatch_log_group_retention_in_days"></a> [cloudwatch\_log\_group\_retention\_in\_days](#input\_cloudwatch\_log\_group\_retention\_in\_days) | Specifies the number of days you want to retain log events in log group for Lambda. | `number` | `0` | no |
109-
| <a name="input_cloudwatch_log_group_tags"></a> [cloudwatch\_log\_group\_tags](#input\_cloudwatch\_log\_group\_tags) | Additional tags for the Cloudwatch log group | `map(string)` | `{}` | no |
110110
| <a name="input_create"></a> [create](#input\_create) | Whether to create all resources | `bool` | `true` | no |
111111
| <a name="input_create_sns_topic"></a> [create\_sns\_topic](#input\_create\_sns\_topic) | Whether to create new SNS topic | `bool` | `true` | no |
112112
| <a name="input_delivery_channels"></a> [delivery\_channels](#input\_delivery\_channels) | The configuration for Slack notifications | <pre>map(object({<br/> lambda_name = optional(string, "delivery_channel")<br/> # The name of the lambda function to create<br/> lambda_description = optional(string, "Lambda function to send notifications")<br/> # The description for the lambda<br/> secret_name = optional(string)<br/> # An optional secret name in secrets manager to use for the slack configuration <br/> webhook_url = optional(string)<br/> # The webhook url to post to<br/> filter_policy = optional(string)<br/> # An optional SNS subscription filter policy to apply<br/> filter_policy_scope = optional(string)<br/> # If filter policy provided this is the scope of that policy; either "MessageAttributes" (default) or "MessageBody"<br/> }))</pre> | `null` | no |
@@ -115,9 +115,8 @@ Subsumed by appvia's GNU V3 license; [see license](../../LICENSE).
115115
| <a name="input_enable_teams"></a> [enable\_teams](#input\_enable\_teams) | To send to teams, set to true | `bool` | `false` | no |
116116
| <a name="input_iam_policy_path"></a> [iam\_policy\_path](#input\_iam\_policy\_path) | Path of policies to that should be added to IAM role for Lambda Function | `string` | `null` | no |
117117
| <a name="input_iam_role_boundary_policy_arn"></a> [iam\_role\_boundary\_policy\_arn](#input\_iam\_role\_boundary\_policy\_arn) | The ARN of the policy that is used to set the permissions boundary for the role | `string` | `null` | no |
118-
| <a name="input_iam_role_name_prefix"></a> [iam\_role\_name\_prefix](#input\_iam\_role\_name\_prefix) | A unique role name beginning with the specified prefix | `string` | `"lambda"` | no |
118+
| <a name="input_iam_role_name_prefix"></a> [iam\_role\_name\_prefix](#input\_iam\_role\_name\_prefix) | A unique role name beginning with the specified prefix | `string` | `"lza"` | no |
119119
| <a name="input_iam_role_path"></a> [iam\_role\_path](#input\_iam\_role\_path) | Path of IAM role to use for Lambda Function | `string` | `null` | no |
120-
| <a name="input_iam_role_tags"></a> [iam\_role\_tags](#input\_iam\_role\_tags) | Additional tags for the IAM role | `map(string)` | `{}` | no |
121120
| <a name="input_identity_center_role"></a> [identity\_center\_role](#input\_identity\_center\_role) | The name of the role to use when redirecting through Identity Center | `string` | `null` | no |
122121
| <a name="input_identity_center_start_url"></a> [identity\_center\_start\_url](#input\_identity\_center\_start\_url) | The start URL of your Identity Center instance | `string` | `null` | no |
123122
| <a name="input_kms_key_arn"></a> [kms\_key\_arn](#input\_kms\_key\_arn) | ARN of the KMS key used for decrypting slack webhook url | `string` | `""` | no |
@@ -126,7 +125,6 @@ Subsumed by appvia's GNU V3 license; [see license](../../LICENSE).
126125
| <a name="input_lambda_function_ephemeral_storage_size"></a> [lambda\_function\_ephemeral\_storage\_size](#input\_lambda\_function\_ephemeral\_storage\_size) | Amount of ephemeral storage (/tmp) in MB your Lambda Function can use at runtime. Valid value between 512 MB to 10,240 MB (10 GB). | `number` | `512` | no |
127126
| <a name="input_lambda_function_s3_bucket"></a> [lambda\_function\_s3\_bucket](#input\_lambda\_function\_s3\_bucket) | S3 bucket to store artifacts | `string` | `null` | no |
128127
| <a name="input_lambda_function_store_on_s3"></a> [lambda\_function\_store\_on\_s3](#input\_lambda\_function\_store\_on\_s3) | Whether to store produced artifacts on S3 or locally. | `bool` | `false` | no |
129-
| <a name="input_lambda_function_tags"></a> [lambda\_function\_tags](#input\_lambda\_function\_tags) | Additional tags for the Lambda function | `map(string)` | `{}` | no |
130128
| <a name="input_lambda_function_vpc_security_group_ids"></a> [lambda\_function\_vpc\_security\_group\_ids](#input\_lambda\_function\_vpc\_security\_group\_ids) | List of security group ids when Lambda Function should run in the VPC. | `list(string)` | `null` | no |
131129
| <a name="input_lambda_function_vpc_subnet_ids"></a> [lambda\_function\_vpc\_subnet\_ids](#input\_lambda\_function\_vpc\_subnet\_ids) | List of subnet ids when Lambda Function should run in the VPC. Usually private or intra subnets. | `list(string)` | `null` | no |
132130
| <a name="input_lambda_role"></a> [lambda\_role](#input\_lambda\_role) | IAM role attached to the Lambda Function. If this is set then a role will not be created for you. | `string` | `""` | no |
@@ -141,12 +139,9 @@ Subsumed by appvia's GNU V3 license; [see license](../../LICENSE).
141139
| <a name="input_sns_topic_feedback_role_name"></a> [sns\_topic\_feedback\_role\_name](#input\_sns\_topic\_feedback\_role\_name) | Name of the IAM role to use for SNS topic delivery status logging | `string` | `null` | no |
142140
| <a name="input_sns_topic_feedback_role_path"></a> [sns\_topic\_feedback\_role\_path](#input\_sns\_topic\_feedback\_role\_path) | Path of IAM role to use for SNS topic delivery status logging | `string` | `null` | no |
143141
| <a name="input_sns_topic_feedback_role_permissions_boundary"></a> [sns\_topic\_feedback\_role\_permissions\_boundary](#input\_sns\_topic\_feedback\_role\_permissions\_boundary) | The ARN of the policy that is used to set the permissions boundary for the IAM role used by SNS topic delivery status logging | `string` | `null` | no |
144-
| <a name="input_sns_topic_feedback_role_tags"></a> [sns\_topic\_feedback\_role\_tags](#input\_sns\_topic\_feedback\_role\_tags) | A map of tags to assign to IAM the SNS topic feedback role | `map(string)` | `{}` | no |
145142
| <a name="input_sns_topic_kms_key_id"></a> [sns\_topic\_kms\_key\_id](#input\_sns\_topic\_kms\_key\_id) | ARN of the KMS key used for enabling SSE on the topic | `string` | `""` | no |
146143
| <a name="input_sns_topic_lambda_feedback_role_arn"></a> [sns\_topic\_lambda\_feedback\_role\_arn](#input\_sns\_topic\_lambda\_feedback\_role\_arn) | IAM role for SNS topic delivery status logs. If this is set then a role will not be created for you. | `string` | `""` | no |
147144
| <a name="input_sns_topic_lambda_feedback_sample_rate"></a> [sns\_topic\_lambda\_feedback\_sample\_rate](#input\_sns\_topic\_lambda\_feedback\_sample\_rate) | The percentage of successful deliveries to log | `number` | `100` | no |
148-
| <a name="input_sns_topic_tags"></a> [sns\_topic\_tags](#input\_sns\_topic\_tags) | Additional tags for the SNS topic | `map(string)` | `{}` | no |
149-
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no |
150145

151146
## Outputs
152147

modules/notify/iam.tf

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,11 @@ data "aws_iam_policy_document" "sns_feedback" {
2424
resource "aws_iam_role" "sns_feedback_role" {
2525
count = local.create_sns_feedback_role ? 1 : 0
2626

27-
name = var.sns_topic_feedback_role_name
27+
assume_role_policy = data.aws_iam_policy_document.sns_feedback[0].json
2828
description = var.sns_topic_feedback_role_description
29-
path = var.sns_topic_feedback_role_path
3029
force_detach_policies = var.sns_topic_feedback_role_force_detach_policies
30+
name = var.sns_topic_feedback_role_name
31+
path = var.sns_topic_feedback_role_path
3132
permissions_boundary = var.sns_topic_feedback_role_permissions_boundary
32-
assume_role_policy = data.aws_iam_policy_document.sns_feedback[0].json
33-
34-
tags = merge(
35-
var.tags,
36-
var.sns_topic_feedback_role_tags,
37-
)
33+
tags = var.tags
3834
}

modules/notify/main.tf

Lines changed: 36 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -116,26 +116,22 @@ data "aws_iam_policy_document" "lambda" {
116116
resource "aws_cloudwatch_log_group" "lambda" {
117117
for_each = local.distributions
118118

119+
kms_key_id = var.cloudwatch_log_group_kms_key_id
119120
name = "/aws/lambda/${var.delivery_channels[each.value].lambda_name}"
120121
retention_in_days = var.cloudwatch_log_group_retention_in_days
121-
kms_key_id = var.cloudwatch_log_group_kms_key_id
122-
123-
tags = merge(var.tags, var.cloudwatch_log_group_tags)
122+
tags = var.tags
124123
}
125124

126125
#trivy:ignore:avd-aws-0095
127126
resource "aws_sns_topic" "this" {
128127
count = var.create_sns_topic && var.create ? 1 : 0
129128

130-
name = var.sns_topic_name
131-
132-
kms_master_key_id = var.sns_topic_kms_key_id
133-
129+
kms_master_key_id = var.sns_topic_kms_key_id
134130
lambda_failure_feedback_role_arn = var.enable_sns_topic_delivery_status_logs ? local.sns_feedback_role : null
135131
lambda_success_feedback_role_arn = var.enable_sns_topic_delivery_status_logs ? local.sns_feedback_role : null
136132
lambda_success_feedback_sample_rate = var.enable_sns_topic_delivery_status_logs ? var.sns_topic_lambda_feedback_sample_rate : null
137-
138-
tags = merge(var.tags, var.sns_topic_tags)
133+
name = var.sns_topic_name
134+
tags = var.tags
139135
}
140136

141137

@@ -211,17 +207,37 @@ module "lambda" {
211207
source = "terraform-aws-modules/lambda/aws"
212208
version = "7.10.0"
213209

214-
create = var.create
215-
216-
function_name = try(var.delivery_channels[each.value].lambda_name, "notify_${each.value}")
217-
description = try(var.delivery_channels[each.value].lambda_description, "")
218-
219-
hash_extra = each.value
220-
handler = "${local.lambda_handler[each.value]}.lambda_handler"
221-
222-
# source_path = var.lambda_source_path != null ? "${path.root}/${var.lambda_source_path}" : "${path.module}/functions/src/notify_${each.value}.py"
223-
# source_path = var.lambda_source_path != null ? "${path.root}/${var.lambda_source_path}" : "${path.module}/functions/src"
224-
210+
architectures = [var.architecture]
211+
attach_cloudwatch_logs_policy = false
212+
attach_dead_letter_policy = var.lambda_attach_dead_letter_policy
213+
attach_network_policy = var.lambda_function_vpc_subnet_ids != null
214+
attach_policy_json = true
215+
create = var.create
216+
create_role = var.lambda_role == ""
217+
dead_letter_target_arn = var.lambda_dead_letter_target_arn
218+
description = try(var.delivery_channels[each.value].lambda_description, "")
219+
ephemeral_storage_size = var.lambda_function_ephemeral_storage_size
220+
function_name = try(var.delivery_channels[each.value].lambda_name, "notify_${each.value}")
221+
handler = "${local.lambda_handler[each.value]}.lambda_handler"
222+
hash_extra = each.value
223+
kms_key_arn = var.kms_key_arn
224+
lambda_role = var.lambda_role
225+
policy_json = try(data.aws_iam_policy_document.lambda[each.value].json, "")
226+
policy_path = var.iam_policy_path
227+
recreate_missing_package = var.recreate_missing_package
228+
reserved_concurrent_executions = var.reserved_concurrent_executions
229+
role_name = "${var.iam_role_name_prefix}-${var.delivery_channels[each.value].lambda_name}"
230+
role_path = var.iam_role_path
231+
role_permissions_boundary = var.iam_role_boundary_policy_arn
232+
role_tags = var.tags
233+
runtime = var.python_runtime
234+
s3_bucket = var.lambda_function_s3_bucket
235+
store_on_s3 = var.lambda_function_store_on_s3
236+
tags = var.tags
237+
timeout = 10
238+
use_existing_cloudwatch_log_group = true
239+
vpc_security_group_ids = var.lambda_function_vpc_security_group_ids
240+
vpc_subnet_ids = var.lambda_function_vpc_subnet_ids
225241

226242
# Bug in this module when creating source bundles on updated code change:
227243
# `Error: Provider produced inconsistent final plan`
@@ -247,14 +263,6 @@ module "lambda" {
247263
}
248264
]
249265

250-
recreate_missing_package = var.recreate_missing_package
251-
runtime = var.python_runtime
252-
architectures = [var.architecture]
253-
timeout = 10
254-
kms_key_arn = var.kms_key_arn
255-
reserved_concurrent_executions = var.reserved_concurrent_executions
256-
ephemeral_storage_size = var.lambda_function_ephemeral_storage_size
257-
258266
# If publish is disabled, there will be "Error adding new Lambda Permission for notify_xxxxx:
259267
# InvalidParameterValueException: We currently do not support adding policies for $LATEST."
260268
publish = true
@@ -273,42 +281,13 @@ module "lambda" {
273281
}
274282
))
275283

276-
create_role = var.lambda_role == ""
277-
lambda_role = var.lambda_role
278-
role_name = "${var.iam_role_name_prefix}-${var.delivery_channels[each.value].lambda_name}"
279-
role_permissions_boundary = var.iam_role_boundary_policy_arn
280-
role_tags = var.iam_role_tags
281-
role_path = var.iam_role_path
282-
policy_path = var.iam_policy_path
283-
284-
# Do not use Lambda's policy for cloudwatch logs, because we have to add a policy
285-
# for KMS conditionally. This way attach_policy_json is always true independenty of
286-
# the value of presense of KMS. Famous "computed values in count" bug...
287-
attach_cloudwatch_logs_policy = false
288-
attach_policy_json = true
289-
policy_json = try(data.aws_iam_policy_document.lambda[each.value].json, "")
290-
291-
use_existing_cloudwatch_log_group = true
292-
attach_network_policy = var.lambda_function_vpc_subnet_ids != null
293-
294-
dead_letter_target_arn = var.lambda_dead_letter_target_arn
295-
attach_dead_letter_policy = var.lambda_attach_dead_letter_policy
296-
297284
allowed_triggers = {
298285
AllowExecutionFromSNS = {
299286
principal = "sns.amazonaws.com"
300287
source_arn = local.sns_topic_arn
301288
}
302289
}
303290

304-
store_on_s3 = var.lambda_function_store_on_s3
305-
s3_bucket = var.lambda_function_s3_bucket
306-
307-
vpc_subnet_ids = var.lambda_function_vpc_subnet_ids
308-
vpc_security_group_ids = var.lambda_function_vpc_security_group_ids
309-
310-
tags = merge(var.tags, var.lambda_function_tags)
311-
312291
depends_on = [
313292
aws_cloudwatch_log_group.lambda,
314293
local_file.notify_account_names_dict_python,

0 commit comments

Comments
 (0)