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
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)
}
}

View File

@ -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
}
}

View File

@ -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)
}
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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)
}
}

View File

@ -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
}

View File

@ -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
}