Skip to content

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

@tangentspace

Description

@tangentspace

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcloudRelated to Terraform Cloud's integration with Terraformwaiting-responseAn issue/pull request is waiting for a response from the community

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions