-
Notifications
You must be signed in to change notification settings - Fork 159
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
Detect & exclude unsupported Terraform versions #361
Conversation
Codecov Report
@@ Coverage Diff @@
## v0.8 #361 +/- ##
==========================================
+ Coverage 70.73% 70.74% +0.01%
==========================================
Files 284 285 +1
Lines 6396 6417 +21
==========================================
+ Hits 4524 4540 +16
- Misses 1504 1508 +4
- Partials 368 369 +1
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work, I have 2 small comments
const TerraformStateReaderSupplier = "tfstate" | ||
const ( | ||
TerraformStateReaderSupplier = "tfstate" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to do that ? Or it is the linter that did this ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's just me, I'll revert this change
pkg/iac/terraform/state/versions.go
Outdated
|
||
func (u *UnsupportedVersionError) Error() string { | ||
return fmt.Sprintf("%s was generated using Terraform %s which is currently not supported by driftctl\n"+ | ||
"Please read documentation at https://docs.driftctl.com/0.7.0/limitations", u.StateFile, u.Version) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're gonna switch the link to the deep link one https://docs.driftctl.com/limitations
324bd27
to
5c214be
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
5c214be
to
070c063
Compare
To rebase on |
070c063
to
9084d4e
Compare
Description
The goal of this patch is to warn the user about the state they provided in case it's from an unsupported version of Terraform.
Implementation
I used go-version by hashicorp to perform the constraint check on Terraform version state. After parsing the state, the version is checked against the constraint (>= 0.11). If the constraint is satisfied, the scan can continue as usual. If it doesn't, a warning is displayed to tell the user this particular state was generated using an unsupported version of Terraform. The scan continue and the ignored state appears as drifted with 0% coverage.
The version constraints are stored in a variable called
UnsupportedVersionConstraints
:Example :
About constraints
I still need to figure out which version of Terraform is supported or not. But as stated in #340, we won't support versions below 0.11. So for now, the unsupported constraints are
<0.11
. This patch assume we can have multiple constraints in the future, so it's possible to add a version constraint at any moment :<0.11
,=0.13.2
Exclude versions below 0.11 and 0.13.2=0.9
,=0.10
Exclude versions 0.9.0 and 0.10.0<0.11
,>=0.13, <0.14
Exclude versions below 0.11 and all 0.13EDIT: I tested with TF v0.11, v0.14.8, & 0.14.9 and it does not appear to have incompatible behavior. May be we need more tests to ensure we fully support versions >=0.11.
Known limitations
Although it's simple to add a constraint at any time, it's important to note the limitation about this feature. If we excludes versions below
0.11
, the constraint will looks like this :<0.11
. But we'll not be able to include any version below 0.11. Also, if we decide to exclude a specific minor version, it's possible to do so using this syntax :>=0.13, <0.14