backend/local: output warnings

Fixes #11628

This is a simple fix to output warnings. I originally forgot to do this
since the local backend didn't have a CLI UI at the time. It does now so
this is an easy fix.
This commit is contained in:
Mitchell Hashimoto 2017-02-07 13:22:28 -08:00
parent a612b43987
commit bdca9bffe4
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
1 changed files with 29 additions and 1 deletions

View File

@ -1,6 +1,10 @@
package local package local
import ( import (
"fmt"
"log"
"strings"
"github.com/hashicorp/errwrap" "github.com/hashicorp/errwrap"
"github.com/hashicorp/go-multierror" "github.com/hashicorp/go-multierror"
"github.com/hashicorp/terraform/backend" "github.com/hashicorp/terraform/backend"
@ -81,7 +85,23 @@ func (b *Local) context(op *backend.Operation) (*terraform.Context, state.State,
if b.OpValidation { if b.OpValidation {
// We ignore warnings here on purpose. We expect users to be listening // We ignore warnings here on purpose. We expect users to be listening
// to the terraform.Hook called after a validation. // to the terraform.Hook called after a validation.
_, es := tfCtx.Validate() ws, es := tfCtx.Validate()
if len(ws) > 0 {
// Log just in case the CLI isn't enabled
log.Printf("[WARN] backend/local: %d warnings: %v", len(ws), ws)
// If we have a CLI, output the warnings
if b.CLI != nil {
b.CLI.Warn(strings.TrimSpace(validateWarnHeader) + "\n")
for _, w := range ws {
b.CLI.Warn(fmt.Sprintf(" * %s", w))
}
// Make a newline before continuing
b.CLI.Output("")
}
}
if len(es) > 0 { if len(es) > 0 {
return nil, nil, multierror.Append(nil, es...) return nil, nil, multierror.Append(nil, es...)
} }
@ -90,3 +110,11 @@ func (b *Local) context(op *backend.Operation) (*terraform.Context, state.State,
return tfCtx, s, nil return tfCtx, s, nil
} }
const validateWarnHeader = `
There are warnings related to your configuration. If no errors occurred,
Terraform will continue despite these warnings. It is a good idea to resolve
these warnings in the near future.
Warnings:
`