Skip to content

Latest commit

 

History

History
97 lines (68 loc) · 3.24 KB

readme.md

File metadata and controls

97 lines (68 loc) · 3.24 KB

Terraform Docker Image

! ! ! ! !

You can find this image in the link below.

https://hub.docker.com/r/raffaeldutra/docker-terraform

All tags available for this image, which is based on Terraform versions. https://cloud.docker.com/repository/docker/raffaeldutra/docker-terraform/tags

What does Terraform do?

Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. Terraform can manage existing and popular service providers as well as custom in-house solutions. Configuration files describe to Terraform the components needed to run a single application or your entire datacenter.

You will find the whole documentation here: https://https://www.terraform.io/docs/index.html

TL;DR

You will just follow the default "behavior" for Terraform, run the init, plan, apply and destroy commands in your CLI as usual, but inside a container.

You need to provide a folder containing your infrastructure's definition.

What does this image do?

  • Terraform binary installation.
  • You need to pass your folder containing the infrastructure's definition, in my example below it is my current directory $(pwd).
  • You need to pass the credentials for your service, ~/.aws or using another approach.
  • If you have modules in a different path, you need to map it using volumes.
  • If you are creating files (ssh keys, maybe?), you need to map that to get access to those files/directories.

How to build this image?

docker build -t raffaeldutra/docker-terraform .

Initializing a project

The terraform init command.

On this example:

  • Using the current terraform files and mapping it to /terraform volume.
  • Using volumes to map the credentials for AWS.
docker run --rm \
-v $(pwd):/terraform \
-v $(pwd)/modules:/terraform/modules \
-v ${HOME}/.aws:/root/.aws \
raffaeldutra/docker-terraform:v0.12.0 \
terraform init

Planning your infrastructure

The terraform plan command.

docker run --rm \
-v $(pwd):/terraform \
-v $(pwd)/modules:/terraform/modules \
-v ${HOME}/.aws:/root/.aws \
raffaeldutra/docker-terraform:v0.12.0 \
terraform plan

Applying your infrastructure

The terraform apply command.

Here we need to map ssh directory, because on this example, it generates keys in /tmp/ssh

docker run --rm \
-v $(pwd):/terraform \
-v $(pwd)/modules:/terraform/modules \
-v ${HOME}/.aws:/root/.aws \
-v $(pwd)/ssh:/tmp/ssh \
raffaeldutra/docker-terraform:v0.12.0 \
terraform apply -auto-approve

Destroying your infrastructure

The terraform destroy command.

docker run --rm \
-v $(pwd):/terraform \
-v $(pwd)/modules:/terraform/modules \
-v ${HOME}/.aws:/root/.aws \
raffaeldutra/docker-terraform:v0.12.0 \
terraform destroy -auto-approve