Skip to content

terraform-test: Add strict mode#38224

Draft
matejrisek wants to merge 8 commits intomainfrom
feature/34010/add-strict-mode-tf-test
Draft

terraform-test: Add strict mode#38224
matejrisek wants to merge 8 commits intomainfrom
feature/34010/add-strict-mode-tf-test

Conversation

@matejrisek
Copy link
Member

TBD

Fixes #

Target Release

1.15.x

Rollback Plan

  • If a change needs to be reverted, we will roll out an update to the code within 7 days.

Changes to Security Controls

Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.

CHANGELOG entry

  • This change is user-facing and I added a changelog entry.
  • This change is not user-facing.

If enabled, strict mode treats each warning as an error.
@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

The equivalence tests will be updated. Please verify the changes here.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

The equivalence tests will be updated. Please verify the changes here.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

The equivalence tests will be updated. Please verify the changes here.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

The equivalence tests will be updated. Please verify the changes here.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

The equivalence tests will be updated. Please verify the changes here.

Copy link
Member

@dsa0x dsa0x left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!. I have some comments around what kind of warnings we would be "promoting".

Comment on lines +34 to +36
if ctx.Strict() {
setVariableDiags = moduletest.PromoteWarningsToErrors(setVariableDiags)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking another look at FilterVariablesToModule, it no longer returns any diagnostic even, so we can update that function, and this entire logic would not even be relevant.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great observation - addressed in 06cd2b4

Comment on lines +191 to +194
if ctx.Strict() {
unexpectedDiags = moduletest.PromoteWarningsToErrors(unexpectedDiags)
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be doing this outside this function. This function should be for the expected_failures conversion, and that is not related to strict. Before passing the original diagnostics to this function, we can apply "strictness" to them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 2e01c5e

Comment on lines +189 to +191
if ctx.Strict() {
variableDiags = moduletest.PromoteWarningsToErrors(variableDiags)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be important to clarify what kind of warnings we are turning into an error. In my opinion, the warnings here are not about the operation made by the run, but by declaring an unused variable within the test, and I would argue that should not cause the test to fail, even in strict mode. The warning we should be focused on are the ones produced by the test's execution of a terraform operation (plan/apply)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @garvitarai1 would you mind chiming in here?
The original Issue is this one .

We wonder what should constitute the strict mode - whether we should report every warning as an error (similar to some other toolings in other languages) or we should be selective with promotion of warnings to errors to the scope Sams proposed in the message above?

And the more important question is - does having one datapoint about the nice-to-have strict mode in "discuss" 2.5 years ago warrants introducing this mode?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked Jira and quickly scanned GH issues as well, so this seems like a one off request. I have the same instinct as Sams that not all warnings are equal, and this might be a noisy experience to promote all warnings to errors.

I think the path forward depends on where the implementation stands. If the work is done, then I'd vote for shipping this as an experiment in an alpha release. In this case, let's bring this to the team meeting to get more opinions on the behaviour. If it needs significant effort, then lets de-prioritize.

@github-actions
Copy link
Contributor

The equivalence tests will be updated. Please verify the changes here.

We've stopped returning diags from the above method, and so we don't need
to populate the named return value with nils all the time, it's better to
remove it.
@github-actions
Copy link
Contributor

The equivalence tests will be updated. Please verify the changes here.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants