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

blast-radius for terraform v12 #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
blast-radius for terraform v12
  • Loading branch information
nibhart1 committed Mar 17, 2020
commit bafab426c0c8d6f4e04060fa68e74225dd986752
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ clean:
dist:
-python3 setup.py sdist


# install hcl2json binary
.PHONY: install-dep
install-dep:
-go get github.com/tmccombs/hcl2json

# build docker image
.PHONY: docker
docker:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Use _Blast Radius_ to:

* [Graphviz](https://www.graphviz.org/)
* [Python](https://www.python.org/) 3.7 or newer
* [Go](https://golang.org/) 1.12.16 or newer

> __Note:__ For macOS you can `brew install graphviz`

Expand Down
18 changes: 13 additions & 5 deletions blastradius/handlers/terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import io
import os
import re
import subprocess
import json

# 3rd party libraries
import hcl # hashicorp configuration language (.tf)
Expand All @@ -16,14 +18,20 @@ def __init__(self, directory=None, settings=None):

# handle the root module first...
self.directory = directory if directory else os.getcwd()
#print(self.directory)

self.config_str = ''
iterator = iglob( self.directory + '/*.tf')
data = {}
for fname in iterator:
with open(fname, 'r', encoding='utf-8') as f:
self.config_str += f.read() + ' '
config_io = io.StringIO(self.config_str)
self.config = hcl.load(config_io)
out=subprocess.getoutput(["hcl2json {}".format(fname)])
file_data = json.loads(out)
for key in file_data:
if not key in data.keys():
data.update(file_data)
else:
for k,v in file_data[key].items():
data[key][k]=v
self.config = data

# then any submodules it may contain, skipping any remote modules for
# the time being.
Expand Down