From bdca9bffe41b8dc893df2b00d9e3f1f715d745a8 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 7 Feb 2017 13:22:28 -0800 Subject: [PATCH] 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. --- backend/local/backend_local.go | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/backend/local/backend_local.go b/backend/local/backend_local.go index f816aeae8..5aca70dd5 100644 --- a/backend/local/backend_local.go +++ b/backend/local/backend_local.go @@ -1,6 +1,10 @@ package local import ( + "fmt" + "log" + "strings" + "github.com/hashicorp/errwrap" "github.com/hashicorp/go-multierror" "github.com/hashicorp/terraform/backend" @@ -81,7 +85,23 @@ func (b *Local) context(op *backend.Operation) (*terraform.Context, state.State, if b.OpValidation { // We ignore warnings here on purpose. We expect users to be listening // 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 { 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 } + +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: +`