Containerised Terraform CLI with Pythyon3, GCP, AWS sdks and GOSU installed.
The below 2 examples are using the terraform
user inside the container.
This is explained below in Configuration.
Run as a command:
docker run --rm -v ~/.aws:/home/terraform/.aws -v $(pwd):/opt/app contino/terraform --version
Using docker-compose:
terraform:
image: contino/terraform
env_file: .env
volumes:
- ~/.aws:/home/terraform/.aws
- .:/opt/app:rw
And run docker-compose run terraform --version
Can also set as a bash function and placed in your ~/.bashrc
or equivalent
for quick access, with correct mounting points:
function terraform() {
docker run --rm -it -v ~/.aws:/home/terraform/.aws -v $(pwd):/opt/app contino/terraform "$@";
}
Then run terraform {params} {action}
just like you are using your local
terraform
executable.
There are some custom configurations that can be applied to prevent the
container from running as root and owning all your files.
gosu is utilised to set the UID and GID of
the custom user inside the container to whatever /opt/app
is mounted as from
the host.
Here are some quick optional
environment variables to get you started:
TERRAFORM_UID
- Custom UID to run terraform process as. Default will try to determine from host mount permissions (i.e. your user ID).TERRAFORM_GID
- Custom GID to run terraform process as. Default will try to determine from host mount permissions (i.e. your group ID).TERRAFORM_USER
- Custom user name to run terraform process as. Defaults toterraform
TERRAFORM_GROUP
- Custom group name to run terraform process as. Defaults toterraform
Remember that these variables are completely optional and that the entrypoint.sh
will do its best to determine UID and GID of the user that invokes the container
from the host machine by whatever the mount point is.
Update the TERRAFORM_VERSION
in both Makefile
and DockerFile
. Then run:
make build
Docker Hub will automatically trigger a new build.