Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terraform plan output: what is the encoding being used

Tags:

terraform

I've saved terraform plan -out=my-plan and intend to save it to source control and inject further to custom tool for ingestion and performing testing etc.

However, the file contents of my-plan are jumbled and I'm wondering what the encoding used is.

What is the encoding being used for the Terraform plan file?

like image 201
user1619524 Avatar asked Mar 20 '18 13:03

user1619524


People also ask

What is the format of terraform plan output?

The Terraform plan output is a binary format that is not designed to be used outside of Terraform. Technically you could probably serialise it using whatever Terraform uses to handle the format but there is no stable API for this and could change at any point.

Does terraform plan show outputs?

The terraform show command is used to provide human-readable output from a state or plan file. This can be used to inspect a plan to ensure that the planned operations are expected, or to inspect the current state as Terraform sees it. Machine-readable output is generated by adding the -json command-line flag.

How do I read a terraform output file?

Output values are stored as plain text in your state file — including those flagged as sensitive. Use the grep command to see the values of the sensitive outputs in your state file. Tip: If you are using an operating system without the grep command, open the terraform.

How do you use output variables in terraform?

Terraform output variables are used within the same parent or child module to print specific values in the command line output and are also used as inputs to create resources using the terraform apply command. Below, you can see the command displays the output's EC2 instance arn and instance public IP address.


2 Answers

While the other tools mentioned here are useful, things change regularly in the Terraform space and third-party tools often aren't able to be kept up-to-date.

For some time now Terraform has directly supported viewing a plan file in the same human-readable format that is displayed at the time you run plan:

terraform show <filename>

Since v0.12 you can now also view a plan file in JSON format, which you could save to work on further with other tools:

terraform show -json <filename>

There's an explanation of the JSON schema at https://www.terraform.io/docs/internals/json-format.html. As of writing, note that:

The output ... currently has major version zero to indicate that the format is experimental and subject to change. A future version will assign a non-zero major version ... We do not anticipate any significant breaking changes to the format before its first major version, however.

like image 148
Tim Malone Avatar answered Sep 20 '22 13:09

Tim Malone


The Terraform plan output is a binary format that is not designed to be used outside of Terraform. Technically you could probably serialise it using whatever Terraform uses to handle the format but there is no stable API for this and could change at any point.

One of the Hashicorp employees (Phinze) briefly covered this in this issue: https://github.com/hashicorp/terraform/issues/7976

One, probably reasonably fragile, option would be to simply parse the text output from running terraform plan. I use Terraform Landscape to format plan outputs locally when working with JSON diffs that Terraform doesn't handle at all and that copes with this fine. However it also tends to break on the "minor" version upgrades (eg 0.9 to 0.10) as Terraform doesn't specify this as an API at all. Terraform Plan Parser also parses the textual output and notes that it is very much not to be used with the binary output.

like image 38
ydaetskcoR Avatar answered Sep 18 '22 13:09

ydaetskcoR