Hi,
I have my own terraform module which create an eks cluster as documented here plus a couple of services on top of k8s in form of helm releases using the helm provider.
After some day since the cluster was created successfully I added some output to the code and tried to apply again but got the error:
Error: Kubernetes cluster unreachable: invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable
I read here this statement from tf doc:
WARNING
When using interpolation to pass credentials to the Kubernetes provider from other resources, these resources SHOULD NOT be created in the same Terraform module where Kubernetes provider resources are also used . This will lead to intermittent and unpredictable errors which are hard to debug and diagnose. The root issue lies with the order in which Terraform itself evaluates the provider blocks vs. actual resources. Please refer to this section of Terraform docs for further explanation.
I would like to know if it is sufficient to reorganize the code in this way:
module "infra" {
source = "./modules/infra"
...
}
module "services" {
source = "./modules/services"
... (using outputs from module above)
}
the first module ouputs the eks params which are in turn passed to 2nd module and used for configuring its kubernetes and helm providers.
Is this a right way to operate or I am forced to use 2 separated projects, which 2 sperated runs and tfstates?
Thanks in advance,
Fabio