Terraform v0.12.26 on Windows
terraform {
backend "azurerm" {
}
}
I've found a problem when running the terraform cli on windows.
Documentation at https://www.terraform.io/docs/backends/config.html states:
File: A configuration file may be specified via the init command line. To specify a file, use the -backend-config=PATH option when running terraform init.
Similarly, terraform init -help states:
-backend-config=path This can be either a path to an HCL file with key/value
assignments (same format as terraform.tfvars) or a
'key=value' format. This is merged with what is in the
configuration file. This can be specified multiple
times. The backend type must be in the configuration
itself.
However, it appears that to make this work on Windows (using PowerShell), you need to specify it as:
terraform init -backend-config <path to file>
eg, you to make it work, there must be a space between the -backend-config and the filename. If you use an = between them, the file is silently ignored.
Documentation and help message should be corrected to reflect issue with Windows.
For me it worked both ways, with and without =. Tested with the same Terraform version: 0.12.26
For example:
terraform init -backend-config=./config/development/backend.conf
terraform init -backend-config ./config/development/backend.conf
Thanks @pito-svk; your note that it worked for you led me to do more investigation, and it appears that the problems I saw are a byproduct of running terraform on Windows (specifically, in powershell). Under linux, I can also confirm that it works for me, but on a Windows system I see the error I noted.
I've edited the issue to reflect this.
It might be Windows specific but looks like you need to include "".
i.e. terraform init -backend-config="./backend.conf"
or terraform init -backend-config "./backend.conf"
or without " but with space terraform init -backend-config ./backend.conf
All 3 above worked for me.
When I tried terraform init -backend-config=./backend.conf it returned nothing, no info but also no error.
Tested with terraform 0.12.26 in PowerShell, Windows 10
Thanks!!!!
_When I tried terraform init -backend-config=./backend.conf it returned nothing, no info but also no error._ Yes, that's the exact problem I found.
Wish this was documented better by Hashicorp!
I have reproduced this issue on 0.12.26 and 0.13.0 beta 2. I've also confirmed that this doesn't require the azure backend - the simplest reproduction case is just:
resource "null_resource" "example" {}
with a backend.conf of:
foo=bar
works:
PS Z:\src\terraform-issue-reproductions\25266> terraform-0.12.26.exe init -backend-config=backend.conf
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.
PS Z:\src\terraform-issue-reproductions\25266> echo $?
True
Doesn't work:
PS Z:\src\terraform-issue-reproductions\25266> terraform-0.12.26.exe init -backend-config=./backend.conf
PS Z:\src\terraform-issue-reproductions\25266> echo $?
False
PS Z:\src\terraform-issue-reproductions\25266> terraform-0.13.0-beta2.exe init -backend-config=./backend.conf
PS Z:\src\terraform-issue-reproductions\25266> echo $?
False
Hi all,
We're going to look into ways to provide better feedback here, starting with #25300 to address the problem where Terraform currently exits silently in this case.
In the meantime though, I want to share some general advice for using Terraform in PowerShell. PowerShell's parser is very different to the Windows Command Prompt, and so using PowerShell to run external programs (rather than cmdlets) often requires special care to avoid PowerShell misinterpreting your input.
As noted in Microsoft's PowerShell documentation, PowerShell 3.0 introduced a special sequence --% to allow you to specify that the remainder of the command line should be taken literally -- which is then more consistent with the Windows Command Prompt's handling of command lines -- and thus avoid many of the odd quirks that PowerShell's parser introduces.
I've not been able to confirm this exact command line because I'm not on a Windows machine today, but something like the following ought to work to work around PowerShell-parser-related quirks by disabling PowerShell's unusual parser:
terraform --% init -backend-config=./config/development/backend.conf
Internally, the above makes PowerShell handle the command line in a way that is consistent with the usual command line processing rules on Windows, whereas by default PowerShell parses the command line as PowerShell syntax and then tries to re-assemble the result into a command line string, often corrupting it in the process (as in this case).
You can also avoid these PowerShell parser issues by running Terraform in the standard Windows Command Prompt (cmd.exe) instead, which is better designed to work with the command line processing conventions on Windows.
It isn't really practical for us to show a PowerShell equivalent of every command in the documentation right now, so we'll look into ways to give better feedback for these cases in the short term, while also considering more general solutions for the longer term.
Terraform Version: 0.12.29
AWS Provider: 2.70.0
Hey folks, maybe I'm doing something wrong here as I've been away from terraform for nearly a year and it's very uncommon for me to be in windows, but I'm running into a similar issue. I am getting these problems in PowerShell, the cmd prompt, as well as the WSL2 Bash for Ubuntu 20.04.
I'm doing the following:
terraform init -backend-config="./config/qa/ca-central-1/backend_config"
I'm receiving the following warning:
Warning: Missing backend configuration
-backend-config was used without a "backend" block in the configuration.
If you intended to override the default local backend configuration,
no action is required, but you may add an explicit backend block to your
configuration to clear this warning:
terraform {
backend "local" {}
}
However, if you intended to override a defined backend, please verify that
the backend configuration is present and valid.
My backend_config looks like so:
terraform {
backend "s3" {
bucket = "terraform.qa.obfuscated.ca"
key = "state"
region = "ca-central-1"
}
}
Please let me know your thoughts.
*edit: this doesn't seem to work in linux either? I'm missing something...?
I figured this out, "partial configuration" was the key. only the k/v pairs belonged in the backend_config file