terraform-linters / tflint

A Pluggable Terraform Linter
Mozilla Public License 2.0
4.88k stars 354 forks source link

terraform: Add support for Terraform v1.6/v1.7/v1.8 #2030

Closed wata727 closed 5 months ago

wata727 commented 5 months ago

Fixes https://github.com/terraform-linters/tflint/issues/1878

This PR adds support for Terraform v1.6, v1.7, and v1.8. Specifically, support for the following features will be added:

A lot of the changes are just pulling upstream changes, but there are some tricks when it comes to supporting provider-defined functions.

Evaluating a provider-defined function requires running the Terraform provider plugin beforehand, which is clearly beyond the "static" scope of TFLint. Therefore, we had to adopt a different evaluation strategy. The idea here is to dynamically generate an EvalContext based on function call references, similar to address references.

If the expression contains a call to a provider-defined function, generate a mock function to satisfy the call, ensuring that it always returns an unknown value. This allows you to avoid errors in the evaluation of any provider-defined functions without special error handling.

However, in order to adapt this idea to dynamic block expansion, we now needed a walker to collect expression references to hcl.Body (note that expressions inside dynamic blocks must always be evaluated beforehand). We can use dynblock.WalkVariables for []hcl.Traversal, but there is no such thing for expressions, so we have to extend the tfhcl package.

Although Terraform-specific functions (provider::terraform::*) are provider-defined functions, they are essentially equivalent to built-in functions, so they are implemented to return valid values. However, the implementation is similar to other built-in functions, so the approach is slightly different than upstream.


The most important part of this change is that the terraform package is now licensed under BUSL 1.1. The changed files that refer to upstream licensed under BUSL have SPDX-License-Identifier: BUSL-1.1 added to the header. As you can see, only a small number of files are currently licensed under BUSL.

However, since it includes BUSL-licensed files when generating the executable forms (release binaries), it becomes bound to both licenses. In other words, MPL-licensed files are still free to use, distribute, and fork as MPL, but release binaries may be subject to Hashicorp's BUSL restrictions.

To inform you of this caveat, this PR also includes updates regarding LISENCE files. There may be other changes that need to be made, but I'll work on those separately.

wata727 commented 5 months ago

Since this change is important to the project, I would like to get approval from co-maintainer @bendrucker. Could you take a look on this?

wata727 commented 5 months ago

Thanks!