-
Notifications
You must be signed in to change notification settings - Fork 3
Hands on 1: Installing local environment
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.
Well, to do the next steps in this tutorial you need to be able to run things hands-on.
You're already able to run Terraform on the command-line somewhere with access to the internet.
- 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.
- 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?
- Not local. Install an ssh client and login to some remote machine on aws, for example.
- 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 ''.
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:
- Install Docker for your machine:
- Check that docker is working by running the hello world test on the command line:
docker run -it --rm hello-world
- Grab and run the official aws cli docker image on the command line:
docker run -it --rm mesosphere/aws-cli:latest --version
- Grab and run the official terraform docker image on the command line:
docker run -it --rm hashicorp/terraform:latest --version
- 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.
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 :)