-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtf.py
More file actions
25 lines (19 loc) · 691 Bytes
/
tf.py
File metadata and controls
25 lines (19 loc) · 691 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import json
import argparse
parser = argparse.ArgumentParser(description='Process Terraform state file to extract resource types.')
parser.add_argument('state', help='The path to the Terraform state file')
args = parser.parse_args()
# Opening JSON file
f = open(args.state)
data = json.load(f)
resource_types = {}
# Looping through the resources and storing the number in resource_types dictionnary
for i in data.get('resources'):
resource_type = i.get('type')
if resource_type in resource_types:
resource_types[resource_type] += 1
else:
resource_types[resource_type] = 1
print(json.dumps(resource_types, indent=2, sort_keys=True))
# Closing file
f.close()