hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.71k stars 9.07k forks source link

[Bug]: Error: Failure to import and generate config for existing aws_wafv2_web_acl resource #36821

Open nmogbuk opened 4 months ago

nmogbuk commented 4 months ago

Terraform Core Version

1.7.5

AWS Provider Version

4.67.0

Affected Resource(s)

aws_wafv2_web_acl

Expected Behavior

Generate configuration successfully for existing WAF ACL

Actual Behavior

Terraform plan fails with the following error:

**_setting rule: Invalid address to set: []string{"rule", "5", "statement", "0", "managed_rule_group_statement", "0", "rule_action_override", "5", "action_to_use", "0", "challenge"}_**

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

import {
    to = aws_wafv2_web_acl.development
    id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/acl-name/REGIONAL"
}

Steps to Reproduce

Create an import block and run terraform plan: terraform plan -generate-config-out=gen.tf

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

github-actions[bot] commented 4 months ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

ZsoltPath commented 1 month ago

Yeah, I'm getting the same issue.

The actual offending rule in JSON is:

{
  "Name": "AdminProtection_exclusion_rule",
  "Priority": 121,
  "Statement": {
    "AndStatement": {
      "Statements": [
        {
          "LabelMatchStatement": {
            "Scope": "LABEL",
            "Key": "awswaf:managed:aws:admin-protection:AdminProtection_URIPath"
          }
        },
        {
          "NotStatement": {
            "Statement": {
              "OrStatement": {
                "Statements": [
                  {
                    "AndStatement": {
                      "Statements": [
                        {
                          "RegexPatternSetReferenceStatement": {
                            "ARN": "arn:aws:wafv2:us-east-1:**********:global/regexpatternset/admin/722ead4c-3ace-4ea0-b4b5-82fcdeca50bd",
                            "FieldToMatch": {
                              "UriPath": {}
                            },
                            "TextTransformations": [
                              {
                                "Priority": 1,
                                "Type": "NONE"
                              }
                            ]
                          }
                        },
                        {
                          "RegexPatternSetReferenceStatement": {
                            "ARN": "arn:aws:wafv2:us-east-1:********:global/regexpatternset/api/cbc944e7-d71f-432e-93d0-ad10127a3a2a",
                            "FieldToMatch": {
                              "SingleHeader": {
                                "Name": "host"
                              }
                            },
                            "TextTransformations": [
                              {
                                "Priority": 1,
                                "Type": "LOWERCASE"
                              }
                            ]
                          }
                        }
                      ]
                    }
                  },
                  {
                    "RegexPatternSetReferenceStatement": {
                      "ARN": "arn:aws:wafv2:us-east-1:***********:global/regexpatternset/test/73899147-af20-4370-ac21-d6402e469312",
                      "FieldToMatch": {
                        "UriPath": {}
                      },
                      "TextTransformations": [
                        {
                          "Priority": 1,
                          "Type": "NONE"
                        }
                      ]
                    }
                  }
                ]
              }
            }
          }
        }
      ]
    }
  },
  "Action": {
    "Block": {}
  },
  "VisibilityConfig": {
    "SampledRequestsEnabled": false,
    "CloudWatchMetricsEnabled": false,
    "MetricName": "rfi-body-metric"
  }
}

I also tried to define the same first in TF, but got syntax error. registry.terraform.io/hashicorp/aws v5.57.0