Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] display more meaningful name as summary #33

Open
m1n9o opened this issue Apr 13, 2023 · 2 comments
Open

[Feature Request] display more meaningful name as summary #33

m1n9o opened this issue Apr 13, 2023 · 2 comments
Labels
question Further information is requested

Comments

@m1n9o
Copy link

m1n9o commented Apr 13, 2023

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
@dineshba
Copy link
Owner

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 dineshba added the question Further information is requested label May 15, 2023
@raghavanrrs
Copy link

raghavanrrs commented Apr 29, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants