Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions internal/command/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,8 @@ func checkGoldenReferenceHumanOutput(t *testing.T, output *terminal.TestOutput,
// checkParameterizedGoldenReferenceHumanOutput compares a test fixture's log output with the given test output.
// The log is expected to be in a file called "output.log" or "output-parameterized.log" located under the specified fixture path.
//
// If any parameters are provided, this function expects to find and use a "output-parameterized.jsonlog" file.
//
// The log can contain format specifiers that will be replaced with the given params, and these are only intended
// for use when output references values like current platform or Terraform version.
func checkParameterizedGoldenReferenceHumanOutput(t *testing.T, output *terminal.TestOutput, fixturePathName string, params ...interface{}) {
Expand Down Expand Up @@ -1343,8 +1345,30 @@ func checkParameterizedGoldenReferenceHumanOutput(t *testing.T, output *terminal
func checkGoldenReference(t *testing.T, output *terminal.TestOutput, fixturePathName string) {
t.Helper()

// No params
checkParameterizedGoldenReference(t, output, fixturePathName)
}

// checkParameterizedGoldenReference compares a test fixture's log output with the given test JSON output.
// The log is expected to be in a file called "output.jsonlog" or "output-parameterized.jsonlog" located under the specified fixture path.
//
// If any parameters are provided, this function expects to find and use a "output-parameterized.jsonlog" file.
//
// The log can contain format specifiers that will be replaced with the given params, and these are only intended
// for use when output references values like current platform or Terraform version.
func checkParameterizedGoldenReference(t *testing.T, output *terminal.TestOutput, fixturePathName string, params ...interface{}) {
t.Helper()

var expectedFilePath string

if len(params) > 0 {
expectedFilePath = path.Join(testFixturePath(fixturePathName), "output-parameterized.jsonlog")
} else {
expectedFilePath = path.Join(testFixturePath(fixturePathName), "output.jsonlog")
}

// Load the golden reference fixture
wantFile, err := os.Open(path.Join(testFixturePath(fixturePathName), "output.jsonlog"))
wantFile, err := os.Open(expectedFilePath)
if err != nil {
t.Fatalf("failed to open output file: %s", err)
}
Expand All @@ -1353,7 +1377,8 @@ func checkGoldenReference(t *testing.T, output *terminal.TestOutput, fixturePath
if err != nil {
t.Fatalf("failed to read output file: %s", err)
}
want := string(wantBytes)
wantTemplate := string(wantBytes)
want := fmt.Sprintf(wantTemplate, params...)

checkGoldenReferenceStr(t, output, want)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/command/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ func (c *InitCommand) getProvidersFromPSSConfig(ctx context.Context, rootModEarl
// which will be surfaced as diagnostic during installation
if !pAddr.IsZero() {
cons := reqs[pAddr]
view.LogInitializingStateStoreProviderPlugin(pAddr, cons, rootModEarly.StateStore.Type)
view.LogInitializingStateStoreProviderStart(pAddr, cons, rootModEarly.StateStore.Type)
}
},
ProviderAlreadyInstalled: providerAlreadyInstalledCallback(view),
Expand Down
8 changes: 4 additions & 4 deletions internal/command/meta_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -3110,7 +3110,7 @@ func (m *Meta) determineIfProviderTrusted(provider addrs.Provider, providerLocat
// confirmProviderIsTrusted takes the action determined by `determineIfProviderTrusted` and either prompts the user for approval, or returns an error if something has gone wrong with pre-supplied locks when Terraform was run in automation.
//
// NOTE: the command parameter is used to determine which command is being run, so that we can provide more specific guidance to the user. Do not use that parameter for any other purpose!
func (m *Meta) confirmProviderIsTrusted(trust ProviderTrust, provider addrs.Provider, stateStoreProviderAuthResult *getproviders.PackageAuthenticationResult, stateStoreProviderLock, locksBeforeInstall *depsfile.Locks, flagLockfilePath string, command cli.Command, view views.ProviderInstallationLogger) tfdiags.Diagnostics {
func (m *Meta) confirmProviderIsTrusted(trust ProviderTrust, provider addrs.Provider, stateStoreProviderAuthResult *getproviders.PackageAuthenticationResult, stateStoreProviderLock, locksBeforeInstall *depsfile.Locks, flagLockfilePath string, command cli.Command, view views.StateStoreProviderTrustLogger) tfdiags.Diagnostics {
var diags tfdiags.Diagnostics

switch trust {
Expand All @@ -3119,20 +3119,20 @@ func (m *Meta) confirmProviderIsTrusted(trust ProviderTrust, provider addrs.Prov

if flagLockfilePath != "" {
// If the user supplied a lock file path via CLI flag, we should notify them that it was used.
view.Output(views.StateStoreProviderAutomationApprovedMessage)
view.LogAutomaticApproval()
view.Spacer()
}
case RequiresApproval:
if m.input {
// Prompt the user about trusting the provider used for state storage.
diags = diags.Append(m.promptStateStorageProviderApproval(provider, stateStoreProviderLock, stateStoreProviderAuthResult))
if diags.HasErrors() {
view.Output(views.StateStoreProviderInteractiveRejectedMessage)
view.LogInteractiveRejection()
view.Spacer()
return diags
}

view.Output(views.StateStoreProviderInteractiveApprovedMessage)
view.LogInteractiveApproval()
view.Spacer()
} else {
// Confirm that a lock was used to control download.
Expand Down
2 changes: 1 addition & 1 deletion internal/command/state_migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ func (c *StateMigrateCommand) getSingleProvider(ctx context.Context, stateStore
// which will be surfaced as diagnostic during installation
if !pAddr.IsZero() {
cons := reqs[pAddr]
view.LogInitializingStateStoreProviderPlugin(pAddr, cons, stateStore.Type)
view.LogInitializingStateStoreProviderStart(pAddr, cons, stateStore.Type)
}
},
ProviderAlreadyInstalled: providerAlreadyInstalledCallback(view),
Expand Down
Loading
Loading