13

Apologies if this may appear like a trivial question, but when I usually run terraform plan or terraform apply you get a dump at the end of information about what what resources will be created, changed or destroyed. This is great!

However, as you may notice, sometimes this output of resources exceeds the terminal buffer, so I can't see all the resources being changed.

So how would I dump this exact information into a readable file so that I can view everything that is going to be changed?

Disclaimer - it is not terraform plan -out=tfplan, as this creates an unreadable file.

Anyone have any suggestions here? I also tried stdout into a file, but this did not show the full dump of resources as I need it to.

Will
  • 229
  • 1
  • 3
  • 5

4 Answers4

18

Apologies for the delayed response. After running plan with output file, I use show command with -no-color, for example:

terraform plan -out tf.plan

terraform show -no-color tf.plan > tfplan.txt

Romina C. M.
  • 191
  • 1
  • 5
13

Edit: You can use terraform plan -out=/path/to/file

If you are on Linux or Mac, you can redirect output to a file.

terraform plan -no-color > output.txt

You can then use any reader like a cat or any other file viewer to read the file.

Note: This will work on Windows as well using the git terminal.

blong
  • 2,815
  • 8
  • 44
  • 110
Naveen Kulkarni
  • 633
  • 6
  • 16
6

Saving as a plain monochrome text file is good for the record, but I like to keep the colours as its easier to read.

This will create a text file with ANSI control characters that can be displayed with less -R or in VS Code using the ANSI Colors extension.

terraform plan -out tf.plan
terraform show  tf.plan > tfplan.ansi
less -R tfplan.ansi
intotecho
  • 4,925
  • 3
  • 39
  • 54
0

For content like the resolved userdata, the strings command can pull this from the plan file. This can be useful when debugging an unexpected user data modification.

Peter Kahn
  • 12,364
  • 20
  • 77
  • 135