Learn how to export your Terraform plan and apply outputs to a readable file for easy sharing, documentation, and troubleshooting.
When working with Terraform, understanding the execution plan before applying changes to your infrastructure is crucial. While terraform plan provides this information, the output is not easily digestible. To view the plan in a human-readable format, follow these steps:
To get a human-readable Terraform plan, you should use the terraform show command with a plan file.
Generate a plan file: Run terraform plan -out=tfplan.out to save the execution plan to a file named "tfplan.out". This file is in a binary format, not directly human-readable.
Convert the plan to a readable format: Use the command terraform show tfplan.out to display the plan in a user-friendly format within your terminal.
(Optional) Save the readable output to a file: Redirect the output of the previous command to a file using terraform show tfplan.out > readable_plan.txt. This will create a file named "readable_plan.txt" containing the human-readable plan.
While you can redirect the output of terraform plan directly to a file, this approach is not recommended for storing and reusing the plan. The -out flag with terraform plan is specifically designed for saving an executable plan that can be later applied using terraform apply.
This code snippet explains how to create a human-readable Terraform plan. It starts by creating a simple Terraform configuration file. Then, it uses the 'terraform plan' command to generate a plan file. The 'terraform show' command is used to display the plan in a user-friendly format, which can optionally be saved to a text file. The code emphasizes that while you can redirect the output of 'terraform plan' directly, it's recommended to use the '-out' flag for saving an executable plan.
This example demonstrates how to generate a human-readable Terraform plan.
1. Create a Terraform Configuration File (e.g., main.tf):
resource "google_storage_bucket" "example" {
name = "my-tf-test-bucket"
location = "US"
force_destroy = false
}2. Generate a Plan File:
terraform plan -out=tfplan.outThis command generates an execution plan and saves it to the "tfplan.out" file.
3. Convert the Plan to a Readable Format:
terraform show tfplan.outThis command displays the plan in a user-friendly format within your terminal.
4. (Optional) Save the Readable Output to a File:
terraform show tfplan.out > readable_plan.txtThis command redirects the output of the previous command to a file named "readable_plan.txt".
Important Note:
While you can redirect the output of terraform plan directly to a file, this is not recommended for storing and reusing the plan. The -out flag with terraform plan is specifically designed for saving an executable plan that can be later applied using terraform apply.
terraform show) before applying changes. This helps prevent unintended consequences and ensures your infrastructure changes are as expected..tfplan files to version control. This provides an audit trail of planned changes and allows for easy rollback if needed.terraform plan only shows the planned execution, while terraform apply actually makes the changes to your infrastructure.terraform show provides a user-friendly format, you can explore tools like terraform-plan-parser or jq for further customization and integration with other tools.terraform show can be overwhelming. Consider using tools like grep or less to filter and navigate the output effectively.| Step | Command | Description |
|---|---|---|
| 1. Generate Plan File (binary) | terraform plan -out=tfplan.out |
Creates a file named "tfplan.out" containing the execution plan in a binary format. |
| 2. Convert to Readable Format | terraform show tfplan.out |
Displays the plan in a user-friendly format in the terminal. |
| 3. (Optional) Save Readable Output | terraform show tfplan.out > readable_plan.txt |
Saves the human-readable plan to a file named "readable_plan.txt". |
Note: While you can redirect terraform plan output directly, it's not recommended for storing reusable plans. Use the -out flag for creating executable plans for later use with terraform apply.
In conclusion, generating a human-readable Terraform plan is essential for understanding and verifying infrastructure changes before applying them. Using the terraform show command with a plan file allows for easy review and collaboration, reducing the risk of unintended consequences. Remember to integrate this practice into your workflow for safer and more transparent infrastructure management.
Terraform plan Write Out is Not Readable Text - Terraform ... | Was reading the doc and tried several times to write out a plan to a file that is readable text. Looks like itās writing out binary. I have been redirecting the output via the ā>ā operation. When redirecting output, the plan is readable. When using terraform plan -out=new.plan, this shows portion of plan file: I can use redirect but would like to get the option working.
Command: apply | Terraform | HashiCorp Developer | When you pass a saved plan file to terraform apply , Terraform takes the ... for all files it would normally read or write in the current working directory.
Internals: JSON Output Format | Terraform | HashiCorp Developer | ... Terraform can output a machine-readable JSON representation of a plan file's changes. ... // to try to apply this plan, possibly after asking a human operator forĀ ...
Running CI/CD Pipeline Across Multiple Directories in one project ... | Hello, So Iāve recently created a little test environment, just to mess around with creating a pipeline. I have my .gitlab-ci.yml file in the root of my directory, and if I add a new file, s3.tf for example, with the necessary code to create an S3 Bucket in AWS, I can run my pipeline and it will deploy the infrastructure with no problem at all. However, Iād like to expand this project at some point, so I would prefer to put all of my āinfrastructureā files into a directory called āinfraā. The...