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

Importing StatefulSet forces recreation

Open abby-gourlay opened this issue 8 months ago • 0 comments

Hi there,

We're having issues importing StatefulSets into our terraform from our EKS cluster. When we are importing StatefulSets which were previously deployed with YAML, terraform states that it'll update the volume_claim_template namespace attribute (even though it's not specified in the terraform config file) which then shows that updating that field forces recreation. Viewing the full YAML output from the cluster doesn't show this attribute on any of our deployed statefulsets

Terraform Version, Provider Version and Kubernetes Version

Terraform version: v1.11.2
Kubernetes provider version: v2.36.0
Kubernetes version: v1.31.6-eks-bc803b4

Affected Resource(s)

  • kubernetes_stateful_set_v1
  • kubernetes_stateful_set

Terraform Configuration Files

provider "kubernetes" {
  config_path = "~/.kube/config"
  config_context = "devops-poc"
}

resource "kubernetes_stateful_set_v1" "testapp" {
  metadata {
    name = "testapp"
  }

  spec {
    replicas = 1

    selector {
      match_labels = {
        app = "testapp"
      }
    }

    template {
      metadata {
        labels = {
          app = "testapp"
        }
      }

      spec {
        container {
          name  = "testapp"
          image = "registry.k8s.io/nginx-slim:0.8"

          port {
            name           = "web"
            container_port = 80
          }

          volume_mount {
            name       = "www"
            mount_path = "/usr/share/nginx/html"
          }
        }
      }
    }

    volume_claim_template {
      metadata {
        name = "www"
      }

      spec {
        access_modes = ["ReadWriteOnce"]

        resources {
          requests = {
            storage = "1Gi"
          }
        }
      }
    }

    service_name = "testapp"
  }
}

This is the YAML file that was used to create this test app https://gist.github.com/abby-gourlay/55210c739348d4efe61af83b687f3a74

Debug Output

https://gist.github.com/abby-gourlay/5d3f28735c152f0325eefa71ee67ffe4

Steps to Reproduce

1, Create stateful set using kubectl 2. Import stateful set into terraform 3. Run terraform plan

Expected Behavior

Terraform shows changes from default value changes, but doesn't force recreation

Actual Behavior

Terraform shows that it needs to add the namespace attribute to the volume_claim_template, which then forces recreation of the statefulset

Image

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

abby-gourlay avatar Mar 25 '25 20:03 abby-gourlay