Skip to content

Commit bdca9bf

Browse files
committed
backend/local: output warnings
Fixes hashicorp#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.
1 parent a612b43 commit bdca9bf

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

backend/local/backend_local.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package local
22

33
import (
4+
"fmt"
5+
"log"
6+
"strings"
7+
48
"github.com/hashicorp/errwrap"
59
"github.com/hashicorp/go-multierror"
610
"github.com/hashicorp/terraform/backend"
@@ -81,7 +85,23 @@ func (b *Local) context(op *backend.Operation) (*terraform.Context, state.State,
8185
if b.OpValidation {
8286
// We ignore warnings here on purpose. We expect users to be listening
8387
// to the terraform.Hook called after a validation.
84-
_, es := tfCtx.Validate()
88+
ws, es := tfCtx.Validate()
89+
if len(ws) > 0 {
90+
// Log just in case the CLI isn't enabled
91+
log.Printf("[WARN] backend/local: %d warnings: %v", len(ws), ws)
92+
93+
// If we have a CLI, output the warnings
94+
if b.CLI != nil {
95+
b.CLI.Warn(strings.TrimSpace(validateWarnHeader) + "\n")
96+
for _, w := range ws {
97+
b.CLI.Warn(fmt.Sprintf(" * %s", w))
98+
}
99+
100+
// Make a newline before continuing
101+
b.CLI.Output("")
102+
}
103+
}
104+
85105
if len(es) > 0 {
86106
return nil, nil, multierror.Append(nil, es...)
87107
}
@@ -90,3 +110,11 @@ func (b *Local) context(op *backend.Operation) (*terraform.Context, state.State,
90110

91111
return tfCtx, s, nil
92112
}
113+
114+
const validateWarnHeader = `
115+
There are warnings related to your configuration. If no errors occurred,
116+
Terraform will continue despite these warnings. It is a good idea to resolve
117+
these warnings in the near future.
118+
119+
Warnings:
120+
`

0 commit comments

Comments
 (0)