Skip to content
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
19 changes: 10 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@

FROM ubuntu:18.04

#define default terraform version in environment var
ENV TF_VERSION "0.12.0"

#expose blast-radius port
EXPOSE 5000

Expand All @@ -31,21 +28,25 @@ RUN apt-get update \
graphviz \
python3 \
python3-pip \
python3-ply \
jq \
unzip \
&& rm -rf /var/lib/apt/lists/*

#install terraform
WORKDIR /src
COPY . .
RUN chmod +x ./docker-build.sh \
&& ./docker-build.sh /src

#create blast-radius package from source
RUN pip3 install -e .

#set up entrypoint script
RUN chmod +x ./docker-entrypoint.sh
RUN pip3 install -e . \
&& chmod +x ./docker-entrypoint.sh

#define default terraform version in environment var
ENV TF_VERSION "0.11.14"

#install terraform
RUN chmod +x ./docker-build.sh \
&& ./docker-build.sh /src

#set up runtime workdir for tf files
WORKDIR /workdir
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ Point *Blast Radius* at an `init-ed` *Terraform* project, and connect with your
*Additional note*:
If you organised your terraform directories with stacks and modules, please call *Blast Radius* from the root directory and give the stack's directory as argument (plus the `--serve` argument).

*Additional note*:
You can specify DO_TF_INIT=true in the docker command line as an environment variable (-e DO_TF_INIT=true) if you want terraform init to be applied

*Additional note*:
You can specify TF_DATA_DIR in the docker command line as an environment variable (-e TF_DATA_DIR=$(pwd)/.terraform) if you want terraform to use an alternate state repository

```bash
[...]$ tree -d
/-- project
Expand Down
13 changes: 7 additions & 6 deletions blastradius/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@

@app.route('/')
def index():
tf_data_dir = os.getenv('TF_DATA_DIR')
# we need terraform, graphviz, and an init-ed terraform project.
if not which('terraform') and not which('terraform.exe'):
return render_template('error.html')
return render_template('error.html', error='No terraform executable found')
elif not which('dot') and not which('dot.exe'):
return render_template('error.html')
elif not os.path.exists('.terraform'):
return render_template('error.html')
return render_template('error.html', error='No dot executable found')
elif not (tf_data_dir is not None and os.path.exists(tf_data_dir)) and not os.path.exists('.terraform'):
return render_template('error.html', error='No .terraform or TF_DATA_DIR={} directory found'.format(tf_data_dir))
else:
return render_template('index.html', help=get_help())

Expand Down Expand Up @@ -70,9 +71,9 @@ def graph_json():
return dot.json()

def run_tf_graph():
completed = subprocess.run(['terraform', 'graph'], stdout=subprocess.PIPE)
completed = subprocess.run(['terraform', 'graph'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if completed.returncode != 0:
raise
raise Exception('Execution error', completed.stderr)
return completed.stdout.decode('utf-8')

def get_help():
Expand Down
3 changes: 2 additions & 1 deletion blastradius/server/templates/error.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ <h3>Something has gone wrong. Please check the following:</h3>
<li>Is Terraform installed?</li>
<li>Is this an init-ed Terraform project?</li>
</ul>
<h4>{{ error }}</h4>
</body>

<script>
svg_activate('#graph', '/graph.svg', '/graph.json');
</script>

</html>
</html>
3 changes: 0 additions & 3 deletions docker-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,3 @@ curl -o terraform.zip $terraform_url
unzip terraform.zip
mv terraform /usr/local/bin
rm terraform.zip



12 changes: 7 additions & 5 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ cd /workdir-rw
cd $2
}

# is terraform already initialized?
[ -d '.terraform' ] && terraform get --update=true
if [ -n "${DO_TF_INIT}" ]; then
# is terraform already initialized?
[ [ -d '.terraform' ] || [ -d ${TF_DATA_DIR:-""} ] && terraform get --update=true

# re-initialize anyway.
terraform init -input=false
# re-initialize anyway.
terraform init -input=false
fi

# it's possible that we're in a sub-directory. leave.
cd /workdir-rw

# okay, we should be good to go.
blast-radius $1 $2 $3
blast-radius $1 $2 $3