@@ -14,7 +14,13 @@ data "aws_iam_policy_document" "cwl_subscription_assume_role" {
1414
1515 principals {
1616 type = " Service"
17- identifiers = [" logs.${ var . default_aws_region } .amazonaws.com" ]
17+ identifiers = [" logs.amazonaws.com" ]
18+ }
19+
20+ condition {
21+ test = " StringEquals"
22+ variable = " aws:SourceAccount"
23+ values = [data . aws_caller_identity . current . account_id ]
1824 }
1925 }
2026}
@@ -33,39 +39,39 @@ resource "aws_iam_role" "cwl_subscription_role" {
3339 )
3440}
3541
36- # IAM policy to allow PutSubscriptionFilter on the existing API Gateway log group and CSOC destination
37- data "aws_iam_policy_document" "put_subscription_filter" {
42+ # IAM policy to allow CloudWatch Logs to write to the CSOC destination
43+ # This is the permission policy for the role that CloudWatch Logs assumes
44+ data "aws_iam_policy_document" "cwl_to_csoc_destination" {
3845 statement {
39- sid = " AllowPutAPIGSubFilter "
46+ sid = " AllowPutLogEventsToDestination "
4047 effect = " Allow"
4148 actions = [
42- " logs:PutSubscriptionFilter "
49+ " logs:PutLogEvents "
4350 ]
4451 resources = [
45- " ${ module . eligibility_signposting_api_gateway . cloudwatch_destination_arn } :*" ,
4652 " arn:aws:logs:${ var . default_aws_region } :693466633220:destination:api_gateway_log_destination"
4753 ]
4854 }
4955}
5056
51- resource "aws_iam_policy" "put_subscription_filter " {
52- name = " ${ var . environment } -${ local . workspace } -PutSubscriptionFilterPolicy "
53- description = " Policy to allow creating subscription filters for CSOC log forwarding "
54- policy = data. aws_iam_policy_document . put_subscription_filter . json
57+ resource "aws_iam_policy" "cwl_to_csoc_destination " {
58+ name = " ${ var . environment } -${ local . workspace } -CWLogsToCSOCDestinationPolicy "
59+ description = " Policy to allow CloudWatch Logs to write to CSOC destination "
60+ policy = data. aws_iam_policy_document . cwl_to_csoc_destination . json
5561
5662 tags = merge (
5763 local. tags ,
5864 {
59- Name = " ${ var . environment } -${ local . workspace } -PutSubscriptionFilterPolicy "
65+ Name = " ${ var . environment } -${ local . workspace } -CWLogsToCSOCDestinationPolicy "
6066 Purpose = " CSOC log forwarding"
6167 }
6268 )
6369}
6470
6571# Attach the policy to the subscription role
66- resource "aws_iam_role_policy_attachment" "put_subscription_filter " {
72+ resource "aws_iam_role_policy_attachment" "cwl_to_csoc_destination " {
6773 role = aws_iam_role. cwl_subscription_role . name
68- policy_arn = aws_iam_policy. put_subscription_filter . arn
74+ policy_arn = aws_iam_policy. cwl_to_csoc_destination . arn
6975}
7076
7177# Create the subscription filter to forward logs to CSOC
@@ -81,6 +87,6 @@ resource "aws_cloudwatch_log_subscription_filter" "csoc_forwarding" {
8187 depends_on = [
8288 module . eligibility_signposting_api_gateway ,
8389 aws_iam_role . cwl_subscription_role ,
84- aws_iam_role_policy_attachment . put_subscription_filter
90+ aws_iam_role_policy_attachment . cwl_to_csoc_destination
8591 ]
8692}
0 commit comments