Search code examples
windowsterraformterraform-template-file

How do I run terraform init from a different folder?


I want to script terraform for CI/CD purpose and I don't like CDing in scripts, I rather have specific paths.

I tried terraform init c:\my\folder\containing\tf-file

But running that puts the .terraform folder in my cwd.


Solution

  • UPDATE: Terraform cli now supports -chdir=PATH/TO/TF_files

    https://www.terraform.io/cli/commands#switching-working-directory-with-chdir

    By default, terraform init assumes that the working directory already contains a configuration and will attempt to initialize that configuration.

    Optionally, init can be run against an empty directory with the -from-module=MODULE-SOURCE option, in which case the given module will be copied into the target directory before any other initialization steps are run.

    https://www.terraform.io/docs/commands/init.html