Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions command/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,17 @@ func (c *OutputCommand) Run(args []string) int {
}

if !jsonOutput && (state.Empty() || len(mod.OutputValues) == 0) {
c.Ui.Error(
"The state file either has no outputs defined, or all the defined\n" +
"outputs are empty. Please define an output in your configuration\n" +
"with the `output` keyword and run `terraform refresh` for it to\n" +
"become available. If you are using interpolation, please verify\n" +
"the interpolated value is not empty. You can use the \n" +
"`terraform console` command to assist.")
diags = diags.Append(tfdiags.Sourceless(
tfdiags.Warning,
"No outputs found",
"The state file either has no outputs defined, or all the defined "+
"outputs are empty. Please define an output in your configuration "+
"with the `output` keyword and run `terraform refresh` for it to "+
"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
}

Expand Down
5 changes: 4 additions & 1 deletion command/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
statePath := testStateFile(t, originalState)

Expand All @@ -139,6 +139,9 @@ func TestOutput_emptyOutputsErr(t *testing.T) {
if code := c.Run(args); code != 0 {
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) {
Expand Down