# Provider config inside child module

**URL:** <https://discuss.hashicorp.com/t/provider-config-inside-child-module/44078>\
**Category:** Kubernetes\
**Created:** [September 8, 2022, 5:27am UTC](https://discuss.hashicorp.com/t/provider-config-inside-child-module/44078 "2022-09-08T05:27:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrlnstpn](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/mrlnstpn/32/30559_2.png) [@mrlnstpn](https://discuss.hashicorp.com/u/mrlnstpn)\
**Post date:** [September 8, 2022, 5:27am UTC](https://discuss.hashicorp.com/t/provider-config-inside-child-module/44078/1 "2022-09-08T05:27:48Z")

</div>

I’m trying to create modules that will handle helm deployments. the structure goes like this

root module

- call helm-traefik module
- there’s an input (cluster name) that will be used to fetch data sources for the provider config inside the helm child module.

child module - helm-traefik

- main tf. - call helm module
- variables.tf
- values.yaml

child module - helm

- providers.tf - both provider config for kubernetes and helm are using kubelogin for authentication
- datasources.tf
- main.tf - helm\_release
- variables.tf

The issue is that I’m getting an error with tf plan and it says that Kubernetes cluster is unreachable. I’ve been reading docs regarding providers and I think the reason why I’m getting errors is that I don’t have the provider config for Kubernetes and helm in the root module level. Any feasible solution for this use case? I want to have a separation between the helm module in a way it can be consumed regardless of the helm chart to be deployed.

---

<div class="post-metadata">

**Author:** ![mrlnstpn](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/mrlnstpn/32/30559_2.png) [@mrlnstpn](https://discuss.hashicorp.com/u/mrlnstpn)\
**Post date:** [September 9, 2022, 5:39am UTC](https://discuss.hashicorp.com/t/provider-config-inside-child-module/44078/2 "2022-09-09T05:39:14Z")

</div>

Also, If I put the provider config from the child module to the root module, that would mean I need to create a provider config for each cluster I want to manage.

on helm - child module, this is how I generate the provider config

datasources.tf

```auto
locals {
  # The purpose of the cluster.
  purpose = split("-", "${var.cluster_name}")[0]
  # The network environment of the cluster.
  customer_env = split("-", "${var.cluster_name}")[2]
}

data "azurerm_kubernetes_cluster" "cluster" {
  resource_group_name = "rg-${local.purpose}-${local.customer_env}-001"
  name = "aks-${local.purpose}-${local.customer_env}"
}

```

provider.tf

```auto
provider "kubernetes" {
  host = data.azurerm_kubernetes_cluster.cluster.kube_config.0.host
  cluster_ca_certificate = base64decode(data.azurerm_kubernetes_cluster.cluster.kube_config.0.cluster_ca_certificate)
  exec {
    api_version = "client.authentication.k8s.io/v1beta1"
    command = "kubelogin"
    args = [
      "get-token",
      "--login", "spn",
      "--environment", "AzurePublicCloud",
      "--server-id", "6dae42f8-4368-4678-94ff-3960e28e3630",
      "--tenant-id", data.azurerm_client_config.current.tenant_id,
      "--client-id", data.azurerm_client_config.current.client_id,
      "--client-secret", data.azurerm_key_vault_secret.service_principal_key.value,
    ]
  }
}

```
