<p>We're using Terraform to deploy AKS clusters to an environment behind a proxy over VPN. Deployment of the cluster works correctly when off-network without the proxy, but errors out on Helm deployment creation on-network.</p>
<p>We are able to connect to the cluster after it's up while on the network using the following command after retrieving the cluster context.</p>
<pre><code>kubectl config set-cluster &lt;cluster name&gt; --certificate-authority=&lt;path to organization's root certificate in PEM format&gt;
</code></pre>
<p>The Helm deployments are also created with Terraform after the creation of the cluster. It seems that these require the <code>certificate-authority</code> data to deploy and we haven't been able to find a way to automate this at the right step in the process. Consequently, the <code>apply</code> fails with the error:</p>
<blockquote>
<p>x509: certificate signed by unknown authority</p>
</blockquote>
<p>Any idea how we can get the <code>certificate-authority</code> data in the right place so the Helm deployments stop failing? Or is there a way to get the cluster to implicitly trust that root certificate? We've tried a few different things:</p>
<ol>
<li><p>Researched if you could automatically have that data in there when retrieving the cluster context (i.e. <code>az aks get-credentials --name &lt;cluster name&gt; --resource-group &lt;cluster RG&gt;</code>)?** Couldn't find an easy way to accomplish this.</p>
</li>
<li><p>We started to consider adding the root cert info as part of the kubeconfig that's generated during deployment (rather than the one you create when retrieving the context). The idea is that it can be passed in to the kubernetes/helm providers and also leveraged when running <code>kubectl</code> commands via local-exec blocks. We know that works but that means that we couldn't find a way to automate that via Terraform.</p>
</li>
<li><p>We've tried providing the root certificate to the different fields of the provider config, shown below. We've specifically tried a few different things with <code>cluster_ca_certificate</code>, namely providing the PEM-style cert of the root CA.</p>
</li>
</ol>
<pre><code>    provider &quot;kubernetes&quot; {
      host                   = module.aks.kube_config.0.host
      client_certificate     = base64decode(module.aks.kube_config.0.client_certificate)
      client_key             = base64decode(module.aks.kube_config.0.client_key)
      cluster_ca_certificate = base64decode(module.aks.kube_config.0.cluster_ca_certificate)
    }
    
    provider &quot;helm&quot; {
      version = &quot;&gt;= 1.2.4&quot;
      kubernetes {
        host                   = module.aks.kube_config.0.host
        client_certificate     = base64decode(module.aks.kube_config.0.client_certificate)
        client_key             = base64decode(module.aks.kube_config.0.client_key)
        cluster_ca_certificate = base64decode(module.aks.kube_config.0.cluster_ca_certificate)
      }
    }
</code></pre>
<p>Thanks in advance for the help! Let me know if you need any additional info. I'm still new to the project so I may not have explained everything correctly.</p>

Jon
<p>In case anyone finds this later, we ultimately ended up just breaking the project up into two parts: cluster creation and bootstrap. This let us add a <code>local-exec</code> block in the middle to run the <code>kubectl config set-cluster...</code> command. So the order of operations is now:</p>
<ol>
<li>Deploy AKS cluster (which copies Kube config locally as one of the Terraform outputs)</li>
<li>Run the command</li>
<li>Deploy microservices</li>
</ol>
<p>Because we're using Terragrunt, we can just use its <code>apply-all</code> function to execute both operations, setting the dependencies described <a href="https://terragrunt.gruntwork.io/docs/features/execute-terraform-commands-on-multiple-modules-at-once/#dependencies-between-modules" rel="nofollow noreferrer">here</a>.</p>
