Navigation Menu

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

terraform_remote_state remote backend ignores token in config block when token is present in CLI config #30664

Open
tangentspace opened this issue Mar 12, 2022 · 2 comments
Labels
bug cloud Related to Terraform Cloud's integration with Terraform v1.1 Issues (primarily bugs) reported against v1.1 releases

Comments

@tangentspace
Copy link
Contributor

Terraform Version

Terraform v1.1.7

Terraform Configuration Files

data "terraform_remote_state" "example" {
  backend = "remote"

  config = {
    hostname     = "terraform.example.com"
    token        = var.tfe_example_access_token
    organization = "ExampleOrg"
    workspaces = {
      name = "ExampleWorkspace"
    }
  }
}

output "something" {
  value = data.terraform_remote_state.example.outputs.vpcs
}

Expected Behavior

Terraform uses the API token provided in the config block to access the remote state for the target workspace.

Actual Behavior

Terraform always uses the API token from the CLI config file when it exists, ignoring the token explicitly provided in config block.

Steps to Reproduce

Create a .terraformrc file containing a token which does not have access to the target workspace.

Additional Context

This makes it impossible to configure API tokens for workspaces that are not accessible using the token defined in the .terraformrc file. In previous Terraform versions which used the atlas backend, the data source token config overrode other config sources, and this behavior has changed in the new remote backend which breaks existing workflows.

References

I opened a PR that implements the desired functionality: #30663

@tangentspace tangentspace added bug new new issue not yet triaged labels Mar 12, 2022
@jbardin jbardin added the cloud Related to Terraform Cloud's integration with Terraform label Mar 24, 2022
@crw crw removed the new new issue not yet triaged label Apr 6, 2022
@rubyisbeautiful
Copy link

rubyisbeautiful commented May 20, 2022

In a possibly related issue, the expected behavior of providing the token on the commandline, e.g. terraform init -backend-config=token=abc123 would be to override .terraformrc, but it does not. This is not documented.
I see #30917 addresses that.

@crw
Copy link
Collaborator

crw commented May 20, 2022

Thanks for these reports! I am checking to see if this issue was fixed by that same PR, but have yet to hear back. I'll update this issue when I hear back. Thanks again!

@apparentlymart apparentlymart added the v1.1 Issues (primarily bugs) reported against v1.1 releases label Sep 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cloud Related to Terraform Cloud's integration with Terraform v1.1 Issues (primarily bugs) reported against v1.1 releases
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants