Skip to content
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

Clarify use of backend-config file #35389

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

asmacdo
Copy link

@asmacdo asmacdo commented Jun 26, 2024

-backend-config It is not a "full override" as one might expect. It works only within the context of an existing partial configuration.

I'm not confident that my docs changes are exactly correct-- but hopefully this will make things a little clearer. I realize this is within the "Partial Configuration" section, but I still found the behavior a little surprising.

(Why do I need to do this? I am using multiple tf environments, which must store their state separately.)

I (as suggested by a confused ChatGPT) attempted:

terraform init -backend-config myfile.tf

myfile.tf

terraform {
  backend "s3" {
    bucket =  "mybucket"
    key = "terraform.tfstate"
    region = "us-east-2"
    encrypt = true
    dynamodb_table = "my-tf-lock"
  }
}

IMO this seems like a pretty reasonable expectation. I did receive a warning that it wasn't overriding any specific config, but I thought that seemed ok. What I absolutely did not expect was that tf would proceed and store my tfstate locally.

The helptext was a little more helpful.

  -backend-config=path    Configuration to be merged with what is in the
                          configuration file's 'backend' block. This can be
                          either a path to an HCL file with key/value
                          assignments (same format as terraform.tfvars) or a
                          'key=value' format, and can be specified multiple
                          times. The backend type must be in the configuration
                          itself.

What ended up working for me:

backend.tf

terraform {
  backend "s3" {
    # NOTHING
  }
}
terraform init -backend-config myfile.tf

myfile.tf

bucket =  "mybucket"
key = "terraform.tfstate"
region = "us-east-2"
encrypt = true
dynamodb_table = "my-tf-lock"

It is not a "full override" as one might expect. It works only within the context of an existing  partial configuration.
Copy link

hashicorp-cla-app bot commented Jun 26, 2024

CLA assistant check
All committers have signed the CLA.

@crw
Copy link
Collaborator

crw commented Jun 26, 2024

Thanks for this submission!

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

Successfully merging this pull request may close these issues.

2 participants