<p>I am creating a kubernetes cluster with the Azure Terraform provider and trying to add a secret to it. The cluster gets created fine but I am getting errors with authenticating to the cluster when creating the secret.  I tried 2 different Terraform Kubernetes provider configurations.  Here is the main configuration:</p>
<pre><code>variable &quot;client_id&quot; {}
variable &quot;client_secret&quot; {}

resource &quot;azurerm_resource_group&quot; &quot;rg-example&quot; {
  name     = &quot;rg-example&quot;
  location = &quot;East US&quot;
}

resource &quot;azurerm_kubernetes_cluster&quot; &quot;k8s-example&quot; {
  name                = &quot;k8s-example&quot;
  location            = azurerm_resource_group.rg-example.location
  resource_group_name = azurerm_resource_group.rg-example.name
  dns_prefix          = &quot;k8s-example&quot;

  default_node_pool {
    name            = &quot;default&quot;
    node_count      = 1
    vm_size         = &quot;Standard_B2s&quot;
  }

  service_principal {
    client_id     = var.client_id
    client_secret = var.client_secret
  }

  role_based_access_control {
    enabled = true
  }
}

resource &quot;kubernetes_secret&quot; &quot;secret_example&quot; {
  metadata {
    name = &quot;mysecret&quot;
  }
  data = {
    &quot;something&quot; = &quot;super secret&quot;
  }
  depends_on = [
    azurerm_kubernetes_cluster.k8s-example
  ]
}

provider &quot;azurerm&quot; {
  version = &quot;=2.29.0&quot;
  features {}
}

output &quot;host&quot; {
  value = azurerm_kubernetes_cluster.k8s-example.kube_config.0.host
}
output &quot;cluster_username&quot; {
  value = azurerm_kubernetes_cluster.k8s-example.kube_config.0.username
}
output &quot;cluster_password&quot; {
  value = azurerm_kubernetes_cluster.k8s-example.kube_config.0.password
}
output &quot;client_key&quot; {
  value = azurerm_kubernetes_cluster.k8s-example.kube_config.0.client_key
}
output &quot;client_certificate&quot; {
  value = azurerm_kubernetes_cluster.k8s-example.kube_config.0.client_certificate
}
output &quot;cluster_ca_certificate&quot; {
  value = azurerm_kubernetes_cluster.k8s-example.kube_config.0.cluster_ca_certificate
}
</code></pre>
<p><strong>Here is the first Kubernetes provider configuration using certificates:</strong></p>
<pre><code>provider &quot;kubernetes&quot; {
  version = &quot;=1.13.2&quot;
  load_config_file = &quot;false&quot;

  host = azurerm_kubernetes_cluster.k8s-example.kube_config.0.host
  
  client_certificate     = azurerm_kubernetes_cluster.k8s-example.kube_config.0.client_certificate
  client_key             = azurerm_kubernetes_cluster.k8s-example.kube_config.0.client_key
  cluster_ca_certificate = azurerm_kubernetes_cluster.k8s-example.kube_config.0.cluster_ca_certificate
}
</code></pre>
<p><strong>And the error I'm receiving:</strong></p>
<pre><code>kubernetes_secret.secret_example: Creating...

Error: Failed to configure client: tls: failed to find any PEM data in certificate input
</code></pre>
<p><strong>Here is the second Kubernetes provider configuration using HTTP Basic Authorization:</strong></p>
<pre><code>provider &quot;kubernetes&quot; {
  version = &quot;=1.13.2&quot;
  load_config_file = &quot;false&quot;

  host = azurerm_kubernetes_cluster.k8s-example.kube_config.0.host
  
  username = azurerm_kubernetes_cluster.k8s-example.kube_config.0.username
  password = azurerm_kubernetes_cluster.k8s-example.kube_config.0.password
}
</code></pre>
<p><strong>And the error I'm receiving:</strong></p>
<pre><code>kubernetes_secret.secret_example: Creating...

Error: Post &quot;https://k8s-example-c4a78c03.hcp.eastus.azmk8s.io:443/api/v1/namespaces/default/secrets&quot;: x509: certificate signed by unknown authority
</code></pre>
<p><strong>ANALYSIS</strong></p>
<p>I checked the outputs of azurerm_kubernetes_cluster.k8s-example and the data seems valid (username, password, host, etc..)  Maybe I need a SSL certificate on my Kubernetes cluster, however I'm am not certain, as I'm new to this.  Can someone help me out ?</p>

<p>According to <a href="https://github.com/hashicorp/terraform-provider-kubernetes/issues/85" rel="nofollow noreferrer">this issue in hashicorp/terraform-provider-kubernetes</a>, you need to use <code>base64decode()</code>. The example that author used:</p>
<pre><code>provider &quot;kubernetes&quot; {
  host = &quot;${google_container_cluster.k8sexample.endpoint}&quot;
  username = &quot;${var.master_username}&quot;
  password = &quot;${var.master_password}&quot;
  client_certificate = &quot;${base64decode(google_container_cluster.k8sexample.master_auth.0.client_certificate)}&quot;
  client_key = &quot;${base64decode(google_container_cluster.k8sexample.master_auth.0.client_key)}&quot;
  cluster_ca_certificate = &quot;${base64decode(google_container_cluster.k8sexample.master_auth.0.cluster_ca_certificate)}&quot;
}
</code></pre>
<p>That author said they got the same error as you if they left out the base64decode. You can read more about that function here: <a href="https://www.terraform.io/docs/configuration/functions/base64decode.html" rel="nofollow noreferrer">https://www.terraform.io/docs/configuration/functions/base64decode.html</a></p>
