-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Make config errors more important during init operations #33628
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
internal/command/testdata/init-syntax-invalid-backend-attribute-invalid/main.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
terraform { | ||
backend "local" { | ||
path = $invalid | ||
} | ||
} | ||
|
||
variable "input" { | ||
type = string | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Hmm,
earlyConfDiags
doesn't include errors from backend initialization, so if I have a config that looks like this:I won't see anything about the backend problems until after I fix any other config errors.
That doesn't seem like a terrible outcome, but I wonder if it might be just as well to return all these diags together and either get rid of or adjust
errInitConfigError
so that it makes sense for both config errors and backend errors - the exact wording of that error message used to be important becauseterraform-exec
relied on it, but that matching was since removed.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.
Yep, sounds good! I've made it print both sets if either one fails and tweaked the wording a bit!
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.
Ah, actually, an important bit of context came back to me and I fear I gave you a bad suggestion 😅
backDiags
includes config validation errors as well, so appending/returning both together means we'll show errors twice.We could consider:
loadBackendConfig
not also validate the entire root module sobackDiags
actually contains what it says on the tin2 seems reasonable to me, unless you have other suggestions - sorry for the false flag!
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'm more than happy to turn it back, but I don't think they will actually contain duplicate diagnostics. The HCL library itself caches the files it loads: https://github.com/hashicorp/hcl/blob/main/hclparse/parser.go#L56
So, the first time round it loads the partial file with the diagnostics, but on following reads it doesn't reproduce the diagnostics. It just returns the partial file directly with no diagnostics. The tests also don't show duplicate errors.
Either way, I'm more than happy to go back to the previous approach but I think it should be fine.