tf-summarize
tf-summarize copied to clipboard
[Feature Request] display more meaningful name as summary
Hi team, currently the markdown table generated by tf-summary looks like.
| CHANGE | NAME |
|---|---|
| update | module.my_team.module.services["training"].pagerduty_service.this |
| module.my_team.module.services["training-incident-triage"].pagerduty_service.this |
However, the name module.my_team.module.services["training"].pagerduty_service.this is not a good indicator to tell me which resource. Shall we consider to refactor the output a little bit? Like
| CHANGE | TYPE | NAME |
|---|---|---|
| update | service | Training Service |
Hi @m1n9o,
As far as I know, we cannot easily do that.
- Users can name their module, resources as they want to
- Users can have nested modules
- Users can have the same resource with same name cross multiple modules
- We have lot of terraform providers, each resource in each provider has some meaning
So, I feel it is not easy. Let me know if you have any ideas to achieve this. Thanks
use this python script meanwhile
import json
import argparse
from prettytable import PrettyTable
def parse_json(file):
with open(file) as json_file:
data = json.load(json_file)
table = PrettyTable()
table.field_names = ["CHANGE", "TYPE", "RESOURCE", "NAME"]
for resource in data.get("resource_changes", {}):
change = ", ".join(resource.get("change", {}).get("actions", []))
resource_type = resource.get("type")
resource_name = resource.get("name")
resource_addr = resource.get("address")
if change not in ["no-op", "read"]:
table.add_row([change, resource_type, resource_addr, resource_name])
print(table)
def main():
parser = argparse.ArgumentParser(description="Parses a Terraform JSON file.")
parser.add_argument("--file", help="The file path to parse.")
args = parser.parse_args()
parse_json(args.file)
if __name__ == "__main__":
main()
pyton tf_summary.py --file tfplan.json
output as follows:
+----------------+---------------+-------------------------+-----------+
| CHANGE | TYPE | RESOURCE | NAME |
+----------------+---------------+-------------------------+-----------+
| delete, create | null_resource | null_resource.build_jar | build_jar |
+----------------+---------------+-------------------------+-----------+