Skip to content

Commit 2fcd5c4

Browse files
committed
feat: Show all preferred hashes for a provider in the prompt to users, update tests to assert hashes are in the prompt.
1 parent 8998061 commit 2fcd5c4

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

internal/command/init_run_experiment.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,15 +599,21 @@ func (c *InitCommand) promptStateStorageProviderApproval(stateStorageProvider ad
599599
// If we can receive input then we prompt for ok from the user
600600
lock := configLocks.Provider(stateStorageProvider)
601601

602+
var hashList strings.Builder
603+
for _, hash := range lock.PreferredHashes() {
604+
hashList.WriteString(fmt.Sprintf("- %s\n", hash))
605+
}
606+
602607
v, err := c.UIInput().Input(context.Background(), &terraform.InputOpts{
603608
Id: "approve",
604609
Query: fmt.Sprintf(`Do you want to use provider %q (%s), version %s, for managing state?
605-
Hash: %s
610+
Hashes:
611+
%s
606612
`,
607613
lock.Provider().Type,
608614
lock.Provider(),
609615
lock.Version(),
610-
lock.PreferredHashes()[0], // TODO - better handle of multiple hashes
616+
hashList.String(),
611617
),
612618
Description: fmt.Sprintf(`Check the dependency lockfile's entry for %q.
613619
Only 'yes' will be accepted to confirm.`, lock.Provider()),

internal/command/init_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3597,7 +3597,7 @@ func TestInit_stateStore_newWorkingDir(t *testing.T) {
35973597
t.Fatalf("expected code 0 exit code, got %d, output: \n%s", code, testOutput.All())
35983598
}
35993599

3600-
// Check output
3600+
// Check output via view
36013601
output := testOutput.All()
36023602
expectedOutputs := []string{
36033603
"Initializing the state store...",
@@ -3609,6 +3609,16 @@ func TestInit_stateStore_newWorkingDir(t *testing.T) {
36093609
t.Fatalf("expected output to include %q, but got':\n %s", expected, output)
36103610
}
36113611
}
3612+
// Check output when prompting for approval
3613+
expectedInputPromptMsg := []string{
3614+
"Do you want to use provider \"test\" (registry.terraform.io/hashicorp/test), version 1.2.3, for managing state?",
3615+
"h1:wlbEC2mChQZ2hhgUhl6SeVLPP7fMqOFUZAQhQ9GIIno=",
3616+
}
3617+
for _, expected := range expectedInputPromptMsg {
3618+
if !strings.Contains(inputWriter.String(), expected) {
3619+
t.Fatalf("expected the input prompt to include %q, but got':\n %s", expected, inputWriter.String())
3620+
}
3621+
}
36123622

36133623
// Assert the dependency lock file was created
36143624
lockFile := filepath.Join(td, ".terraform.lock.hcl")

0 commit comments

Comments
 (0)