-
-
Save yermulnik/afb0b5efa68debc52fb8c35b61168147 to your computer and use it in GitHub Desktop.
Summarize TF plan output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Created by Randy Wallace (@Real Human Bot; https://hangops.slack.com/team/U4ZT6HSH5) | |
# Taken from HangOps Slack and adopted for my needs (c) yz 21-Oct-2024 | |
cat - | jq -r ' | |
# pull out changes only | |
([.resource_changes[]?]) | |
| | |
# filter out no-op changes | |
map(select(.change.actions!=["no-op"])) | |
| | |
# create pretty array of changes | |
# options documented at https://pkg.go.dev/github.com/hashicorp/terraform-json?tab=doc | |
# New Documentation: https://www.terraform.io/docs/internals/json-format.html#plan-representation | |
[ | |
# [["Operation", "Provider", "Resource Type", "Module Address", "Index ID", "Full Resource ID"]], | |
# [["---------", "--------", "-------------", "--------------", "--------", "----------------"]], | |
# (map(select(.change.actions==["create"] )) | map(["Create", .provider_name, .type, .module_address?, .index?, .address]) ), | |
# (map(select(.change.actions==["update"] )) | map(["Update", .provider_name, .type, .module_address?, .index?, .address]) ), | |
# (map(select(.change.actions==["delete"] )) | map(["!!DESTROY!!", .provider_name, .type, .module_address?, .index?, .address]) ), | |
# # Note that both these are a "Replace" operation. I prefer knowing which kind of replace is happening explicitly. | |
# (map(select(.change.actions==["create","delete"])) | map(["Replace - Create before Destroy", .provider_name, .type, .module_address?, .index?, .address]) ), | |
# (map(select(.change.actions==["delete","create"])) | map(["Replace - Destroy before Create", .provider_name, .type, .module_address?, .index?, .address]) ) | |
[["Operation", "Full Resource ID"]], | |
[["---------", "----------------"]], | |
(map(select(.change.actions==["create"] )) | map(["Create", .address]) ), | |
(map(select(.change.actions==["update"] )) | map(["Update", .address]) ), | |
(map(select(.change.actions==["delete"] )) | map(["DESTROY", .address]) ), | |
# Note that both these are a "Replace" operation. I prefer knowing which kind of replace is happening explicitly. | |
(map(select(.change.actions==["create","delete"])) | map(["Replace - Create before Destroy", .address]) ), | |
(map(select(.change.actions==["delete","create"])) | map(["Replace - Destroy before Create", .address]) ) | |
] | |
# Unnest arrays for @tsv | |
| .[] | .[] | |
# Convert to Tab Delimited | |
| @tsv | |
# column will convert tabs to spaces and make it pretty | |
' |\ | |
column -s $'\t' -t |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment