Skip to content

Kustomize Provider Attempting to Patch Resources During Terraform Plan #261

@tajpouria

Description

@tajpouria

During terraform plan, the kustomize provider is attempting to execute patch operations against the live Kubernetes cluster instead of just building a diff for planning purposes. This causes permission errors when running terraform with restricted credentials.

Error Message

time=2025-03-13T09:26:34Z level=info msg=╷
Error: github.com/kbst/terraform-provider-kustomize/kustomize.kustomizationResourceDiff: configmaps "config" is forbidden: User "user-read:plan" cannot patch resource "configmaps" in API group "" in the namespace "service-namespace"

with module.resources.kustomization_resource.service_p1["_/ConfigMap/service-namespace/config"],
on service.tf line 234, in resource "kustomization_resource" "service_p1":
234: resource "kustomization_resource" "service_p1" {

Expected Behavior

The terraform plan operation should only calculate the diff between local and remote state without performing any modification operations against the cluster. The plan user shouldn't need write permissions for resources.

Current Behavior

The kustomize provider is attempting to patch resources during plan phase, which requires write permissions to the resources, even though the plan operation should be read-only.

Additional Context

The issue involves RBAC setup where planning uses read-only credentials (user-read user), while apply operations use elevated permissions. The current behavior prevents following this security practice.

Affected Code

resource "kustomization_resource" "service" {
  depends_on = [kustomization_resource.service_p0]
  for_each   = data.kustomization_overlay.service.ids_prio[1]
  manifest   = data.kustomization_overlay.service.manifests[each.value]

  # Wait for deployments to update
  wait = true
  timeouts {
    create = "10m"
    update = "10m"
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions