terraform-provider-kubernetes icon indicating copy to clipboard operation
terraform-provider-kubernetes copied to clipboard

Cycle dependency in Kubernetes provider when referencing to the gke module via a local variable

Open gioannidis opened this issue 8 months ago • 0 comments

Introduction

Terraform detects a cycle change when creating the provider "kubernetes" when referencing to the terraform-provider-kubernetes module indirectly via a local variable.

I am illustrating below a very simple broken example and a working example to compare it with.

Terraform Version, Provider Version and Kubernetes Version

$ terraform -v
Terraform v1.11.2
on linux_amd64
+ provider registry.terraform.io/hashicorp/google v6.26.0
+ provider registry.terraform.io/hashicorp/kubernetes v2.36.0
+ provider registry.terraform.io/hashicorp/random v3.7.1

Affected Resource(s)

  • provider registry.terraform.io/hashicorp/kubernetes

Terraform Configuration Files

Broken example

# main.tf
# Example of a broken configuration, where `terraform validate` detects
# a cycle dependency.

module "gke" {
  source  = "terraform-google-modules/kubernetes-engine/google"
  version = ">= 36.0.0"
  name    = "broken"

  ip_range_services = null
  ip_range_pods     = null
  project_id        = null
  network           = null
  subnetwork        = null
}

locals {
  gke = module.gke
}

provider "kubernetes" {
  host = "https://${local.gke.endpoint}"
}

Working example

The only change versus the previous example is replacing local.gke -> module.gke. This is sufficient for terraform validate to succeed.

# main.tf
# Example where `terraform validate` succeeds.

module "gke" {
  source  = "terraform-google-modules/kubernetes-engine/google"
  version = ">= 36.0.0"
  name    = "working"

  ip_range_services = null
  ip_range_pods     = null
  project_id        = null
  network           = null
  subnetwork        = null
}

provider "kubernetes" {
  host = "https://${module.gke.endpoint}"
}

Debug Output

https://gist.github.com/gioannidis/c541bb41c34b18a7aeb15b9498abfbd5

Steps to Reproduce

  1. Copy the broken example to your main.tf file.
  2. Execute terraform init.
  3. Execute terraform validate.

Expected Behavior

terraform validate should output: Success! The configuration is valid.

Actual Behavior

Terraform detects a cycle dependency.

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

gioannidis avatar Mar 21 '25 17:03 gioannidis