Is there an official docker image for applying Terraform json configuration

Docker image is so cool for applying HCL, but is there an official docker image for applying Terraform JSON configurations? Thanks.

Hi @zzxwill,

The Docker images you referred to here are essentially just a minimal Linux distribution with the linux_amd64 build of Terraform copied into them, so you can in principle use them to do anything that you could do by installing the primary Terraform distribution packages, albeit with the extra overhead of having to correctly configure Docker first. There is no special image or package for JSON configuration support; that’s just built in to the terraform executable, which is installed in those images.

Thanks for the reply, while it didn’t work for JSON configuration files.

It worked by terraform plan, but didn’t by the docker. Besides, it worked for HCL.

Hi @zzxwill,

I believe that in order to use the Docker image in the way you tried here you’ll need some additional command line options to make sure that the filesystem inside the docker container will include your configuration files that are presumably not in the docker container.

How to configure that is a Docker-specific situation that I don’t personally have a ready answer for today, because I’ve not used Docker for a while, but maybe someone else in this forum remembers the settings for mapping in a directory and setting the working directory, which I think are what is needed here.

I don’t think the problem you saw here is specific to the JSON version of the language; instead, the Terraform running inside the docker container is reporting that there are no configuration files within the working directory inside the container at all, whether .tf or .tf.json.

Running Terraform directly as a regular program is far simpler than dealing with all of the extra indirection of Docker, so if you are intending to run it directly as you showed here (as opposed to special situations like producing a custom image to use for jobs in a Docker-based CI system) I would suggest just running the terraform executable directly as you did in your second example, which was successful.

1 Like