Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: aws_cloudwatch_log_account_policy not updating after first failed update #41036

Open
clementdenis opened this issue Jan 22, 2025 · 1 comment
Labels
bug Addresses a defect in current functionality. service/logs Issues and PRs that pertain to the logs service.

Comments

@clementdenis
Copy link

Terraform Core Version

1.10.4

AWS Provider Version

5.84.0

Affected Resource(s)

aws_cloudwatch_log_account_policy

Expected Behavior

When an error occurs updating aws_cloudwatch_log_account_policy after changing its policy_document argument, next plan / apply should see that the resource needs updating.

Actual Behavior

After an error updating a aws_cloudwatch_log_account_policy resource, next plan / apply don't see that policy_document is not up to date, resulting in hidden drift with target infrastructure.

Relevant Error/Panic Output Snippet

When updating the policy_document attribute of an aws_cloudwatch_log_account_policy, it's possible that the AWS API returns an error (happens when the RoleArn in a subscription filter policy does not exists or does not have required permissions for example)


aws_cloudwatch_log_account_policy.log_subscription: Modifying... [id=ForwardLogsToDatadog]

│ Error: putting CloudWatch Logs Account Policy (ForwardLogsToDatadog): operation error CloudWatch Logs: PutAccountPolicy, https response error StatusCode: 400, RequestID: 1d5a2209-c211-41ba-aafb-d8e564da644f, InvalidParameterException: Could not deliver test message to specified Firehose stream. Check if the given Firehose stream is in ACTIVE state.

│   with aws_cloudwatch_log_account_policy.log_subscription,
│   on main.tf line 198, in resource "aws_cloudwatch_log_account_policy" "log_subscription":
│  198: resource "aws_cloudwatch_log_account_policy" "log_subscription" {

Terraform Configuration Files

First apply to create the resource:

//acutal DestinationArn does not matter

resource "aws_cloudwatch_log_account_policy" "log_subscription" {
  policy_name        = "ForwardLogsToDatadog"
  policy_type        = "SUBSCRIPTION_FILTER_POLICY"
  policy_document = {\"RoleArn\":\"ExistingRoleWithCorrectPermissions\",\"DestinationArn\":\"${aws_kinesis_firehose_delivery_stream.log_firehose.arn}\",\"FilterPattern\":\"\",\"Distribution\":\"Random\"}"
}

Next applies to try to update the resource (will fail because of RoleThatDoesNotExist)

//acutal DestinationArn does not matter

resource "aws_cloudwatch_log_account_policy" "log_subscription" {
  policy_name        = "ForwardLogsToDatadog"
  policy_type        = "SUBSCRIPTION_FILTER_POLICY"
  policy_document = {\"RoleArn\":\"RoleThatDoesNotExist\",\"DestinationArn\":\"${aws_kinesis_firehose_delivery_stream.log_firehose.arn}\",\"FilterPattern\":\"\",\"Distribution\":\"Random\"}"
}

Steps to Reproduce

  • Apply a plan that correctly creates a aws_cloudwatch_log_account_policy resource
  • Make a change to the policy_document argument (like changing RoleArn to an non-existing role) that will result in an error during apply
  • Apply again => you get a 400 / InvalidParameterException error, and the policy is not updated to the expected value
  • Apply again => you should get the same error, but instead there's no change

Debug Output

No response

Panic Output

No response

Important Factoids

The same problem does not happen with an invalid selection_criteria, as this argument forces replacement => maybe adding ForceNew: true to policy_document is enough to fix this.

References

Initially implemented in #38328

Would you like to implement a fix?

No

@clementdenis clementdenis added the bug Addresses a defect in current functionality. label Jan 22, 2025
Copy link

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@github-actions github-actions bot added service/logs Issues and PRs that pertain to the logs service. needs-triage Waiting for first response or review from a maintainer. labels Jan 22, 2025
@justinretzolk justinretzolk removed the needs-triage Waiting for first response or review from a maintainer. label Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Addresses a defect in current functionality. service/logs Issues and PRs that pertain to the logs service.
Projects
None yet
Development

No branches or pull requests

2 participants