Open dkirrane opened 2 years ago
Hello, there. Despite the error regarding being unable to read the CLI config, you may not be experiencing an authentication failure. When a token is not authorized to read from a tfe datasource, you should see the following error:
data.tfe_outputs.foo: Reading...
╷
│ Error: Error reading remote state output
│
│ with data.tfe_outputs.foo,
│ on main.tf line 20, in data "tfe_outputs" "foo":
│ 20: data "tfe_outputs" "foo" {
│
│ Error reading remote state output: Error reading workspace: unauthorized
╵
Instead, can you check to ensure that the outputs you expect are available? Create a minimal config that reads the tfe_outputs and writes them to an output, for example:
provider "tfe" {
token = "foo"
}
# ---
data "tfe_outputs" "foo" {
organization = "hashicorp"
workspace = "terraform-minimal"
}
resource "null_resource" "null" {
triggers = {
"key" = data.tfe_outputs.foo.values.a-string
}
}
output "sensitive-stuff" {
value = data.tfe_outputs.foo.values
sensitive = true
}
@brandonc
The workspace I'm importing into has an empty state file. It hasn't been run yet.
The data "tfe_outputs"
does not exist in state yet.
Does this mean I'll have to run plan/apply first so Terraform state has the tfe_outputs
datasources populated. Before importing other resources?
The remote workspace it's reading does have the outputs.
The TFE_TOKEN
is set as env variable on the workspace itself (and I also set it locally when running terraform import). It's a Team token and has admin privileges' on the Terrafrom Cloud workspaces (admin on both the one I'm running terrform import on and the remote workspace I'm readin from via tfe_outputs).
Terraform config has
provider "tfe" {
# Gets Terraform Cloud token from env variable
# TFE_TOKEN
}
I have also tried setting TF_TOKEN_app_terraform_io
env variable to get rid of the [ERROR] Error reading CLI config or credentials file
. But that didn't work
I got rid of the the [ERROR] Error reading CLI config or credentials file
by manually creating the credentials.tfrc.json
file.
Setting the env variables TFE_TOKEN
or TF_TOKEN_app_terraform_io
was not enough.
mkdir ~/.terraform.d
cat >~/.terraform.d/credentials.tfrc.json<<EOL
{
"credentials": {
"app.terraform.io": {
"token": "${TFE_TOKEN}"
}
}
}
EOL
However, the other error still exists on terraform import
Error: 12:11.812Z [ERROR] provider.terraform-provider-tfe_v0.37.0_x5: [ERROR] Error parsing provider name "": Invalid provider source string: The "source" attribute must be in the format "[hostname/][namespace/]name"
@dkirrane I'm sorry I never followed up with you. The provider can be authenticated (in order of decreasing priority) using the token provider config, the TFE_TOKEN environment variable, and finally terraform login
credentials.
tfe_outputs are only populated once the target workspace has state applied. If your data source points at a workspace that has outputs, that should be enough.
The import error appears to be caused by the source string within the terraform/provider_requirements block and not the outputs in particular. Hopefully you figured this out long ago, but if you are still having trouble let me know.
I have this error in my runs, has anyone got the fix?
[ERROR] Error reading CLI config or credentials file /home/tfc-agent/.tfc-agent/component/terraform/runs/
Terraform Cloud/Enterprise version
Terraform Cloud
Terraform version
Issue
My terrafrom plan uses
tfe_outputs
datasource to lookup remote state. When I runterraform import
on this plan I hit below error Locally, I have also tried setTFE_TOKEN
env variable before running terraform import but hit the same issue.