From 4d749e2813a8d39729bc42a0da8f4a4af7f3895c Mon Sep 17 00:00:00 2001 From: Megan Bang Date: Tue, 30 Aug 2022 17:52:51 -0500 Subject: [PATCH] add warning to diags and show at the end of each command --- internal/command/import.go | 7 ++++--- internal/command/meta.go | 4 ++-- internal/command/state_mv.go | 7 ++++--- internal/command/state_push.go | 6 ++---- internal/command/state_replace_provider.go | 8 +++++--- internal/command/state_rm.go | 7 ++++--- internal/command/taint.go | 8 +++++--- internal/command/untaint.go | 8 +++++--- 8 files changed, 31 insertions(+), 24 deletions(-) diff --git a/internal/command/import.go b/internal/command/import.go index 5a2f1b56f3..d2a9917a85 100644 --- a/internal/command/import.go +++ b/internal/command/import.go @@ -251,9 +251,10 @@ func (c *ImportCommand) Run(args []string) int { // Get schemas, if possible, before writing state var schemas *terraform.Schemas if isCloudMode(b) { - schemas, diags = c.MaybeGetSchemas(newState, nil) - if diags.HasErrors() { - c.Ui.Warn(failedToLoadSchemasMessage) + var schemaDiags tfdiags.Diagnostics + schemas, schemaDiags = c.MaybeGetSchemas(newState, nil) + if schemaDiags.HasErrors() { + diags = diags.Append(schemaDiags) } } diff --git a/internal/command/meta.go b/internal/command/meta.go index 4b51ddb594..de5a921188 100644 --- a/internal/command/meta.go +++ b/internal/command/meta.go @@ -792,14 +792,14 @@ func (c *Meta) MaybeGetSchemas(state *states.State, config *configs.Config) (*te path, err := os.Getwd() if err != nil { - diags.Append(err) + diags.Append(tfdiags.SimpleWarning(failedToLoadSchemasMessage)) return nil, diags } if config == nil { config, diags = c.loadConfig(path) if diags.HasErrors() { - diags.Append(diags) + diags.Append(tfdiags.SimpleWarning(failedToLoadSchemasMessage)) return nil, diags } } diff --git a/internal/command/state_mv.go b/internal/command/state_mv.go index 279c1a1eb8..da316d32a6 100644 --- a/internal/command/state_mv.go +++ b/internal/command/state_mv.go @@ -396,9 +396,10 @@ func (c *StateMvCommand) Run(args []string) int { // Get schemas, if possible, before writing state var schemas *terraform.Schemas if isCloudMode(b) { - schemas, diags = c.MaybeGetSchemas(stateTo, nil) - if diags.HasErrors() { - c.Ui.Warn(failedToLoadSchemasMessage) + var schemaDiags tfdiags.Diagnostics + schemas, schemaDiags = c.MaybeGetSchemas(stateTo, nil) + if schemaDiags.HasErrors() { + diags = diags.Append(schemaDiags) } } diff --git a/internal/command/state_push.go b/internal/command/state_push.go index 7745e7e873..c738dc70e3 100644 --- a/internal/command/state_push.go +++ b/internal/command/state_push.go @@ -131,12 +131,9 @@ func (c *StatePushCommand) Run(args []string) int { // Get schemas, if possible, before writing state var schemas *terraform.Schemas + var diags tfdiags.Diagnostics if isCloudMode(b) { - var diags tfdiags.Diagnostics schemas, diags = c.MaybeGetSchemas(srcStateFile.State, nil) - if diags.HasErrors() { - c.Ui.Warn(failedToLoadSchemasMessage) - } } if err := stateMgr.WriteState(srcStateFile.State); err != nil { @@ -148,6 +145,7 @@ func (c *StatePushCommand) Run(args []string) int { return 1 } + c.showDiagnostics(diags) return 0 } diff --git a/internal/command/state_replace_provider.go b/internal/command/state_replace_provider.go index da5dc82a20..75d9f05ef4 100644 --- a/internal/command/state_replace_provider.go +++ b/internal/command/state_replace_provider.go @@ -171,9 +171,10 @@ func (c *StateReplaceProviderCommand) Run(args []string) int { // Get schemas, if possible, before writing state var schemas *terraform.Schemas if isCloudMode(b) { - schemas, diags = c.MaybeGetSchemas(state, nil) - if diags.HasErrors() { - c.Ui.Warn(failedToLoadSchemasMessage) + var schemaDiags tfdiags.Diagnostics + schemas, schemaDiags = c.MaybeGetSchemas(state, nil) + if schemaDiags.HasErrors() { + diags = diags.Append(schemaDiags) } } @@ -187,6 +188,7 @@ func (c *StateReplaceProviderCommand) Run(args []string) int { return 1 } + c.showDiagnostics(diags) c.Ui.Output(fmt.Sprintf("\nSuccessfully replaced provider for %d resources.", len(willReplace))) return 0 } diff --git a/internal/command/state_rm.go b/internal/command/state_rm.go index 2f7cb21d9a..f49081f4cd 100644 --- a/internal/command/state_rm.go +++ b/internal/command/state_rm.go @@ -121,9 +121,10 @@ func (c *StateRmCommand) Run(args []string) int { // Get schemas, if possible, before writing state var schemas *terraform.Schemas if isCloudMode(b) { - schemas, diags = c.MaybeGetSchemas(state, nil) - if diags.HasErrors() { - c.Ui.Warn(failedToLoadSchemasMessage) + var schemaDiags tfdiags.Diagnostics + schemas, schemaDiags = c.MaybeGetSchemas(state, nil) + if schemaDiags.HasErrors() { + diags = diags.Append(schemaDiags) } } diff --git a/internal/command/taint.go b/internal/command/taint.go index c1e21e07bd..859fa29920 100644 --- a/internal/command/taint.go +++ b/internal/command/taint.go @@ -129,9 +129,10 @@ func (c *TaintCommand) Run(args []string) int { // Get schemas, if possible, before writing state var schemas *terraform.Schemas if isCloudMode(b) { - schemas, diags = c.MaybeGetSchemas(state, nil) - if diags.HasErrors() { - c.Ui.Warn(failedToLoadSchemasMessage) + var schemaDiags tfdiags.Diagnostics + schemas, schemaDiags = c.MaybeGetSchemas(state, nil) + if schemaDiags.HasErrors() { + diags = diags.Append(schemaDiags) } } @@ -186,6 +187,7 @@ func (c *TaintCommand) Run(args []string) int { return 1 } + c.showDiagnostics(diags) c.Ui.Output(fmt.Sprintf("Resource instance %s has been marked as tainted.", addr)) return 0 } diff --git a/internal/command/untaint.go b/internal/command/untaint.go index 21ffefe9b2..1fd0e2eed7 100644 --- a/internal/command/untaint.go +++ b/internal/command/untaint.go @@ -168,9 +168,10 @@ func (c *UntaintCommand) Run(args []string) int { // Get schemas, if possible, before writing state var schemas *terraform.Schemas if isCloudMode(b) { - schemas, diags = c.MaybeGetSchemas(state, nil) - if diags.HasErrors() { - c.Ui.Warn(failedToLoadSchemasMessage) + var schemaDiags tfdiags.Diagnostics + schemas, schemaDiags = c.MaybeGetSchemas(state, nil) + if schemaDiags.HasErrors() { + diags = diags.Append(schemaDiags) } } @@ -186,6 +187,7 @@ func (c *UntaintCommand) Run(args []string) int { return 1 } + c.showDiagnostics(diags) c.Ui.Output(fmt.Sprintf("Resource instance %s has been successfully untainted.", addr)) return 0 }