add warning to diags and show at the end of each command

This commit is contained in:
Megan Bang 2022-08-30 17:52:51 -05:00
parent 5eaa4c45c0
commit 4d749e2813
8 changed files with 31 additions and 24 deletions

View File

@ -251,9 +251,10 @@ func (c *ImportCommand) Run(args []string) int {
// Get schemas, if possible, before writing state // Get schemas, if possible, before writing state
var schemas *terraform.Schemas var schemas *terraform.Schemas
if isCloudMode(b) { if isCloudMode(b) {
schemas, diags = c.MaybeGetSchemas(newState, nil) var schemaDiags tfdiags.Diagnostics
if diags.HasErrors() { schemas, schemaDiags = c.MaybeGetSchemas(newState, nil)
c.Ui.Warn(failedToLoadSchemasMessage) if schemaDiags.HasErrors() {
diags = diags.Append(schemaDiags)
} }
} }

View File

@ -792,14 +792,14 @@ func (c *Meta) MaybeGetSchemas(state *states.State, config *configs.Config) (*te
path, err := os.Getwd() path, err := os.Getwd()
if err != nil { if err != nil {
diags.Append(err) diags.Append(tfdiags.SimpleWarning(failedToLoadSchemasMessage))
return nil, diags return nil, diags
} }
if config == nil { if config == nil {
config, diags = c.loadConfig(path) config, diags = c.loadConfig(path)
if diags.HasErrors() { if diags.HasErrors() {
diags.Append(diags) diags.Append(tfdiags.SimpleWarning(failedToLoadSchemasMessage))
return nil, diags return nil, diags
} }
} }

View File

@ -396,9 +396,10 @@ func (c *StateMvCommand) Run(args []string) int {
// Get schemas, if possible, before writing state // Get schemas, if possible, before writing state
var schemas *terraform.Schemas var schemas *terraform.Schemas
if isCloudMode(b) { if isCloudMode(b) {
schemas, diags = c.MaybeGetSchemas(stateTo, nil) var schemaDiags tfdiags.Diagnostics
if diags.HasErrors() { schemas, schemaDiags = c.MaybeGetSchemas(stateTo, nil)
c.Ui.Warn(failedToLoadSchemasMessage) if schemaDiags.HasErrors() {
diags = diags.Append(schemaDiags)
} }
} }

View File

@ -131,12 +131,9 @@ func (c *StatePushCommand) Run(args []string) int {
// Get schemas, if possible, before writing state // Get schemas, if possible, before writing state
var schemas *terraform.Schemas var schemas *terraform.Schemas
var diags tfdiags.Diagnostics
if isCloudMode(b) { if isCloudMode(b) {
var diags tfdiags.Diagnostics
schemas, diags = c.MaybeGetSchemas(srcStateFile.State, nil) schemas, diags = c.MaybeGetSchemas(srcStateFile.State, nil)
if diags.HasErrors() {
c.Ui.Warn(failedToLoadSchemasMessage)
}
} }
if err := stateMgr.WriteState(srcStateFile.State); err != nil { if err := stateMgr.WriteState(srcStateFile.State); err != nil {
@ -148,6 +145,7 @@ func (c *StatePushCommand) Run(args []string) int {
return 1 return 1
} }
c.showDiagnostics(diags)
return 0 return 0
} }

View File

@ -171,9 +171,10 @@ func (c *StateReplaceProviderCommand) Run(args []string) int {
// Get schemas, if possible, before writing state // Get schemas, if possible, before writing state
var schemas *terraform.Schemas var schemas *terraform.Schemas
if isCloudMode(b) { if isCloudMode(b) {
schemas, diags = c.MaybeGetSchemas(state, nil) var schemaDiags tfdiags.Diagnostics
if diags.HasErrors() { schemas, schemaDiags = c.MaybeGetSchemas(state, nil)
c.Ui.Warn(failedToLoadSchemasMessage) if schemaDiags.HasErrors() {
diags = diags.Append(schemaDiags)
} }
} }
@ -187,6 +188,7 @@ func (c *StateReplaceProviderCommand) Run(args []string) int {
return 1 return 1
} }
c.showDiagnostics(diags)
c.Ui.Output(fmt.Sprintf("\nSuccessfully replaced provider for %d resources.", len(willReplace))) c.Ui.Output(fmt.Sprintf("\nSuccessfully replaced provider for %d resources.", len(willReplace)))
return 0 return 0
} }

View File

@ -121,9 +121,10 @@ func (c *StateRmCommand) Run(args []string) int {
// Get schemas, if possible, before writing state // Get schemas, if possible, before writing state
var schemas *terraform.Schemas var schemas *terraform.Schemas
if isCloudMode(b) { if isCloudMode(b) {
schemas, diags = c.MaybeGetSchemas(state, nil) var schemaDiags tfdiags.Diagnostics
if diags.HasErrors() { schemas, schemaDiags = c.MaybeGetSchemas(state, nil)
c.Ui.Warn(failedToLoadSchemasMessage) if schemaDiags.HasErrors() {
diags = diags.Append(schemaDiags)
} }
} }

View File

@ -129,9 +129,10 @@ func (c *TaintCommand) Run(args []string) int {
// Get schemas, if possible, before writing state // Get schemas, if possible, before writing state
var schemas *terraform.Schemas var schemas *terraform.Schemas
if isCloudMode(b) { if isCloudMode(b) {
schemas, diags = c.MaybeGetSchemas(state, nil) var schemaDiags tfdiags.Diagnostics
if diags.HasErrors() { schemas, schemaDiags = c.MaybeGetSchemas(state, nil)
c.Ui.Warn(failedToLoadSchemasMessage) if schemaDiags.HasErrors() {
diags = diags.Append(schemaDiags)
} }
} }
@ -186,6 +187,7 @@ func (c *TaintCommand) Run(args []string) int {
return 1 return 1
} }
c.showDiagnostics(diags)
c.Ui.Output(fmt.Sprintf("Resource instance %s has been marked as tainted.", addr)) c.Ui.Output(fmt.Sprintf("Resource instance %s has been marked as tainted.", addr))
return 0 return 0
} }

View File

@ -168,9 +168,10 @@ func (c *UntaintCommand) Run(args []string) int {
// Get schemas, if possible, before writing state // Get schemas, if possible, before writing state
var schemas *terraform.Schemas var schemas *terraform.Schemas
if isCloudMode(b) { if isCloudMode(b) {
schemas, diags = c.MaybeGetSchemas(state, nil) var schemaDiags tfdiags.Diagnostics
if diags.HasErrors() { schemas, schemaDiags = c.MaybeGetSchemas(state, nil)
c.Ui.Warn(failedToLoadSchemasMessage) if schemaDiags.HasErrors() {
diags = diags.Append(schemaDiags)
} }
} }
@ -186,6 +187,7 @@ func (c *UntaintCommand) Run(args []string) int {
return 1 return 1
} }
c.showDiagnostics(diags)
c.Ui.Output(fmt.Sprintf("Resource instance %s has been successfully untainted.", addr)) c.Ui.Output(fmt.Sprintf("Resource instance %s has been successfully untainted.", addr))
return 0 return 0
} }