github hashicorp/terraform-provider-kubernetes v4.0.0-beta1

pre-releaseone hour ago

4.0.0-beta1 (Dec 03, 2026)

BREAKING CHANGES:

  • Back up state before upgrading to 4.0. All 14 managed resources listed in the v4 upgrade guide write a newer state schema, including Services, PersistentVolumes, and PersistentVolumeClaims. Once 4.0 saves any of those instances, rolling back to 3.x requires restoring the pre-upgrade state backup; pinning 3.x alone is not enough. [GH-3017]
  • resource/kubernetes_deployment_v1, resource/kubernetes_daemon_set_v1, resource/kubernetes_stateful_set_v1, resource/kubernetes_pod_v1, resource/kubernetes_job_v1, resource/kubernetes_cron_job_v1: Migrate to the Terraform Plugin Framework. Container and init container resources, Deployment and DaemonSet strategy and its rolling_update, StatefulSet persistent_volume_claim_retention_policy and Job and CronJob selector change from blocks to object arguments, for example resources = { ... }, so references and ignore_changes paths drop their [0]. Pod spec image_pull_secrets and readiness_gate and Job and CronJob selector.match_expressions become lists of objects. See the v4 upgrade guide. [GH-3017]
  • resource/kubernetes_horizontal_pod_autoscaler_v2: An omitted behavior is no longer sent as an empty object, and an omitted stabilization_window_seconds is no longer sent as 0, so Kubernetes applies its own defaults. New autoscalers without stabilization_window_seconds use a 300 second scale-down window instead of 0. Existing autoscalers keep their current values. [GH-3050]
  • resource/kubernetes_horizontal_pod_autoscaler_v2: spec.metric and spec.behavior change from blocks to arguments, for example metric = [{ ... }] and behavior = { ... }. Inside them, the metric sources, target, described_object, the metric identifier, selector, scale_up and scale_down become objects; policy and match_expressions become lists of objects. Drop [0] from references and ignore_changes paths only where a block became a single object. [GH-3050]
  • resource/kubernetes_horizontal_pod_autoscaler_v2beta2: Removed. Use kubernetes_horizontal_pod_autoscaler_v2 and update any metric and behavior blocks to the v4 argument syntax. With Terraform 1.8 or later, include a moved block from the removed type to keep the existing autoscaler. [GH-3042]
  • resource/kubernetes_ingress_v1, resource/kubernetes_ingress_class_v1, resource/kubernetes_network_policy_v1: Selected singleton backends, HTTP rules, parameters, selectors, and IP blocks now use object arguments (field = { ... }) instead of blocks. Ingress HTTP paths and selector match expressions remain repeated values and now use list-of-object arguments. Update only the converted object indexes in references and lifecycle paths. Metadata/spec and other repeated blocks retain their syntax. IngressClass state containing multiple historical parameters blocks is rejected; consolidate to the one active parameters object and refresh with the previous provider before upgrading. Follow each resource's migration guide and preserve absent versus empty selectors. [GH-2994]
  • resource/kubernetes_persistent_volume_v1, resource/kubernetes_persistent_volume_claim_v1: Null entries in metadata.labels or metadata.annotations are now rejected. Remove those entries or supply a string value. [GH-3061]
  • resource/kubernetes_persistent_volume_v1: spec.claim_ref changes from a block to an object argument, claim_ref = { ... }, so references and ignore_changes paths drop its [0]. spec accepts exactly one block. See the resource's upgrade section. [GH-3061]
  • resource/kubernetes_pod_disruption_budget_v1: Change spec.selector to a required object (selector = { ... }) and match_expressions to a list of objects. Remove the selector's [0] from references and lifecycle paths. See the resource upgrade guide for module, conditional and Terraform JSON examples. [GH-2995]
  • resource/kubernetes_pod_v1, resource/kubernetes_job_v1: Review replacement plans before applying. Changing a Pod spec replaces the Pod, except when setting or lowering active_deadline_seconds, which updates it in place. Changing a Job's Pod template or pod_failure_policy replaces the Job. [GH-3017]
  • resource/kubernetes_service_v1: session_affinity_config and its nested client_ip now use object assignment syntax instead of blocks. Remove the two affinity [0] indexes from references and lifecycle paths. API-allocation markers (node_port = 0 when allocation is enabled, empty/zero target_port, and empty cluster_ips/ip_families for non-ExternalName Services) are rejected; omit these arguments or use null instead. [GH-2992]

FEATURES:

  • New action: kubernetes_job_run. Runs a Job once, from the job template of a CronJob or from a manifest, and waits for it to complete. [GH-3064]
  • New action: kubernetes_manifest_create. Creates one object of any kind from its manifest, such as the request object an operator acts on, and can wait for the outcome the object reports. [GH-3064]
  • New action: kubernetes_rollout_restart. Restarts the pods of a Deployment, StatefulSet or DaemonSet as kubectl rollout restart does and waits for the rollout, for example when a ConfigMap or Secret they read changes. Actions need Terraform 1.14 or later. [GH-3064]
  • New actions: kubernetes_node_cordon, kubernetes_node_drain and kubernetes_node_uncordon, for one node or the nodes a label selector matches. Cordon makes the nodes unschedulable, drain also evicts their pods as kubectl drain does, and uncordon makes them schedulable again. [GH-3064]
  • New ephemeral resource: kubernetes_secret_v1. Reads a Secret without storing its values in the Terraform plan or state. [GH-3054]
  • New function: manifest_decode_map. Decodes multi-document YAML into a map keyed by Kind[.group]/[namespace/]name, a stable for_each key for one resource instance per object. [GH-3054]
  • New resource: kubernetes_manifest_patch. Applies fields of an object that something else creates and manages, such as a cluster add-on or an operator, with server-side apply under its own field manager, and keeps them set. It never creates or deletes the object: destroying it gives up the fields, or removes them with destroy_behavior = "remove_fields". [GH-3058]
  • New resource: kubernetes_manifest_v2, the successor of kubernetes_manifest. It uses server-side apply for HCL or YAML manifests. Planning a new object does not require its kind to exist: a CustomResourceDefinition and its custom resources can be created in one apply when the custom resources depend on the definition. Terraform 1.8+ supports moved blocks from kubernetes_manifest or from another provider's kubectl_manifest. [GH-3054]
  • kubernetes_gateway_class_v1: Add a new data source for reading a Gateway API v1 GatewayClass. [GH-3051]
  • kubernetes_gateway_v1: Add a new data source for reading a Gateway API v1 Gateway. [GH-3065]
  • kubernetes_http_route_v1: Add a new data source for reading a Gateway API v1 HTTPRoute. [GH-3065]
  • kubernetes_reference_grant_v1: Add a new data source for reading a Gateway API v1 ReferenceGrant. [GH-3066]
  • kubernetes_gateway_class_v1: Add a new resource for managing a Gateway API v1 GatewayClass. [GH-3051]
  • kubernetes_gateway_v1: Add a new resource for managing a Gateway API v1 Gateway. [GH-3065]
  • kubernetes_http_route_v1: Add a new resource for managing a Gateway API v1 HTTPRoute. [GH-3065]
  • kubernetes_reference_grant_v1: Add a new resource for managing a Gateway API v1 ReferenceGrant. [GH-3066]

ENHANCEMENTS:

  • Workload Pod specs: Add Linux user namespaces (host_users), proc_mount, AppArmor profiles, Windows security options, and supplemental group and SELinux policies. proc_mount = "Unmasked" requires host_users = false and a cluster that supports it. [GH-3017]
  • Workload Pod specs: Add Pod-level resources, Dynamic Resource Allocation claims (resource_claims and container resources.claims), container resize_policy, restart_policy_rules, and OnFailure and Never restart policies on supported clusters. [GH-3017]
  • Workload Pod specs: Add set_hostname_as_fqdn, hostname_override, affinity label keys, probe termination grace periods, lifecycle sleep, TCP probe host, and env.value_from.file_key_ref. See the Pod feature guide for Kubernetes version requirements. [GH-3017]
  • Workload Pod specs: Mount OCI images with volume.image, project cluster_trust_bundle and pod_certificate sources, and set recursive read-only mounts or volume_attributes_class_name in ephemeral volume claim templates. Availability depends on cluster and node support. [GH-3017]
  • resource/kubernetes_ingress_v1, resource/kubernetes_ingress_class_v1, resource/kubernetes_network_policy_v1: Existing versioned resources upgrade at the same address without re-import. Terraform 1.8+ also supports moved blocks from kubernetes_ingress_class and kubernetes_network_policy to their _v1 types. The v1beta1 kubernetes_ingress type cannot move to kubernetes_ingress_v1 this way. [GH-2994]
  • resource/kubernetes_job_v1, resource/kubernetes_cron_job_v1: Add Job suspend, success_policy, pod_replacement_policy, and managed_by. A suspended standalone Job skips waiting for completion. [GH-3017]
  • resource/kubernetes_persistent_volume_v1, resource/kubernetes_persistent_volume_claim_v1: Migrate to the Terraform Plugin Framework. Resource type names, import IDs and existing state are kept, and kubernetes_persistent_volume_claim_v1 keeps its configuration syntax. Explicitly empty values that 3.x stored as null, such as labels = {} or mount_options = [], and a node_affinity that is set in Kubernetes but not in the configuration, can show a one-time in-place update that changes only Terraform state. With Terraform 1.8 or later, moved blocks can move resources from the deprecated kubernetes_persistent_volume and kubernetes_persistent_volume_claim types. [GH-3061]
  • resource/kubernetes_pod_disruption_budget_v1: Existing versioned PDBs upgrade at the same address without re-import. Spec changes still require replacement. Empty selector and metadata collections may need a one-time state update without changing the PDB. [GH-2995]
  • resource/kubernetes_service_v1: Add spec.traffic_distribution attribute. [GH-3055]
  • resource/kubernetes_service_v1: Existing Services upgrade in place without re-import. To change from the deprecated kubernetes_service type, use a moved block with Terraform 1.8 or later. [GH-2992]
  • resource/kubernetes_stateful_set_v1: Set the starting Pod ordinal with ordinals, limit unavailable Pods with update_strategy.rolling_update.max_unavailable, and select a volume attributes class with volume_claim_template.spec.volume_attributes_class_name on supported clusters. [GH-3017]

BUG FIXES:

  • resource/kubernetes_daemon_set_v1: Accept "0%" for rolling-update limits when the other limit permits progress. [GH-3017]
  • resource/kubernetes_deployment_v1, resource/kubernetes_daemon_set_v1, resource/kubernetes_stateful_set_v1, resource/kubernetes_pod_v1, resource/kubernetes_job_v1, resource/kubernetes_cron_job_v1: A pod security_context block that sets only empty values, such as supplemental_groups = [], no longer plans a change on every run. [GH-3017]
  • resource/kubernetes_deployment_v1, resource/kubernetes_daemon_set_v1, resource/kubernetes_stateful_set_v1, resource/kubernetes_pod_v1, resource/kubernetes_job_v1, resource/kubernetes_cron_job_v1: Accept SCTP container ports, downward API volume items that use only resource_field_ref, and huge page sizes beyond 2Mi and 1Gi in empty_dir.medium. [GH-3017]
  • resource/kubernetes_deployment_v1, resource/kubernetes_daemon_set_v1, resource/kubernetes_stateful_set_v1, resource/kubernetes_pod_v1, resource/kubernetes_job_v1, resource/kubernetes_cron_job_v1: Accept a single dot, a trailing dot and underscores in dns_config.searches, as Kubernetes does. [GH-3017]
  • resource/kubernetes_deployment_v1, resource/kubernetes_daemon_set_v1, resource/kubernetes_stateful_set_v1, resource/kubernetes_pod_v1, resource/kubernetes_job_v1, resource/kubernetes_cron_job_v1: Keep the configured spelling of numeric strings, such as run_as_user = "01000" or replicas = "01", to avoid repeated planned changes or Pod and Job replacements for equivalent values. [GH-3017]
  • resource/kubernetes_horizontal_pod_autoscaler_v2: A metric value or average_value that Kubernetes stores in a different but equal form, such as 1000m stored as 1, no longer plans a change. [GH-3050]
  • resource/kubernetes_horizontal_pod_autoscaler_v2: select_policy can be omitted from scale_up and scale_down. Previously the provider sent an empty value and Kubernetes rejected it with Unsupported value: "". [GH-3050]
  • resource/kubernetes_job_v1, resource/kubernetes_cron_job_v1: Accept exit code zero with the NotIn operator in Pod failure policy rules. [GH-3017]
  • resource/kubernetes_job_v1: Apply changes to ttl_seconds_after_finished and max_failed_indexes to the Job. [GH-3017]
  • resource/kubernetes_persistent_volume_v1, resource/kubernetes_persistent_volume_claim_v1: Planning rejects a known-invalid PVC storage request or a replacement whose destination name is confirmed occupied. These checks do not guarantee that Kubernetes will accept the replacement at apply. [GH-3061]
  • resource/kubernetes_persistent_volume_v1: Adding claim_ref for the claim that already holds the volume no longer makes Kubernetes mark the claim Lost. A volume that does not become available within the create timeout is recorded in state as tainted instead of being left in Kubernetes without state. [GH-3061]
  • resource/kubernetes_pod_v1: Keep a configured toleration of a built-in taint, such as node.kubernetes.io/not-ready with toleration_seconds, instead of replacing the Pod on every plan. A Pod whose state 3.x last wrote is replaced once more. [GH-3017]
  • resource/kubernetes_pod_v1: Keep several projections in one projected volume sources block without reporting a change on every plan. [GH-3017]
  • resource/kubernetes_pod_v1: Record the priority class Kubernetes assigns to a Pod that leaves out priority_class_name, such as a globalDefault PriorityClass, instead of replacing the Pod on every plan. [GH-3017]
  • resource/kubernetes_stateful_set_v1: Update revision_history_limit in place and accept zero. [GH-3017]
  • provider: Interrupting Terraform (Ctrl-C) stops an operation that is waiting, such as wait in kubernetes_manifest or the rollout wait of kubernetes_deployment_v1. Before, the wait continued until its timeout. [GH-3054]

NOTES:

  • resource/kubernetes_deployment_v1, resource/kubernetes_daemon_set_v1, resource/kubernetes_stateful_set_v1, resource/kubernetes_cron_job_v1: Updates now use patches rather than rebuilding the whole spec or Pod template from the Terraform configuration. [GH-3017]
  • resource/kubernetes_deployment_v1, resource/kubernetes_daemon_set_v1, resource/kubernetes_stateful_set_v1, resource/kubernetes_pod_v1, resource/kubernetes_job_v1, resource/kubernetes_cron_job_v1: After a create or update, state records the planned values, and only values the plan leaves unknown come from Kubernetes. Fields that admission webhooks or other clients add, such as an injected sidecar container, show as drift on the next refreshed plan instead of being recorded by the apply; lifecycle.ignore_changes handles them as before. [GH-3017]
  • resource/kubernetes_deployment_v1, resource/kubernetes_daemon_set_v1, resource/kubernetes_stateful_set_v1, resource/kubernetes_pod_v1, resource/kubernetes_job_v1, resource/kubernetes_cron_job_v1: Resource type names, namespace/name import IDs, import identities and existing state are kept, and an unchanged configuration normally plans no change. Values that earlier versions stored differently, such as explicitly empty labels = {}, can show a one-time in-place update that changes only Terraform state. With Terraform 1.8 or later, moved blocks can move resources from the deprecated kubernetes_deployment, kubernetes_daemonset, kubernetes_stateful_set, kubernetes_pod, kubernetes_job and kubernetes_cron_job types. [GH-3017]
  • resource/kubernetes_deployment_v1, resource/kubernetes_daemon_set_v1, resource/kubernetes_stateful_set_v1, resource/kubernetes_pod_v1, resource/kubernetes_job_v1, resource/kubernetes_cron_job_v1: Setting both name and generate_name in metadata gives a warning, since Kubernetes ignores generate_name when name is set. [GH-3017]
  • resource/kubernetes_deployment_v1: Setting rolling_update with the Recreate strategy is reported during planning. Kubernetes rejects the combination. [GH-3017]
  • resource/kubernetes_horizontal_pod_autoscaler_v2: Existing resources keep their address and namespace/name import ID. Terraform 1.8+ also supports moving from the unversioned kubernetes_horizontal_pod_autoscaler when its state has metric or behavior. target_cpu_utilization_percentage is still accepted but is not part of autoscaling/v2 and is never sent. [GH-3050]
  • resource/kubernetes_horizontal_pod_autoscaler: Now uses autoscaling/v2 instead of autoscaling/v2beta2 when metric or behavior is set. Configurations without those fields continue to use autoscaling/v1. Existing state does not need to be migrated. [GH-3042]
  • resource/kubernetes_ingress_v1, resource/kubernetes_ingress_class_v1, resource/kubernetes_network_policy_v1: Explicitly empty selector label maps and expression values can require a one-time state-only update from null to an empty collection. The update preserves the Kubernetes policy. After create or update, state retains known planned specification values; admission changes appear as drift on the next refresh. [GH-2994]
  • resource/kubernetes_ingress_v1, resource/kubernetes_ingress_class_v1, resource/kubernetes_network_policy_v1: Updates patch configured fields while preserving unrelated fields managed by other clients. [GH-2994]
  • resource/kubernetes_persistent_volume_v1, resource/kubernetes_persistent_volume_claim_v1: An unknown value alone does not trigger replacement. If it resolves to an immutable change during apply, Terraform fails the apply without changing the object. Adding node_affinity to a volume that has none is an in-place update. [GH-3061]
  • resource/kubernetes_pod_v1, resource/kubernetes_job_v1: A plan that changes a Pod spec or a Job pod template reads the object from Kubernetes, even with -refresh=false, to decide whether it must be replaced. Planning fails if that read fails or takes longer than 30 seconds. [GH-3017]
  • resource/kubernetes_service_v1: Explicitly empty maps and sets may produce a one-time state update from null to an empty collection without changing the Service. [GH-2992]
  • resource/kubernetes_stateful_set_v1: Warn during planning when changes to the requests, labels or annotations of a volume_claim_template cannot be applied to the existing StatefulSet. Replace the StatefulSet to apply such a change. [GH-3017]
  • provider: Upgraded Kubernetes client libraries to v0.37.2 (k8s.io/kubernetes v1.37.2). [GH-3042]

Don't miss a new terraform-provider-kubernetes release

NewReleases is sending notifications on new releases.