I’m working on a private reusable module that creates a bunch of Kubernetes resources The company has multiple kubernetes clusters and people often have more than one configured in their kubeconfig, switching contexts as they need.
This creates a problem with implicit provider configuration passing: if the person using my module forgets to pass a providers argument to my module, and for any possible reason has a kubernetes provider configured in the top module that does not match the cluster where these resources need to be, it may happen that terraform will try to create resources in the wrong cluster.
I understand this is a user error, but I’d like to mitigate it by forcing the user to pass an explicit provider configuration for the kubernetes provider, but could not find a way to do it. Is it at all possible? Maybe some kind of workaround exists?
Alternative provider configurations (that is, those with aliases) never automatically inherit since the namespace for them is separate for each module, so declaring one will effectively force the caller to always specify a configuration, though as noted in this example it will require specifying some specific alias rather than just assigning a default (unaliased) configuration for the provider.
I would suggest choosing an alias name that somehow represents what the module will use the provider configuration for, so that the providers = { ... } declaration in the calling block will hopefully be clearer to a future reader who might not yet be familiar with the details of the module being called.