Running terraform graph locally

Hello,
is there a way to get a terraform state graph locally? We usually interact with our infrastructure through Atlantis; so I generated a plan through there and copied that into a file called plan.tfplan. Then I ran terraform graph -plan=plan.tfplan and got the following error:

Usage: terraform graph [options] [DIR]

  Outputs the visual execution graph of Terraform resources according to
  configuration files in DIR (or the current directory if omitted).

  The graph is outputted in DOT format. The typical program that can
  read this format is GraphViz, but many web services are also available
  to read this format.

  The -type flag can be used to control the type of graph shown. Terraform
  creates different graphs for different operations. See the options below
  for the list of types supported. The default type is "plan" if a
  configuration is given, and "apply" if a plan file is passed as an
  argument.

Options:

  -draw-cycles     Highlight any cycles in the graph with colored edges.
                   This helps when diagnosing cycle errors.

  -type=plan       Type of graph to output. Can be: plan, plan-destroy, apply,
                   validate, input, refresh.

  -module-depth=n  (deprecated) In prior versions of Terraform, specified the
                                   depth of modules to show in the output.
Error parsing command-line flags: flag provided but not defined: -plan

Hi @akosasante,

The latest version of Terraform does have a -plan option like you tried to use here, so I think the problem here is that you’re using an older version of Terraform that didn’t have that option yet.

I think that if you use a more recent version of Terraform then what you tried would work, but note that the saved plan file format is specific to each Terraform version and so you’d need to also upgrade the Terraform which is running something like terraform plan -out=plan.tfplan so that it’ll create a plan file compatible with the Terraform you’ll use to run terraform graph.