|
| 1 | +module "access-audit-gateway" { |
| 2 | + # Gateway Variables |
| 3 | + source = "./modules/gateway" |
| 4 | + api_gateway_id = aws_api_gateway_rest_api.ndr_doc_store_api.id |
| 5 | + parent_id = aws_api_gateway_rest_api.ndr_doc_store_api.root_resource_id |
| 6 | + http_methods = ["POST"] |
| 7 | + authorization = "CUSTOM" |
| 8 | + gateway_path = "AccessAudit" |
| 9 | + authorizer_id = aws_api_gateway_authorizer.repo_authoriser.id |
| 10 | + require_credentials = true |
| 11 | + origin = contains(["prod"], terraform.workspace) ? "'https://${var.domain}'" : "'https://${terraform.workspace}.${var.domain}'" |
| 12 | + |
| 13 | + # Lambda Variables |
| 14 | + api_execution_arn = aws_api_gateway_rest_api.ndr_doc_store_api.execution_arn |
| 15 | + owner = var.owner |
| 16 | + environment = var.environment |
| 17 | + |
| 18 | + depends_on = [ |
| 19 | + aws_api_gateway_rest_api.ndr_doc_store_api, |
| 20 | + ] |
| 21 | +} |
| 22 | + |
| 23 | +module "access-audit-alarm" { |
| 24 | + source = "./modules/lambda_alarms" |
| 25 | + lambda_function_name = module.access-audit-lambda.function_name |
| 26 | + lambda_timeout = module.access-audit-lambda.timeout |
| 27 | + lambda_name = "access_audit_handler" |
| 28 | + namespace = "AWS/Lambda" |
| 29 | + alarm_actions = [module.access-audit-alarm-topic.arn] |
| 30 | + ok_actions = [module.access-audit-alarm-topic.arn] |
| 31 | + depends_on = [module.access-audit-lambda, module.access-audit-alarm-topic] |
| 32 | +} |
| 33 | + |
| 34 | + |
| 35 | +module "access-audit-alarm-topic" { |
| 36 | + source = "./modules/sns" |
| 37 | + sns_encryption_key_id = module.sns_encryption_key.id |
| 38 | + current_account_id = data.aws_caller_identity.current.account_id |
| 39 | + topic_name = "access-audit-alarms-topic" |
| 40 | + topic_protocol = "lambda" |
| 41 | + topic_endpoint = module.access-audit-lambda.lambda_arn |
| 42 | + depends_on = [module.sns_encryption_key] |
| 43 | + delivery_policy = jsonencode({ |
| 44 | + "Version" : "2012-10-17", |
| 45 | + "Statement" : [ |
| 46 | + { |
| 47 | + "Effect" : "Allow", |
| 48 | + "Principal" : { |
| 49 | + "Service" : "cloudwatch.amazonaws.com" |
| 50 | + }, |
| 51 | + "Action" : [ |
| 52 | + "SNS:Publish", |
| 53 | + ], |
| 54 | + "Condition" : { |
| 55 | + "ArnLike" : { |
| 56 | + "aws:SourceArn" : "arn:aws:cloudwatch:eu-west-2:${data.aws_caller_identity.current.account_id}:alarm:*" |
| 57 | + } |
| 58 | + } |
| 59 | + "Resource" : "*" |
| 60 | + } |
| 61 | + ] |
| 62 | + }) |
| 63 | +} |
| 64 | + |
| 65 | +module "access-audit-lambda" { |
| 66 | + source = "./modules/lambda" |
| 67 | + name = "AccessAuditLambda" |
| 68 | + handler = "handlers.access_audit_handler.lambda_handler" |
| 69 | + iam_role_policy_documents = [ |
| 70 | + module.ndr-app-config.app_config_policy, |
| 71 | + module.auth_session_dynamodb_table.dynamodb_write_policy_document, |
| 72 | + module.auth_session_dynamodb_table.dynamodb_read_policy_document, |
| 73 | + module.access_audit_dynamodb_table.dynamodb_write_policy_document |
| 74 | + ] |
| 75 | + rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id |
| 76 | + resource_id = module.access-audit-gateway.gateway_resource_id |
| 77 | + http_methods = ["POST"] |
| 78 | + |
| 79 | + api_execution_arn = aws_api_gateway_rest_api.ndr_doc_store_api.execution_arn |
| 80 | + lambda_environment_variables = { |
| 81 | + APPCONFIG_APPLICATION = module.ndr-app-config.app_config_application_id |
| 82 | + APPCONFIG_ENVIRONMENT = module.ndr-app-config.app_config_environment_id |
| 83 | + APPCONFIG_CONFIGURATION = module.ndr-app-config.app_config_configuration_profile_id |
| 84 | + WORKSPACE = terraform.workspace |
| 85 | + AUTH_SESSION_TABLE_NAME = "${terraform.workspace}_${var.auth_session_dynamodb_table_name}" |
| 86 | + ACCESS_AUDIT_TABLE_NAME = "${terraform.workspace}_${var.access_audit_dynamodb_table_name}" |
| 87 | + } |
| 88 | + depends_on = [ |
| 89 | + aws_api_gateway_rest_api.ndr_doc_store_api, |
| 90 | + module.access-audit-gateway, |
| 91 | + module.ndr-app-config, |
| 92 | + ] |
| 93 | +} |
0 commit comments