<p>I'm trying to create some reusable Terraform modules that provision Kubernetes resources on a cluster. My modules do not explicitly configure a Kubernetes provider, expecting that a configured one will be created by the "root" module. I believe this is in line with <a href="https://www.terraform.io/docs/configuration/modules.html" rel="nofollow noreferrer">Terraform best practices</a>.</p>

<p>If the root module "forgets" to provide a configured Kubernetes provider, though, it appears that Terraform will provide one by default, and with the default behaviour of using whatever context may currently be configured in the executing user's <code>kubeconfig</code>. If the user is not paying attention, they may inadvertently end up modifying resources on the wrong cluster.</p>

<p>Is there a way to prevent this behaviour and effectively say "you <em>must</em> explicitly pass in a provider for this module to use"?</p>

AwesomeTown
<p>The best option I've come up with is to create a Kubernetes provider in the module like:</p>

<pre><code># Prevents this module from loading a default context from local kubeconfig when calling module forgets to define a Kubernetes provider
provider "kubernetes" {
  load_config_file = false
}
</code></pre>

<p>Then, as long as the calling module provides a different instance, eg:</p>

<pre><code>provider "kubernetes" {
  # properly configure stuff here
}

module "my-module" {
  source              = "blah"
  providers = {
    kubernetes = kubernetes
  }
  etc.
}
</code></pre>

<p>you can avoid accidentally using the default provider.</p>

<p>This is fine, but a little non-obvious until you're used to the pattern.</p>
