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

"invalid reference" error with lifecycle.ignore_changes #1474

Closed
LiuVII opened this issue Aug 8, 2022 · 2 comments · Fixed by #1478
Closed

"invalid reference" error with lifecycle.ignore_changes #1474

LiuVII opened this issue Aug 8, 2022 · 2 comments · Fixed by #1478
Labels

Comments

@LiuVII
Copy link

LiuVII commented Aug 8, 2022

Introduction

When lifecycle ignore_changes block contains data e.g.

resource "kubernetes_secret" "my_secret" {
  metadata {
   ...
  }

  data = {
   ...
  }

  lifecycle {
    ignore_changes = [
      data
    ]
  }
}

Tflint shows a warning on it.

Expected Behavior

This shouldn't cause any issues

Actual behavior

Tflint shows this warning on this code

Error: Invalid reference; The "data" object must be followed by two attribute names: the data source type and the resource name.

Additional Context

$ tflint -v
TFLint version 0.39.2
$ terraform -v
Terraform v1.1.4
@bendrucker bendrucker changed the title False positive "invalid reference" warning when using "data" in lifecylce ignore_changes block "invalid reference" error with lifecycle.ignore_changes Aug 8, 2022
@wata727
Copy link
Member

wata727 commented Aug 8, 2022

Thank you for reporting this.

This is probably caused by creating references for all expressions including ignore_changes since v0.39.0. See #1432.
Normally, unknown references are ignored, but unfortunately the data seems to be misidentified as a reference to a data resource here:
https://github.com/terraform-linters/tflint/blob/v0.39.2/rules/terraformrules/utils.go#L291-L299

This issue doesn't occur in Terraform as it doesn't generate references to ignore_changes. We should avoid this case in its own way. It's a hard question to work around, but running terraform validate can catch reference errors, so one idea is to ignore the errors for now.

@LiuVII
Copy link
Author

LiuVII commented Aug 12, 2022

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants