terraform init and apply in docker-compose.yml

by HelloWorld   Last Updated September 11, 2019 14:00 PM

Trying to run docker-compose up to spin up this docker image: hashicorp/terraform:0.11.13 (need that specific).

I expect: a terraform container to run both terraform init and terraform apply commands but I'm unable to do so.

This is how my yaml looks like:

version: "2"
services:
  terraform:
    #env_file:
     # - .env
    image: hashicorp/terraform:0.11.13
    volumes:
      - "//c//Users/user1/development/terraform/:/tmp/test"
    working_dir: /tmp/test
    environment:
      AWS_ACCESS_KEY_ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
      AWS_SECRET_ACCESS_KEY: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    command: init /tmp/test/ && apply /tmp/test

Terraform does understand it as a bad structured syntax since it troughs me the help:

"The init command expects at most one argument"

Then tried using:

command: init /tmp/test/
command: apply /tmp/test

Getting this:

Error: No configuration files found!

Finally this way:

- /bin/sh
  - -c
  - |
    terraform init /tmp/test/
    terraform apply /tmp/test

Getting this:

ERROR: yaml.scanner.ScannerError: while scanning a simple key in ".\docker-compose.yml", line 17, column 9 could not find expected ':' in ".\docker-compose.yml", line 18, column 9

Would you please shed some light into this?

TY!



Related Questions


docker compose sharing volumes with mapped to paths

Updated April 30, 2017 19:00 PM

Docker Issue - exit status 34

Updated January 25, 2018 13:00 PM


docker stack network issue

Updated September 11, 2017 12:00 PM