44 policy_path = " ${ path . root } /policies"
55}
66
7+ # Select the Policy folder
78data "aws_iam_policy_document" "logs_policy_document" {
89 source_policy_documents = [templatefile (" ${ local . policy_path } /log.json" , {})]
910}
@@ -57,6 +58,20 @@ data "aws_iam_policy_document" "imms_policy_document" {
5758 ]
5859}
5960
61+ data "aws_iam_policy_document" "imms_data_quality_s3_doc" {
62+ source_policy_documents = [
63+ templatefile (" ${ local . policy_path } /s3_data_quality_access.json" , {
64+ s3_bucket_arn = aws_s3_bucket.data_quality_reports_bucket.arn
65+ kms_key_arn = data.aws_kms_key.existing_s3_encryption_key.arn
66+ })
67+ ]
68+ }
69+
70+ resource "aws_iam_policy" "imms_s3_kms_policy" {
71+ name = " ${ local . short_prefix } -s3-kms-policy"
72+ policy = data. aws_iam_policy_document . imms_data_quality_s3_doc . json
73+ }
74+
6075module "imms_event_endpoint_lambdas" {
6176 source = " ./modules/lambda"
6277 count = length (local. imms_endpoints )
@@ -71,6 +86,19 @@ module "imms_event_endpoint_lambdas" {
7186 vpc_security_group_ids = [data . aws_security_group . existing_securitygroup . id ]
7287}
7388
89+
90+ # Attach data quality report S3 bucket and KMS policy only to "create_imms" and "update_imms" endpoints
91+ resource "aws_iam_role_policy_attachment" "attach_data_quality_s3_to_specific_lambdas" {
92+ for_each = {
93+ for i , mod in module . imms_event_endpoint_lambdas :
94+ local.imms_endpoints[i] => mod
95+ if local . imms_endpoints [i ] == " create_imms" || local . imms_endpoints [i ] == " update_imms"
96+ }
97+
98+ role = each. value . lambda_role_name
99+ policy_arn = aws_iam_policy. imms_s3_kms_policy . arn
100+ }
101+
74102locals {
75103 # Mapping outputs with each called lambda
76104 imms_lambdas = {
0 commit comments