Problem
When using the tfe_team data source from the TFE provider to retrieve information about a team in Terraform Enterprise, the operation fails with an error message indicating the team could not be found.
Error: could not find team daniela-team with module.base.module.data_admin_test.data.tfe_team.admin[0] on .terraform/modules/base.data_admin_test/main.tf line 26, in data "tfe_team" "admin"
The following example Terraform configuration can trigger this error.
terraform {
required_providers {
tfe = {
source = "hashicorp/tfe"
version = "0.50.0"
}
}
}
provider "tfe" {
hostname = "xx.xxx.xx.101.nip.io"
}
data "tfe_team" "admin" {
name = "daniela-team"
organization = "daniela-org"
}Cause
The TFE provider requires an authentication token to communicate with the Terraform Enterprise API. This error occurs when a token is not provided through either the provider configuration or an environment variable.
Solutions
There are two primary methods to provide the required authentication token to the TFE provider.
Solution 1: Set the token in the provider configuration
You can set the token argument directly in the provider configuration block. For security, use an input variable for the token value.
provider "tfe" {
hostname = "xx.xxx.xx.101.nip.io"
token = var.token ## Team or user token
}
variable "token" {
type = string
description = "TFE API token."
sensitive = true
}Solution 2: Set the TFE_TOKEN environment variable
The provider can automatically read the TFE_TOKEN environment variable to authenticate. Export the environment variable in your shell before running Terraform.
$ export TFE_TOKEN="<YOUR_TFE_TOKEN>"
Outcome
After configuring one of the authentication methods, the TFE provider can successfully authenticate to your Terraform Enterprise instance, and the data source can retrieve team information without errors.
Additional Information
- For more details on authentication methods, refer to the TFE provider authentication documentation.
- For more information on the data source, see the Data Source: tfe_team documentation.