Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terraform official Docker image can't see my files

I'd like to use the official Hashicorp image to run Terraform rather than install manually. I have followed the docs on dockerhub but there aren't any details about how where to mount volumes - e.g. with 'main.tf' in current directory:

> docker run -i -t hashicorp/terraform:light init main.tf
Terraform initialized in an empty directory!

The directory has no Terraform configuration files. You may begin working
with Terraform immediately by creating Terraform configuration files.


> docker run -i -t hashicorp/terraform:light plan main.tf
stat main.tf: no such file or directory

Where do I mount the files? Is there any docuementation beyond the dockerhub page that I can also use?

like image 599
user1016765 Avatar asked Oct 21 '25 10:10

user1016765


1 Answers

The Docker Hub docs for this image are misleading and unhelpful boilerplate, unfortunately. I would ignore them.

You need to provide the present working directory as a volume mount and you'll want to pin the version of Terraform as well as follows:

docker run -v `pwd`:/workspace -w /workspace hashicorp/terraform:0.12.26 init
docker run -v `pwd`:/workspace -w /workspace hashicorp/terraform:0.12.26 apply
docker run -v `pwd`:/workspace -w /workspace hashicorp/terraform:0.12.26 destroy

This is based on the blog post Terraform With Docker by Victor Leong (sadly no longer available so I've replaced the URL with a Wayback Machine snapshot)

like image 110
Alain O'Dea Avatar answered Oct 24 '25 21:10

Alain O'Dea