Syntax error in line 1

You could also try

dot -Tsvg TerraformGraph20220930.dot -o TerraformGraph20220930.svg

I’m wary of side-effects in redirection in the Windows shell(s).

Hi, Its Dec 2023
I encountered this error in my Windows PC while running on PowerShell
PS C:\Terraform> terraform graph | dot -Tpng > graph.png
Error: : syntax error in line 1 near ‘digraph’

Turns Out that file named by graph.dot in the folder is being saved automatically in UTF-8-BOM
So the solution is
1- Run this command → terraform graph
2- Open the graph.dot file (it is created in the directory you run command) in Notepad++
3- Go to Encoding and change it settings to UTF-8 and save it.
4- Run this command → dot -Tpng graph.dot -o TerraformGraphNew.png

Hope it helps

1 Like