Merge pull request #26036 from hashicorp/alisdair/output-empty-should-be-warning

command: Warn instead of error for empty output
This commit is contained in:
Alisdair McDiarmid 2020-09-01 10:23:51 -04:00 committed by GitHub
commit 6d228cc560
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 8 deletions

View File

@ -113,13 +113,17 @@ func (c *OutputCommand) Run(args []string) int {
} }
if !jsonOutput && (state.Empty() || len(mod.OutputValues) == 0) { if !jsonOutput && (state.Empty() || len(mod.OutputValues) == 0) {
c.Ui.Error( diags = diags.Append(tfdiags.Sourceless(
"The state file either has no outputs defined, or all the defined\n" + tfdiags.Warning,
"outputs are empty. Please define an output in your configuration\n" + "No outputs found",
"with the `output` keyword and run `terraform refresh` for it to\n" + "The state file either has no outputs defined, or all the defined "+
"become available. If you are using interpolation, please verify\n" + "outputs are empty. Please define an output in your configuration "+
"the interpolated value is not empty. You can use the \n" + "with the `output` keyword and run `terraform refresh` for it to "+
"`terraform console` command to assist.") "become available. If you are using interpolation, please verify "+
"the interpolated value is not empty. You can use the "+
"`terraform console` command to assist.",
))
c.showDiagnostics(diags)
return 0 return 0
} }

View File

@ -120,7 +120,7 @@ func TestOutput_json(t *testing.T) {
} }
} }
func TestOutput_emptyOutputsErr(t *testing.T) { func TestOutput_emptyOutputs(t *testing.T) {
originalState := states.NewState() originalState := states.NewState()
statePath := testStateFile(t, originalState) statePath := testStateFile(t, originalState)
@ -139,6 +139,9 @@ func TestOutput_emptyOutputsErr(t *testing.T) {
if code := c.Run(args); code != 0 { if code := c.Run(args); code != 0 {
t.Fatalf("bad: \n%s", ui.ErrorWriter.String()) t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
} }
if got, want := ui.ErrorWriter.String(), "Warning: No outputs found"; !strings.Contains(got, want) {
t.Fatalf("bad output: expected to contain %q, got:\n%s", want, got)
}
} }
func TestOutput_jsonEmptyOutputs(t *testing.T) { func TestOutput_jsonEmptyOutputs(t *testing.T) {