terraform-linters / tflint-ruleset-google

TFLint ruleset for terraform-provider-google
Mozilla Public License 2.0
69 stars 20 forks source link

Unexpected JSON parsing error #129

Closed tgolsson closed 2 years ago

tgolsson commented 2 years ago

Hello!

I'm running into an issue with linting our audit resources, and as far as I can tell our setup is correct, and the JSON is valid. Running tflint on the following data:

{
   "resource": {
      "google_project_iam_audit_config": {
         "iam-audit-conf": {
            "audit_log_config": [
               {
                  "log_type": "DATA_WRITE"
               }
            ],
            "service": "iam.googleapis.com"
         },
         "logging-audit-conf": {
            "audit_log_config": [
               {
                  "log_type": "DATA_READ"
               },
               {
                  "log_type": "ADMIN_READ"
               }
            ],
            "service": "logging.googleapis.com"
         }
      }
   }
}

Generates the following error:

Failed to check ruleset. An error occurred:

Error: Failed to check `google_project_iam_audit_config_invalid_member` rule: xxx.tf.json:3,22-23: Unclosed object; No closing bracket was found for this JSON array., and 1 other diagnostic(s)

This seems like a parsing error in this library, but I've not been able to locate why/where so far. Any thoughts?

wata727 commented 2 years ago

This seems to be a bug in WalkResourceBlocks. When transferring blocks between plugins, it is necessary to extract the target block (audit_log_config in this case) from the Terraform configuration, but there is a problem with this range extraction in JSON syntax. https://github.com/terraform-linters/tflint/blob/v0.33.1/tflint/terraform.go#L107-L108

I'm working on a redesign of the plugin API to resolve this problem. Once this is done, this kind of problem will be resolved. https://github.com/terraform-linters/tflint-plugin-sdk/issues/89

As a workaround, I think it can be avoided by using the WalkResources API instead.

tgolsson commented 2 years ago

Thank you @wata727!