tf-summarize icon indicating copy to clipboard operation
tf-summarize copied to clipboard

[Feature Request] display more meaningful name as summary

Open m1n9o opened this issue 2 years ago • 3 comments

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

m1n9o avatar Apr 13 '23 02:04 m1n9o

Hi @m1n9o,

As far as I know, we cannot easily do that.

  1. Users can name their module, resources as they want to
  2. Users can have nested modules
  3. Users can have the same resource with same name cross multiple modules
  4. 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

dineshba avatar May 15 '23 04:05 dineshba

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 |
+----------------+---------------+-------------------------+-----------+

raghavanrrs avatar Apr 29 '24 09:04 raghavanrrs