Skip to content

Conversation

@Zephirin
Copy link

Fixes #35

What

Add `cloudwatch_log_group_principals` variable to allow overriding the CloudWatch Logs IAM role trust policy principals.

Why

The module currently uses the `cloudposse/cloudwatch-logs/aws` module which defaults to `ec2.amazonaws.com` as the principal service for the IAM role trust policy. This is incorrect for API Gateway, which requires `apigateway.amazonaws.com`, and causes deployment failures.

How

  • Add `cloudwatch_log_group_principals` variable with sensible default (`apigateway.amazonaws.com`)
  • Pass the variable through to the `cloudwatch_log_group` module
  • Maintain backward compatibility while fixing the issue

Impact

  • ✅ Fixes API Gateway deployments with CloudWatch logging enabled
  • ✅ Backward compatible - uses correct default
  • ✅ Allows customization if needed for edge cases
  • ✅ Existing tests should pass

Testing

  • Existing `examples/complete` test creates API Gateway with logging enabled
  • With this fix, the test should pass without IAM trust policy errors
  • Validated in production at Life360 (collision-response service migration)

References

@Zephirin Zephirin requested review from a team as code owners November 10, 2025 16:51
@Zephirin Zephirin requested review from jamengual and oycyc November 10, 2025 16:51
@mergify mergify bot added the triage Needs triage label Nov 10, 2025
…licy

Fixes cloudposse#35

## Problem
The module uses the cloudposse/cloudwatch-logs/aws module which defaults
to ec2.amazonaws.com as the principal service for the IAM role trust policy.
This is incorrect for API Gateway and causes deployment failures.

## Solution
Add a cloudwatch_log_group_principals variable that:
- Accepts a map of service principals for the CloudWatch Logs IAM role
- Defaults to apigateway.amazonaws.com (the correct principal)
- Passes through to the cloudwatch-logs module

## Impact
- Fixes API Gateway deployments with CloudWatch logging enabled
- Backward compatible - uses sensible default
- Allows overriding principals if needed for specific use cases

## Testing
Existing tests should pass as they now use the correct IAM principal.
The complete example creates an API Gateway with logging enabled and
verifies successful deployment.
Add comprehensive test to validate the fix for issue cloudposse#35:
- New example: examples/with-custom-principals
- Go test that validates IAM role trust policy contains apigateway.amazonaws.com
- Ensures API Gateway deploys successfully with CloudWatch logging enabled
- Validates the principals parameter works as expected
@Zephirin Zephirin force-pushed the fix/add-cloudwatch-principals-parameter branch from 7463a22 to cb8ce68 Compare November 10, 2025 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triage Needs triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

incorrect log-group role principal

1 participant