diff --git a/command/graph.go b/command/graph.go index aec4ffecd..42d59a2a6 100644 --- a/command/graph.go +++ b/command/graph.go @@ -7,7 +7,6 @@ import ( "os" "strings" - "github.com/hashicorp/terraform/config" "github.com/hashicorp/terraform/digraph" "github.com/hashicorp/terraform/terraform" "github.com/mitchellh/cli" @@ -43,16 +42,13 @@ func (c *GraphCommand) Run(args []string) int { } } - conf, err := config.LoadDir(path) + ctx, err := ContextArg(path, "", c.ContextOpts) if err != nil { - c.Ui.Error(fmt.Sprintf("Error loading config: %s", err)) + c.Ui.Error(fmt.Sprintf("Error loading Terraform: %s", err)) return 1 } - g, err := terraform.Graph(&terraform.GraphOpts{ - Config: conf, - Providers: c.ContextOpts.Providers, - }) + g, err := ctx.Graph() if err != nil { c.Ui.Error(fmt.Sprintf("Error creating graph: %s", err)) return 1 diff --git a/command/graph_test.go b/command/graph_test.go index 1a1e298f9..f95089def 100644 --- a/command/graph_test.go +++ b/command/graph_test.go @@ -5,6 +5,8 @@ import ( "strings" "testing" + "github.com/hashicorp/terraform/config" + "github.com/hashicorp/terraform/terraform" "github.com/mitchellh/cli" ) @@ -70,3 +72,27 @@ func TestGraph_noArgs(t *testing.T) { t.Fatalf("doesn't look like digraph: %s", output) } } + +func TestGraph_plan(t *testing.T) { + planPath := testPlanFile(t, &terraform.Plan{ + Config: new(config.Config), + }) + + ui := new(cli.MockUi) + c := &GraphCommand{ + ContextOpts: testCtxConfig(testProvider()), + Ui: ui, + } + + args := []string{ + planPath, + } + if code := c.Run(args); code != 0 { + t.Fatalf("bad: \n%s", ui.ErrorWriter.String()) + } + + output := ui.OutputWriter.String() + if !strings.Contains(output, "digraph {") { + t.Fatalf("doesn't look like digraph: %s", output) + } +}