You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(kubernetes): implement Read + Importer for all 17 stub K8s resources
All 17 Kubernetes resources previously had stub Read functions (`return nil`)
and no Importer block, making them invisible to drift detection and blocking
`terraform import` entirely.
Changes:
- Added `Importer: &schema.ResourceImporter{StateContext: schema.ImportStatePassthroughContext}` to all 17 resources
- Replaced every `return nil` stub with a real context-based Read using `diag.Diagnostics`
- Added `internal/resource_kubernetes_common.go` with `k8sConfirmExistsByGET` — a shared helper used by the 13 manifest-based resources that issues a GET, handles 404 by clearing the ID, and avoids refreshing the manifest field (K8s server-expands objects, so re-reading would cause permanent diffs)
- `portainer_kubernetes_helm`: upgraded from existence-check to full Read; recovers `chart` and `repo` from `chartReference.{chartPath,repoURL}` in the release-detail response, eliminating the ForceNew destroy+recreate that would otherwise trigger after `terraform import`
- `portainer_kubernetes_namespace`: guards `owner` and `resource_quota` with nil checks so environments with EnableResourceOverCommit or a missing NamespaceOwner field don't generate permanent drift
- `portainer_kubernetes_namespace_system`: reads `IsSystem` from the namespace API and stores it
- All Read implementations follow the context-aware `diag.Diagnostics` pattern introduced in the recent provider refactor
Tested end-to-end on a live Portainer/k0s environment:
terraform apply → 17/17 created
rm terraform.tfstate → state dropped (brownfield simulation)
terraform import (×17) → 17/17 "Import successful!"
terraform apply → 15 in-place reconciliation updates (idempotent re-POST of manifests; no resources destroyed)
terraform plan → No changes.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
0 commit comments