New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
anosulchik opened this Issue Apr 11, 2017 · 5 comments

Comments

Projects
None yet
4 participants
@anosulchik

anosulchik commented Apr 11, 2017

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.

@anosulchik

This comment has been minimized.

Show comment
Hide comment
@anosulchik

anosulchik Apr 11, 2017

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.

anosulchik commented Apr 11, 2017

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.

@jbardin

This comment has been minimized.

Show comment
Hide comment
@jbardin

jbardin Apr 17, 2017

Contributor

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.

Contributor

jbardin commented Apr 17, 2017

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.

@jbardin jbardin closed this Apr 17, 2017

@anosulchik

This comment has been minimized.

Show comment
Hide comment
@anosulchik

anosulchik Apr 17, 2017

init requires that to be in the working directory

Thanks! @jbardin

anosulchik commented Apr 17, 2017

init requires that to be in the working directory

Thanks! @jbardin

@devth

This comment has been minimized.

Show comment
Hide comment
@devth

devth May 4, 2017

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?

devth commented May 4, 2017

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?

@jbardin

This comment has been minimized.

Show comment
Hide comment
@jbardin

jbardin May 4, 2017

Contributor

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

Contributor

jbardin commented May 4, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment