Terraform Kubernetes provider not available to get data from ressource provisioned

2/17/2022

I'm trying to use the Kubernetes Terraform provider. Everytime I try to create a resource with helm provider and get data from this with Kubernetes provider, I'm not able to make it working within the same script as the kubernetes data isn't created (and no dependency detected between provider) at the launch time.

For example in the same script I'd like to do the following :

#define de required provider
terraform {
  required_providers {
    kubernetes = {
      source = "hashicorp/kubernetes"
      version = "2.7.1"
    }
  }
}
    
provider "kubernetes" {
   host = var.host
   token = var.token
   insecure = true
}

#define the helm provider
provider "helm" {
  kubernetes {
    host = var.host
    token = var.token
    insecure = true
  }
}


#deploy grafana chart, as example app
resource "helm_release" "grafana" {
  name       = "grafana"
  namespace  = "grafana"

  repository = "https://grafana.github.io/helm-charts"
  chart      = "grafana"

  values = [
    templatefile("${path.module}/grafana-values.tftpl", {
        grafana_username = var.grafana_username,
        grafana_password = var.grafana_password}
    )
  ]
}

data "kubernetes_service" "grafana" {
  metadata {
    name = "grafana"
    namespace = "grafana"
  }
}

output "service_ip"{
    value = data.kubernetes_service.grafana.status[0].load_balancer[0].ingress[0].ip
    depends_on = [data.kubernetes_service.grafana]
}

It looks it's not possible to create Kubernetes ressource from a different provider than kubernetes? Or am I doing something wrong?

If I run this a second time one the helm chart is already deployed, then the output will be correct.

-- Fab
kubernetes
provider
terraform

0 Answers