Terraform: Terraform backend init: settings in -backend-config file are ignored

Created on 11 Apr 2017  ยท  6Comments  ยท  Source: hashicorp/terraform

Hi there,

I faced the following issue with terraform 0.9.2. THere's backend configuration file that contains settings for s3 backend:

terraform {
  backend "s3" {
    bucket = "ourteam-terraform-dev"
    key = "anosulchik.tfstate"
    region = "us-east-1"
  }
}

Then I'm trying to do terraform init to this backend:

$ terraform init -backend-config environments/staging/backend.tf -backend=true -force-copy  -lock=false

This command produces the following output stating that initialization went well:

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your environment. If you forget, other
commands will detect it and remind you to do so if necessary.

But file .terraform/terraform.tfstate isn't created in current directory so backend is not configured. This doesn't look right. Please advise.

bug core

Most helpful comment

I've managed to override this by moving backend.tf to current directory with partial configuration:

terraform {
  backend "s3" {}
}
$ terraform init -backend-config="bucket=ourteam-terraform-dev" -backend-config="key=anosulchik.tfstate" -backend-config="region=us-east-1" -backend=true -force-copy -get=true -input=false

After that file .terraform/terraform.tfstate is created and I can do terraform plan and apply now.

All 6 comments

I've managed to override this by moving backend.tf to current directory with partial configuration:

terraform {
  backend "s3" {}
}
$ terraform init -backend-config="bucket=ourteam-terraform-dev" -backend-config="key=anosulchik.tfstate" -backend-config="region=us-east-1" -backend=true -force-copy -get=true -input=false

After that file .terraform/terraform.tfstate is created and I can do terraform plan and apply now.

Hi @anosulchik,

Sorry about the confusion here. The file argument to -backend-config is a key-value vars file containing the options to configure the backend. It is not another terraform configuration file.

The "terraform" block and "backend" setting must be part of the current configuration, and init requires that to be in the working directory.

init requires that to be in the working directory

Thanks! @jbardin

init requires that to be in the working directory

This seems wrong. It should allow the user to specify a directory the same way terraform plan and terraform apply do, right?

Hi @devth,

Yes, we're discussing trying to clarify this, and possibly change the behavior somewhat. Backends are a little different, because they have both a saved config and the configuration given the .tf files which must match.

We'll look into this under #14066

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shubhambhartiya picture shubhambhartiya  ยท  72Comments

FlorinAndrei picture FlorinAndrei  ยท  61Comments

kforsthoevel picture kforsthoevel  ยท  86Comments

felnne picture felnne  ยท  133Comments

glenjamin picture glenjamin  ยท  112Comments