Docker with Terraform on Clouds GCP and AWS

Ibrezm
2 min readJan 29, 2022

Sometimes we just need a container ready in the cloud for testing different artifacts or Ideas. I have faced this a lot be it setting up a splunk forwarder, Concourse server, quickly testing out SlackStrom. While all this is very diverse subjects, I am here to talk about how to stand up these quickly and destroy them efficiently.

In all of the above cases we need a cloud VM and docker ready , docker can then be used as building blocks for others.

So here I will show you how to set up docker ready VM in AWS or GCP quickly with all the relevant installations done via Terraform. Lets go ….

I will probably go over two repos that I have been working on one for GCP and one for AWS, for those with no patience they are hyperlinked to the respective entities.

The Idea is pretty simple, Create a terraform script that can provision basic VPC and Firewall setup along with a VM or EC2 with it. Next install docker on it to finally give it up to the user.

Some quick prerequisites,

Have Terraform installed

in case you plan to use GCP :

Install gcloud CLI — Gcloud init — and if possible please have config set for your own ease, if you swtich to multiple accounts / service accounts etc.

For AWS :

Please install AWS CLI — aws configure — You will probably find it better to create a IAM user (seperate than the root user ) and use them — Again if you switch a lot better to create named profiles.

With all this pre-req aside you can clone the the respective repo and have a look into run-terra.sh

Please set up the credentials if you are using a json key ( Service account in GCP) and you should be good to go.

just execute ./run-terra.sh and wait for 2–3 mins to get your enviornment ready !!!

--

--