Closed iret-m-murakami closed 1 week ago
Voting for Prioritization
Volunteering to Work on This Issue
Hey @iret-m-murakami 👋 Thank you for taking the time to raise this! I can see why you would expect the aws_wafv2_web_acl
resource to behave in the way that you're describing, but that's not quite how the ignore_changes
meta-argument works. With ignore_changes
in place, Terraform will ignore any changes that it detects to the given argument(s) when detecting drift, but that doesn't necessarily guarantee that those values won't be modified at all.
Looking at the supplied plan output, Terraform isn't reporting a drift for rule
, but is detecting drift on visibility_config.sampled_requests_enabled
, which Terraform is attempting to correct. The reference for the upstream API that's used has the following note:
This operation completely replaces the mutable specifications that you already have for the web ACL with the ones that you provide to this call.
Because of how the upstream API operates, the value set for rule
must be included in the UpdateWebACL
call. In your case, that value is unset, which is causing the rule(s) to be removed.
There's a couple of ways to get around this. The first would be to define any expected rules in rule
block(s), adhering more strictly to Terraform's declarative nature. If this isn't possible for some reason, and the ignore_changes
route must be taken, you'll need to ensure that no other values are attempted to be updated, given the note from the upstream API above. From my personal perspective, that direction severely limits the utility of managing the Web ACL with Terraform, but I recognize that a confluence of the upstream API's limitations and potential organizational limitations might force you into taking that path.
If the upstream API were to change such that the above note was no longer relevant, we'd be happy to look into this again. As it stands, however, this appears to be working as expected. With that in mind, since there's no action for the AWS Provider team to take at this time, I'm going to close this issue. If you encounter any other unexpected behavior, please do let us know!
[!WARNING] This issue has been closed, meaning that any additional comments are hard for our team to see. Please assume that the maintainers will not see them.
Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed.
Terraform Core Version
1.5.7
AWS Provider Version
5.65.0
Affected Resource(s)
aws_wafv2_web_acl
Expected Behavior
Rule and rule groups added outside Terraform are retained
Actual Behavior
Rules were deleted
Relevant Error/Panic Output Snippet
Terraform Configuration Files
Steps to Reproduce
Create Web ACL with no rule using the Terraform configuration file Note that
rule
is in the ignore_changes listAdd rule and/or rule group to the Web ACL via AWS console Type of rules (rule/rule group/managed rule group) doesn't matter. e.g. AWSManagedRulesCommonRuleSet
Change other attribute of Web ACL via AWS console e.g. change sampled requests from true -> false
Execute
terraform appy -refresh-only
This is unnecessary to reproduce the issue, but just to make sure state refresh is performedterraform apply
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: ~ update in-place
Terraform will perform the following actions:
aws_wafv2_web_acl.webacl will be updated in-place
~ resource "aws_wafv2_web_acl" "webacl" { id = "d9d57833-2e71-46ec-8077-8e257a917abd" name = "test-waf" tags = {}
(9 unchanged attributes hidden)
Plan: 0 to add, 1 to change, 0 to destroy.