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
terraform init: add warning and guidance when lock file is incomplete #31399
Changes from 2 commits
d08b485
d19d6e1
2695db4
f9fcbc7
b77fffd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1644,7 +1644,7 @@ func TestInit_providerSource(t *testing.T) { | |
}) | ||
defer close() | ||
|
||
ui := new(cli.MockUi) | ||
ui := cli.NewMockUi() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see you've discovered another example of the historical mistake of not properly initializing the mock UI! This does still come up from time to time, and indeed this is the way we typically fix it. (By which I mean: this probably won't be the last time you make a change like this!) |
||
view, _ := testView(t) | ||
m := Meta{ | ||
testingOverrides: metaOverridesForProvider(testProvider()), | ||
|
@@ -1726,13 +1726,17 @@ func TestInit_providerSource(t *testing.T) { | |
}, | ||
), | ||
} | ||
|
||
if diff := cmp.Diff(gotProviderLocks, wantProviderLocks, depsfile.ProviderLockComparer); diff != "" { | ||
t.Errorf("wrong version selections after upgrade\n%s", diff) | ||
} | ||
|
||
outputStr := ui.OutputWriter.String() | ||
if want := "Installed hashicorp/test v1.2.3 (verified checksum)"; !strings.Contains(outputStr, want) { | ||
t.Fatalf("unexpected output: %s\nexpected to include %q", outputStr, want) | ||
if got, want := ui.OutputWriter.String(), "Installed hashicorp/test v1.2.3 (verified checksum)"; !strings.Contains(got, want) { | ||
t.Fatalf("unexpected output: %s\nexpected to include %q", got, want) | ||
} | ||
|
||
if got, want := ui.ErrorWriter.String(), "(hashicorp/source, hashicorp/test, hashicorp/test-beta)"; !strings.Contains(got, want) { | ||
t.Fatalf("wrong error message\nshould contain: %s\ngot:\n%s", want, got) | ||
} | ||
} | ||
|
||
|
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 have some copyedits of this warning message which are admittedly subjective but my idea here is firstly to make this "sound like" the Terraform UI voice (which isn't defined strongly, but I think you'll get a sense for it over time) and also to give a little more information about what Terraform just did:
My thought process as I wrote this was:
Subjectively, feels nicer to enumerate the providers as a "bullet list", rather than as a comma-separated list, because the list could potentially be quite long and contain long strings like
foo.example.com/bleep-bloop/bar-baz
that probably won't word-wrap nicely.State that this is caused by the customized installation methods, which hopefully hints at a potential way to avoid this problem altogether (use the default settings) but without implying that it's wrong to use customized settings, since there are of course various good reasons to do so.
Mention the lock file name specifically so it's easier to see that we're talking about the same file that Terraform presumably also mentioned elsewhere in this output.
Mention the platform the user is currently using, honestly mainly just to give another example of what a platform string might look like, since this might be the user's first exposure to them.
Show the copy-pasteable command line on a line of its own, to avoid readers being confused about whether the delimiters are important. (This is our typical style with other error and warning messages which include commands to run).
I also kinda arbitrarily chose to use
linux_amd64
as a "real example" of a platform string, rather than the "os_arch" placeholder, in the hope of making it easier to see what to do by showing another actual platform string. I choselinux_amd64
in recognition that a typical way this problem manifests is someone writing a configuration originally on a Windows or macOS workstation but then trying to run it "for real" in automation running in Linux containers.Note that our diagnostic renderer in the CLI will automatically wrap any line of text that has no leading whitespace, assuming it's a paragraph, but will not wrap lines which start with leading whitespace. In the above example, that applies to both the "bullet points" for the provider addresses and to the copy-pasteable command line at the end.
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.
Done! All makes sense to me.