Answers: <p>If you read the <a href="https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/manifest" rel="nofollow noreferrer">docs for the resource <code>kubernetes_manifest</code></a> you'll see it says the following,</p>
  <blockquote>
  <p>This resource requires API access during planning time. <strong>This means the cluster has to be accessible at plan time and thus cannot be created in the same apply operation.</strong> We recommend only using this resource for custom resources or resources not yet fully supported by the provider.</p>
  </blockquote>
  <p>This was my problem. You can't create the resource in the same terraform files that use the <code>kubernetes_manifest</code> on. And the reason why, for me, only I was getting this error is because the shared state was in GitLab and it wasn't being pulled down.</p>
  
Answers: CC BY-SA 4.0
Answers: 2023-04-05T07:09:20.320Z
Answers: 2023-04-05T15:43:53.197Z
Answers: 2023-04-05T15:43:53.197Z
Answers: Evan Carroll
Answers: <p>The error means that you are not authenticating to the K8s cluster for some reason.</p>
  <p>Take a look here:</p>
  <p><a href="https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs#example-usage" rel="nofollow noreferrer">https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs#example-usage</a></p>
  <p>For better troubleshooting, I recommend enabling auditing on the K8s cluster, so you can see what went wrong.</p>
  <p><a href="https://kubernetes.io/docs/tasks/debug/debug-cluster/audit/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/debug/debug-cluster/audit/</a></p>
  
Answers: CC BY-SA 4.0
Answers: 2023-04-05T07:12:37.490Z
Answers: I couldn't find out anything looking at the logs, but i did update with the answer that solved it. Thanks for trying to help though.'
Answers: Evan Carroll
Answers: CC BY-SA 4.0
Answers: 2023-04-04T16:11:04.510Z
Answers: 2023-04-04T16:11:04.510Z
Answers: glv
Body: <p>Getting the following error with Terraform</p>
  <blockquote>
  <p>forbidden: User &quot;system:anonymous&quot; cannot get path &quot;/apis&quot;</p>
  </blockquote>
  <p>In context,</p>
  <pre><code>│ Error: Invalid configuration for API client
  │ 
  │   with acme.dev_env_02.kubernetes_manifest.grafana-agent,
  │   on modules/acme-02/prometheus.tf line 1, in resource &quot;kubernetes_manifest&quot; &quot;grafana-agent&quot;:
  │    1: resource &quot;kubernetes_manifest&quot; &quot;grafana-agent&quot; {
  │ 
  │ forbidden: User &quot;system:anonymous&quot; cannot get path &quot;/apis&quot;
  </code></pre>
  <p>I'm also getting this error with,</p>
  <pre><code>resource &quot;kubernetes_manifest&quot; &quot;seccomp&quot; {
  </code></pre>
  
Tags: <kubernetes><terraform><gcloud>
Title: Terraform kubernetes_manifest: forbidden: User "system:anonymous" cannot get path "/apis"
UserDisplayName: Evan Carroll
ThreadText: # Terraform kubernetes_manifest: forbidden: User "system:anonymous" cannot get path "/apis"
  
  (Asked by: username_0 on 2023-04-03)
  
  Getting the following error with Terraform
  
  > forbidden: User "system:anonymous" cannot get path "/apis"
  
  In context,
  
  ```
  │ Error: Invalid configuration for API client
  │ 
  │   with acme.dev_env_02.kubernetes_manifest.grafana-agent,
  │   on modules/acme-02/prometheus.tf line 1, in resource "kubernetes_manifest" "grafana-agent":
  │    1: resource "kubernetes_manifest" "grafana-agent" {
  │ 
  │ forbidden: User "system:anonymous" cannot get path "/apis"
  
  ```
  
  I'm also getting this error with,
  
  ```
  resource "kubernetes_manifest" "seccomp" {
  
  ```
  
  **Tags:** kubernetes, terraform, gcloud
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2023-04-05. Score: 0 | Accepted answer
  
  If you read the [docs for the resource `kubernetes_manifest`](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/manifest) you'll see it says the following,
  
  > This resource requires API access during planning time. **This means the cluster has to be accessible at plan time and thus cannot be created in the same apply operation.** We recommend only using this resource for custom resources or resources not yet fully supported by the provider.
  
  This was my problem. You can't create the resource in the same terraform files that use the `kubernetes_manifest` on. And the reason why, for me, only I was getting this error is because the shared state was in GitLab and it wasn't being pulled down.
  
  
  ---
  
  ### Answer by username_1 on 2023-04-04. Score: 1
  
  The error means that you are not authenticating to the K8s cluster for some reason.
  
  Take a look here:
  
  <https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs#example-usage>
  
  For better troubleshooting, I recommend enabling auditing on the K8s cluster, so you can see what went wrong.
  
  <https://kubernetes.io/docs/tasks/debug/debug-cluster/audit/>
  
  > **Comments:**
  > **username_0**: I couldn't find out anything looking at the logs, but i did update with the answer that solved it. Thanks for trying to help though.'  
  
  ---
  
  