Problem
When using Terraform Enterprise to provision Kubernetes resources, you may encounter the following authentication error during a run.
Get "https://xx.xx.xx.xx/apis": authenticationrequired Error: Invalid configuration for API client
This error can also appear in the context of a resource block.
on ../main.tf line 23, in resource "kubernetes_manifest" "test-configmap":
23: resource "kubernetes_manifest" "test-configmap" {
Get "https://xx.xx.xx.xx/apis": authenticationrequired
Error: Invalid configuration for API clientPrerequisites
This issue typically occurs when using Terraform Enterprise with a Kubernetes provider, such as in this example which uses GKE with Terraform and the kubernetes_manifest resource.
An example provider configuration may include the following.
terraform {
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
version = "2.7.1"
}
}
}
data "google_client_config" "provider" {}
data "google_container_cluster" "test_cluster" {
name = "test-cluster"
location = "us-central1"
}
provider "kubernetes" {
host = "https://${data.google_container_cluster.test_cluster.endpoint}"
token = data.google_client_config.provider.access_token
cluster_ca_certificate = base64decode(
data.google_container_cluster.test_cluster.master_auth[0].cluster_ca_certificate,
)
}An example resource configuration may include the following.
resource "kubernetes_manifest" "test-configmap" {
manifest = {
"apiVersion" = "v1"
"kind" = "ConfigMap"
"metadata" = {
"name" = "test-config"
"namespace" = "default"
}
"data" = {
"foo" = "bar"
}
}
}Cause
This error is often caused by missing or incorrect proxy settings within the Terraform Enterprise run environment.
- While proxy settings may be configured correctly on your local machine, they must also be defined within the Terraform Enterprise workspace for runs executed in that environment.
- You can often reproduce this issue locally by unsetting or disabling your local proxy configuration.
Solution
Configure Proxy Settings in the Terraform Enterprise Workspace
Ensure that your proxy settings are correctly configured in the environment variables for the relevant Terraform Enterprise workspace.
- Navigate to the workspace experiencing the error.
- Go to the Variables tab.
- Add or update the necessary proxy environment variables, such as
HTTP_PROXY,HTTPS_PROXY, andNO_PROXY. - Ensure the variables are marked as Environment variables and not Terraform variables.