From 66256249e7991f3e6754d781644c29153c494fce Mon Sep 17 00:00:00 2001 From: Olivier Bourdon Date: Tue, 8 Dec 2020 14:05:43 +0100 Subject: [PATCH 1/6] Update to Terraform 0.12.29 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 2d35634..6a2445f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -ARG TF_VERSION=0.12.12 +ARG TF_VERSION=0.12.29 ARG PYTHON_VERSION=3.7 FROM hashicorp/terraform:$TF_VERSION AS terraform From 4a11e214acfea06efce917e3f845d37193aed90f Mon Sep 17 00:00:00 2001 From: Olivier Bourdon Date: Tue, 18 Jun 2019 13:42:53 +0200 Subject: [PATCH 2/6] Misc additions/fixes Update to Terraform 0.12.29 Allow passing more variables to change behaviour Add meaningful error messages --- README.md | 20 ++++++++++++++++++++ blastradius/server/server.py | 9 +++++---- blastradius/server/templates/error.html | 1 + docker-entrypoint.sh | 10 ++++++---- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index d475fd7..80f7ce5 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,26 @@ $ docker run --rm -it -p 5000:5000 \ 28mm/blast-radius --serve stacks/beef ``` +## Additional notes for Docker usage + +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 (default is not to run `terraform init`). + +You can salso pecify `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. + +If you have several other variables to specify for your terraform command, like `AWS_PROFILE` or dedicated variable files, you can do so as follows: + +```sh +$ docker run --rm -it -p 5000:5000 \ + -v $(pwd):/data:ro \ + --security-opt apparmor:unconfined \ + --cap-add=SYS_ADMIN \ + -e TF_DATA_DIR=/data-rw/.terraform.dev \ + -e AWS_PROFILE=dev \ + -v $HOME/.aws/:/root/.aws/:ro,Z \ + -v $w/$s/terraform-dev.tfvars:/data-rw/terraform.tfvars:Z \ + 28mm/blast-radius +``` + ## Embedded Figures You may wish to embed figures produced with *Blast Radius* in other documents. diff --git a/blastradius/server/server.py b/blastradius/server/server.py index aae9278..9d588fc 100644 --- a/blastradius/server/server.py +++ b/blastradius/server/server.py @@ -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()) diff --git a/blastradius/server/templates/error.html b/blastradius/server/templates/error.html index ea97c1f..1326379 100644 --- a/blastradius/server/templates/error.html +++ b/blastradius/server/templates/error.html @@ -13,6 +13,7 @@

Something has gone wrong. Please check the following:

  • Is Terraform installed?
  • Is this an init-ed Terraform project?
  • +

    {{ error }}