Skip to content

Commit

Permalink
add warning to diags and show at the end of each command
Browse files Browse the repository at this point in the history
  • Loading branch information
megan07 committed Aug 30, 2022
1 parent 5eaa4c4 commit 4d749e2
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 24 deletions.
7 changes: 4 additions & 3 deletions internal/command/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
4 changes: 2 additions & 2 deletions internal/command/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
7 changes: 4 additions & 3 deletions internal/command/state_mv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
6 changes: 2 additions & 4 deletions internal/command/state_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -148,6 +145,7 @@ func (c *StatePushCommand) Run(args []string) int {
return 1
}

c.showDiagnostics(diags)
return 0
}

Expand Down
8 changes: 5 additions & 3 deletions internal/command/state_replace_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -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
}
Expand Down
7 changes: 4 additions & 3 deletions internal/command/state_rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
8 changes: 5 additions & 3 deletions internal/command/taint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 5 additions & 3 deletions internal/command/untaint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -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
}
Expand Down

0 comments on commit 4d749e2

Please sign in to comment.