0
votes

I am trying Terraform as Docker. I have pulled the image from:

Docker Repo Image

I have simple main.tf:

output "greetings" { value = "Hello World!" }

provider "random" {}

Now, in the same dir as main.tf I run:

docker run -i -t hashicorp/terraform:light plan main.tf

as it is suggested on that page. But I get the error:

stat main.tf: no such file or directory

So I guess that I need to create a Dockerfile to create an image including the main.tf, right?

thanks.

1
Terraform is distributed as a single static binary. You don't need Docker to run it at all. - David Maze
thanks, indeed I know that. But I wanted to try the Docker version. - toto'

1 Answers

5
votes

First, you need to make sure that your terraform files are available inside the container. This can be done using volumes as it is shown below

$>  docker run -it -v $PWD:/tr-scripts  hashicorp/terraform:light plan /tr-scripts/

second, you may need to run init before the plan

dockerfile example

From hashicorp/terraform:light
COPY ./TR-SCRIPT /tr-scripts

RUN terraform init /tr-scripts