-backend-config flag not working

… or most likely me not using it properly.

Hi everyone,

I’m looking to consolidate my code under the DRY principle, (Don’t Repeat Yourself), so instead of having as many forks of the same code as needed to managed the same number of environments, I’m looking to have just onec copy of the code, with different *.tfvars and *.tfbackend files to define each of these environments.

The problem is that while I can point to the proper .tfvars file depending on which environment I want to target, the same thing doesn’t work when trying to use a different backend definition.

When I run terraform init -backend-config=foo/bar, I get the following warning message:

╷
│ 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.
│ 
╵

The idea here is to eventually use the same set of .tf files with any of the enviornments needed, like: terraform plan -backend-config=env/dev.tfbackend -var-file=env/dev.tfvars.

Any help shedding light on whatever I’m doing wrong will be greatly appreciated!

Thanks,
-Martín

EDIT:
I’m following the official documentation from Backend Configuration - Configuration Language | Terraform by HashiCorp, so in the papers it should work, right?

Hi @cig0,

The -backend-config option allows overriding arguments inside your backend block, but you do still need at least an empty backend block to override into, because that’s what will tell Terraform which arguments are valid to use inside the file you provided (because each backend type has its own set of arguments).

1 Like