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?
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With