0

I'm using terraform on windows, and would like to visualize the graphs using Graphviz. However, there is a difference between the encoding that is being output by Terraform vs what Graphviz expects. Ideally, I want to do the following:

terraform graph -draw-cycles |  dot -Tsvg > output.svg

That doesn't work, because the output that is being given by terraform is in the wrong encoding. The following sequence works, but uses an intermediate file:

terraform graph -draw-cycles > output.tmp 
Get-Content .\output.tmp | Set-Content -Encoding Ascii output2.tmp
dot -Tsvg output2.tmp > output.svg
rm output.tmp
rm output2.tmp

However, I would like to do this without intermediate files using piping. A statement such as

terraform graph -draw-cycles | Set-Content -Encoding Ascii -PassThru | dot -Tsvg > output.svg

doesn't work. The output from the terraform graph statement is text, and apparantly the Set-Content commandlet needs additional information (Path?):

Set-Content : The input object cannot be bound because it did not contain the information required to bind all mandatory parameters:  Path
At line:1 char:32
+ ... rm graph -draw-cycles | Set-Content -Encoding Ascii -PassThru | dot - ...
+                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (digraph {:PSObject) [Set-Content], ParameterBindingException
    + FullyQualifiedErrorId : InputObjectMissingMandatory,Microsoft.PowerShell.Commands.SetContentCommand

Any suggestions?

4
  • Set-Content needs a -Path or -LiteralPath to a file it can write content to Commented Nov 12, 2021 at 11:05
  • Have a look at [Console]::OutputEncoding. See this answer. Commented Nov 12, 2021 at 11:31
  • @Theo so I guess I can't use Set-Content then for my purpose.... Commented Nov 12, 2021 at 12:24
  • @zett42 Your reference put me on the right track, thanks! Commented Nov 12, 2021 at 12:28

1 Answer 1

1

After reading the article referred to by zett42, I saw a reference to CMD pipe different form Powershell pipe? in the comments.

The easiest solution for my specific case is simply executing the call with cmd:

cmd /c "terraform graph -draw-cycles | dot -Tsvg > output.svg" 

Using the Invoke-WithEncoding would also work, but is a little more involved.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.