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

Linting tftest.hcl files #2128

Open
wyardley opened this issue Sep 20, 2024 · 3 comments
Open

Linting tftest.hcl files #2128

wyardley opened this issue Sep 20, 2024 · 3 comments

Comments

@wyardley
Copy link

wyardley commented Sep 20, 2024

Summary

It sounds from #2030 like tftest.hcl files should be able to be linted.

It seems, however, as if tflint may not be parsing *.tftest.hcl files (it should also recurse into subdirectories when in recursive mode if there are directories with no .tf files but with .tftest.hcl files).

Taking a look at the code, including here, seems like some adjustments and tests might be needed for this to work?

In the example below, if the file is renamed to .tf, tflint will correctly flag google_storage_bucket.foo.bar.0.main_page_suffix vs google_storage_bucket.foo.bar[0].main_page_suffix being used.

Terraform Configuration

provider "google" {
  project = "foo-testproject"
}
variables {
  name    = "test-me"
}
run "basic" {
  command = plan
  plan_options {
    refresh = false
  }

  assert {
    condition     = google_storage_bucket.foo.bar.0.main_page_suffix == "index.html"
    error_message = "Incorrect website main page suffix."
  }
}
@wata727
Copy link
Member

wata727 commented Sep 23, 2024

Thank you for raising this feature request.

We probably can't just use the current evaluator and parser as is because the test language has different semantics than the Terraform language. We would need to implement a dedicated emulator stack for the test language, which would require a fairly large refactoring.

See also #1949

@wyardley
Copy link
Author

A lot of the things can be parsed as-is, since the assertions are used in things like validation conditions. Even though there are some new fields possibly, I get at least some value (list index style for example) simply by renaming the files, and don’t notice any errors from the attributes that maybe tflint doesn’t know about.

@wyardley
Copy link
Author

https://developer.hashicorp.com/terraform/language/tests/mocking

.tfmock.hcl and .tfmock.json -- two more test specific files

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

No branches or pull requests

3 participants