‹ Back to all articles

Terraform Kubernetes Provider: Choosing between generic and version-specific resources

When orchestrating infrastructure with Terraform's Kubernetes provider, a recurring dilemma comes up: either use the generic resources or pin configurations to a specific Kubernetes API version. Both approaches have their own pros and cons.

Update 2026: since version 3.0 of the Kubernetes provider (December 2025), the generic resources are deprecated: use the _v1 variants. So the choice below has been made for you. The migration is still relevant, and it has become easier: for a growing number of resources the provider supports a moved block from the old to the _v1 resource (Terraform 1.8 or later, see the provider’s changelog), and you can replace terraform import and terraform state rm with import and removed blocks in your code.

Generic resources, such as kubernetes_namespace, bring a certain level of abstraction. They hide the details of the Kubernetes API version. This abstraction implies that your configurations will adapt seamlessly to the default Kubernetes API version supported by the provider. In a dynamic environment where you want your infrastructure to automatically benefit from updated Kubernetes versions, this looks like an attractive option. This flexibility has its downsides too, though. Relying on the provider’s default versions can introduce unexpected behaviour, especially if newer Kubernetes versions contain breaking changes. On top of that, with a generic setup you may miss out on the immediate benefits that newer API versions can bring.

On the other hand, version-specific resources, such as kubernetes_namespace_v1, offer a different set of advantages. By pinning your configurations to a specific version, you get an environment with stability and predictability. Such an approach is invaluable, especially for production workloads where the smallest unexpected change can snowball into bigger problems. Besides stability, there is an inherent clarity in using version-specific resources. They make it clear which version of the Kubernetes API you expect. Moreover, these resources usually let you use features unique to their corresponding API version in a more fine-grained way. But, as always, there are trade-offs. Pinning to a specific version can complicate future migrations and requires careful updates to Terraform configurations whenever a version change is considered.

Complex vs simple resources

The example above is a simple namespace within a cluster. This is a resource that will change very little, and its API can be called stable. For this one, you could consider using the generic version after all. But once you start introducing a mix of _v1 and non-_v1 types, you quickly end up in an unclear situation. So it’s best to be consistent and go for an all-or-nothing approach.

Migrating between generic and version-specific resources

When you’re considering migrating between different resource types in Terraform, especially for a workload that has already been applied, there are two methods to consider: using terraform state mv to mutate state objects, or removing them and then importing them again.

Using terraform state mv

The terraform state mv command lets you move resources within your state. This method makes sure the underlying resource isn’t destroyed and recreated, which is especially crucial for production workloads.

For example, if you’re moving from a generic kubernetes_namespace to a version-specific kubernetes_namespace_v1, you would run the following:

$ terraform state mv kubernetes_namespace.example kubernetes_namespace_v1.example

Here kubernetes_namespace.example is the address of the original resource and kubernetes_namespace_v1.example the address of the new one. Adjust the addresses to match your actual resources.

I use this method most for simpler objects: Namespaces, RBAC definitions, storage descriptions, …

Removing and Re-importing

This method involves removing the resource from the state and then importing it again under the new resource type. It’s somewhat riskier because there’s a period during which the resource isn’t tracked, but it works well for resources that support importing. The example below uses a resource in a module, but functionally it’s no different.

Steps:

Get the resource ID of the current resource.

$ terraform state show module.mongodb.kubernetes_namespace.mongodb
# module.mongodb.kubernetes_namespace.mongodb:
resource "kubernetes_namespace" "mongodb" {
    id                               = "mongodb"
    wait_for_default_service_account = false

    metadata {
        annotations      = {}
        generation       = 0
        labels           = {}
        name             = "mongodb"
        resource_version = "37735496"
        uid              = "7e55d60b-b647-4226-9569-b47cfb92119a"
    }
}

In the “ID” field you’ll see the value of the resource ID, “mongodb” in our case.

Remove the old resource from the state (this does NOT destroy the actual resource, it only removes its representation from Terraform’s state):

$ terraform state rm module.mongodb.kubernetes_namespace.mongodb

Change your Terraform configuration to use the desired resource (kubernetes_namespace_v1 in this case).

Import the resource into the state again:

$ terraform import module.mongodb.kubernetes_namespace_v1.mongodb <resource-ID>

Replace <resource-ID> with the correct identifier for your resource. You’ll need to consult the Kubernetes documentation or your own infrastructure records to get this ID.

I prefer to use this method for more complex definitions, such as a Deployment. I might try those with a simple state mv first, but if too many differences turn up, a re-import is sometimes the handier option.

Which option to choose

The Kubernetes provider is an exception among the widely used providers; it offers both the generic and the version-specific resources. Providers such as AWS, Azure and GCP, for example, don’t do this.

At Krane Labs we normally go for the version-specific variant. Although generic resources and their adaptability have a strong appeal, using version-specific resources mainly gives long-term stability, which is what we’re after. In production environments it’s wise to embrace predictability. Pinning configurations to a specific Kubernetes API version makes sure that re-applying Terraform workloads in the future won’t make unexpected changes. It’s a deliberate choice that favours controlled evolution over unintended mutations, and provides a foundation where production-ready infrastructure stays undisturbed.

When you want to align a workload to a particular version, the terraform state mv approach is generally safer and simpler because it leaves the actual underlying resource untouched. However, if state mv isn’t feasible for some reason, the remove-and-re-import method is an alternative. Whichever method you use, always back up your Terraform state before making changes. If possible, test these operations first in a safe, non-production environment, so you understand the process and its possible implications, and get the steps into your fingers, should you ever need to apply this to production.

The choice between one approach and the other isn’t new. It’s in line with the discussions around whether or not to version-pin deployments (:latest or :specific-tag), auto-updating non-security OS packages, or defining versions of, for example, providers and Terraform itself as fixed or loose.

Written by

Bernard Grymonpon

Technical architect. Turns abstract requirements into working, maintainable platforms.

Not sure your platform is ready for what's next?

Interested in: