Skip to content

Hands on 1: Installing local environment

Dr. Rob Lambert, PhD edited this page Jan 18, 2018 · 6 revisions

Why do we use local anything?

Isn't it cool if you can run most things in this tutorial and practice some things from your laptop? For most purposes we will be building things from within a preconfigured shared environment, but for the purposes of this tutorial to be runnable by anyone anywhere we need some local stuff.

Why do you need to know about it?

Well, to do the next steps in this tutorial you need to be able to run things hands-on.

Skip over if:

You're already able to run Terraform on the command-line somewhere with access to the internet.

Options for you local setup:

  1. Docker. No matter what your base OS is, you can get the exact right and same environment as us by using a docker container on your Mac, Linux or Windows machine. Slightly more efficient on Linux, but saves so much time this is pretty much the recommended option.
  2. Vagrant/VirtualBox: on your Mac or Windows machine, you can use a full VM instead of a container, heavier, less portable, but maybe you like the pain?
  3. Not local. Install an ssh client and login to some remote machine on aws, for example.
  4. Actual physical local installation of the Terraform software: not recommended, not needed, because you'd have to maintain it yourself, especially not on windows because of OS minor deviations, like '/' vs ''.

Prerequisites and pre-reading

You will need:

  • A computer where you are the admin, or docker is already installed
  • Access to the internet over most ports including port 22
  • Some disk space on your machine
  • A recent/updated operating system, most containerization features don't work on older linux or windows installations. For linux think ubuntu 16+ or centos/redhat 7+, for Windows think 8.1+

You must know:

  • The basics of command line work
  • The basics of the internet
  • Multidimensional rifts and the Cthulhu mythos (just kidding, after all, that's unknowable)

Things you can learn now:

Recommended installation.

  1. Install Docker for your machine:
  1. Check that docker is working by running the hello world test on the command line:
  • docker run -it --rm hello-world
  • Docker works
  1. Grab and run the official aws cli docker image on the command line:
  • docker run -it --rm mesosphere/aws-cli:latest --version
  • aws cli
  1. Grab and run the official terraform docker image on the command line:
  • docker run -it --rm hashicorp/terraform:latest --version
  • terraform
  1. Install your favorite git client and IDE
  • for example git bash with pycharm, or Eclipse with in-built git integration.
  • If you don't have a favorite, then probably you need to do some more before you can go further with this tutorial, find a colleague or friend to help you out with git and IDEs.

Configuration and Test Run

To connect to aws, you will need your ID and secret key. We will get back to that in the next tutorial. However, oce you have those you need a way to pass them to docker, let's do that without needing to type it in plain text! in fact let's use the standard aws way of doing that, by mounting a file in docker.

> cd $HOME
> mkdir .aws

Now configure awscli via docker:

> docker run -it --rm -v $HOME/.aws:/root/.aws mesosphere/aws-cli:latest configure
AWS Access Key [NONE]:
...

Now your credentials are stored and you can run the cli via docker with:

> docker run -it --rm -v $HOME/.aws:/root/.aws mesosphere/aws-cli:latest ...something...

We can do the same sort of thing for terraform, now. We haven't really learnt too much about terraform yet, but let's anyway do some magic now, and then we'll use it later. To understand more about what you are doing you could read: https://www.terraform.io/intro/getting-started/variables.html

Make a file called aws_creds.tfvars in the same folder ($HOME/.aws), and add your credentials something like:

aws_access_key = "thelongaccesskey_uniqueID"
aws_secret_key = "thathexadecimalnumberstringkey"

Now when you write terraform code, you'll need to remember the names of these variables, declare these as variables, and also pass them when planning and building.

> docker run -it --rm -v $HOME/.aws:/root/.aws hashicorp/terraform:latest --tfvars=/root/.aws/aws_creds.tfvars ...something...

Remember this then :)