Back to Terraform

Kubernetes Manifest Resources: CRDs, Server-Side Apply and Field Ownership

November 6, 2026 Wasil Zafar 20 min read

Use generic manifests while respecting schema discovery and competing field managers

Table of Contents

  1. Choose Typed Resources or Kubernetes Manifest Deliberately
  2. Install the CRD Before Planning Its Custom Resources
  3. Inspect Field Managers Before Taking Ownership
  4. Treat Computed Fields and Conflict Overrides Narrowly
  5. Import a Disposable Object and Resolve One Ownership Conflict

Choose Typed Resources or Kubernetes Manifest Deliberately

Typed resources are compiled contracts. A resource such as kubernetes_deployment_v1 carries a schema the provider ships, so Terraform validates argument types before it contacts the API. The trade is reach: the provider version decides which fields exist, and a new upstream field waits for a provider release.

Generic manifests trade that schema for coverage. kubernetes_manifest carries an HCL object, resolves its kind against the cluster, and applies it with server-side apply. It is the supported route for custom resources and for built-in kinds the provider has not modeled field by field.

The real decision is who owns the schema. With a typed resource the provider owns it; with a manifest the installed CRD owns it. A CRD upgrade can therefore change what Terraform can plan without any provider upgrade, which is useful for platform APIs and dangerous when nobody reviews the CRD.

Neither path avoids the API. A typed plan still refreshes live objects and needs working credentials; the difference is where the field definitions come from, not whether the cluster is contacted. An unreachable API fails both paths, just at different moments.

Figure 1 is the shortest version of the choice: start with the kind, then check whether the schema is already installed.

Choose Typed Resources or Kubernetes Manifest Deliberately
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','signalColor':'#5a6e82','noteBkgColor':'#c4873b','noteTextColor':'#132440','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    A["Kubernetes object to manage"] --> B{"Does a stable typed
resource exist?"} B -->|"yes, built-in API"| C["Typed resource
provider schema"] B -->|"no, custom resource"| D["kubernetes_manifest
cluster schema"] C --> E{"Need a field the
provider does not model?"} E -->|"yes"| D E -->|"no"| F["typed plan and apply"] D --> G{"CRD installed and
discoverable now?"} G -->|"no"| H["plan fails before
it can show a diff"] G -->|"yes"| I["server-side apply
with a field manager"] F --> J["provider update path"] I --> K["managedFields
ownership record"] H --> L["install the CRD in
an earlier stage"] classDef primary fill:#132440,color:#ffffff,stroke:#0b172b; classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a; classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f; classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420; classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f; class A,B,E,G primary; class C,D secondary; class F,I,K ok; class H danger; class J,L warn;

The schema source moves the failure point. A typed resource with a missing attribute fails during validation, before any request. A manifest with a missing CRD fails during plan, often after the rest of the graph has been read. The second error is later, louder and easier to misread as a cluster outage.

Two schema paths from HCL to the same API server The left lane shows a typed resource whose schema ships inside the Terraform provider, then uses the provider update path. The right lane shows a kubernetes_manifest whose schema is discovered from a CRD through the RESTMapper and OpenAPI, then applied with server-side apply. Both lanes meet at the API server, where admission and defaulting run before field ownership is recorded in managedFields. A CRD missing from discovery stops the right lane at plan time. One API server, two places to learn the schema Typed resources compile it. Manifests discover it. typed resource lane HCL typed arguments named fields and types provider schema ships with the provider binary changes at upgrade time provider update path create, read, update, delete manifest lane HCL dynamic object apiVersion, kind, nested map schema from the cluster RESTMapper plus OpenAPI CRD version decides the fields server-side apply field manager records ownership no CRD in discovery: stop here at plan The API server adds defaults and admission changes after either path. managedFields records who owns the result.

Manifest is the escape hatch, not the default. The provider documentation recommends it for custom resources and for kinds not yet fully supported. Replacing every typed resource with a manifest gives up provider-side validation, readable diffs and provider-tested defaults in exchange for flexibility you may not need.

A typed resource can still be the wrong abstraction. Large nested blocks make some built-in objects harder to read than the equivalent YAML. When the typed schema turns a ten-line manifest into a hundred-line HCL block, the manifest is the clearer contract even though the kind is supported.

The table keeps the comparison attached to a decision rather than a preference.

DecisionTyped resourceGeneric manifestCheck before choosing
Schema sourcecompiled into the providerdiscovered from the cluster and CRDDoes the plan need a kind the provider already knows?
API coveragebuilt-in, version-suffixed kindsany GVK, including custom resourcesIs this a custom resource or a new upstream API?
Plan-time dependencyprovider schema; API needed to refreshAPI discovery required before any diffIs the CRD installed and served right now?
Field ownershipprovider update pathserver-side apply with a field managerWho else writes the fields you intend to set?
Defaults and admissioncomputed attributes absorb server valuesAPI values returned in object; computed_fields is the tolerance listWhich values are defaulted or mutated after apply?
Best fitstable built-in objectscustom resources and fast-moving APIsWill a CRD upgrade change the shape of your HCL?

Install the CRD Before Planning Its Custom Resources

A CRD is a schema installation, not an ordinary dependency. It teaches the API server a new kind and gives the provider the OpenAPI schema it needs to turn a custom resource into a typed plan. Until that schema exists, there is nothing for the manifest resource to plan against.

The failure happens before any diff. The provider asks the cluster's RESTMapper for the kind, then reads the CRD's schema. When the kind is absent, the diagnostic says the API did not recognize the GroupVersionKind and suggests the CRD may not be installed. Retrying the same plan cannot change that answer; the definition has to exist first.

depends_on orders apply, not discovery. Terraform cannot create the CRD during planning, so a graph edge inside one root does not make the kind visible when the custom resource is planned. The CRD must already be installed by an earlier apply, a platform pipeline or a bootstrap tool.

A deferred plan is a convenience, not a guarantee. Newer Terraform clients can defer a resource whose schema is unknown and show the object as unknown. That keeps the rest of the plan moving, but the resource stays unknown and the apply cannot succeed until discovery catches up.

Separate the definition from the instances. Put the CRD in a platform-owned root and the custom resources in an application root. The second root can take the group and version as inputs, so the dependency is explicit in configuration rather than hidden in an ordering comment.

Establishment and discovery are separate observations. A CRD can be accepted before the version is served in discovery. Apply the CRD, wait for its Established condition, then confirm the kind appears in discovery before planning the second root. That sequence is slower than one apply and much easier to diagnose.

A CRD upgrade follows the same rule. Adding a served version does not make it usable in the plan that introduces it. Apply the CRD change first, confirm the new version is discoverable, then move the custom resources. Removing a served version while objects still use it breaks reads even though the definition still exists.

The CRD is a cluster-wide deletion lever. Deleting it deletes every custom resource of that kind in every namespace. Keep it out of application roots, guard it against casual destroy, and never let a workload's teardown decide the fate of the API definition.

Figure 2 follows the two-stage sequence and keeps each failure attached to the boundary that causes it.

Install the CRD Before Planning Its Custom Resources
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','signalColor':'#5a6e82','noteBkgColor':'#c4873b','noteTextColor':'#132440','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    S1["stage 1 root
cluster and CRD"] --> A["CRD accepted
by the API"] A --> E{"Established
condition true?"} E -->|"no"| F["schema rejected or
conversion not ready"] E -->|"yes"| D["discovery serves
group, version, kind"] D --> S2["stage 2 plan
custom resources"] S2 --> G{"GVK found in
discovery?"} G -->|"no"| H["plan error: CRD may
not be installed"] G -->|"yes"| I["OpenAPI schema mapped
to Terraform types"] I --> J["server-side apply
of the custom resource"] J --> K{"Controller
reconciles?"} K -->|"no"| L["object stored, status
empty, no readiness"] K -->|"yes"| M["status and conditions
are separate evidence"] H --> N["same-root depends_on
cannot help at plan"] F --> O["fix the schema or
webhook before stage 2"] classDef primary fill:#132440,color:#ffffff,stroke:#0b172b; classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a; classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f; classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420; classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f; class S1,E,G,K primary; class A,D,S2,I secondary; class J,M ok; class H,N danger; class F,L,O warn;

A stored object is not a working controller. The custom resource can exist with an empty status long before anything reconciles it. Read the custom resource's status conditions and the controller's own logs as separate evidence; a successful Terraform apply proves only that the API accepted the object.

Inspect Field Managers Before Taking Ownership

A field manager is the name attached to a write. Server-side apply stores an entry in metadata.managedFields for each manager, listing the fields that manager last applied. The API rejects a write that changes a field owned by another manager with a different value, unless the write is forced.

Ownership is per field, not per object. A field can have more than one owner while the managers agree on its value; a conflicting value is what the API refuses. This is why an operator can own status and Terraform can own spec on the same object without either side fighting.

Terraform's default manager name is Terraform. Every manifest resource in a root uses that name unless a field_manager block overrides it. Two roots that keep the default are indistinguishable to the API, so one root's apply can release a field the other root believed it owned.

Give each root a distinct manager name. A platform root might use tf-platform and an application root tf-app; the name is part of the contract. It makes the ownership record readable and keeps one root's field set from rewriting another root's entry.

Other managers are usually controllers. The deployment controller, the horizontal autoscaler, cert-manager and operators all apply fields. Kubectl adds its own records: client-side apply uses the last-applied annotation, while server-side apply uses the name passed to --field-manager, which defaults to kubectl itself. Helm writes under its own manager as well.

Read the record before you write. A kubectl get with --show-managed-fields prints the manager entries next to the object. The manager, operation and field list answer "who owns this value" more directly than the last-applied annotation, which only client-side apply maintains.

A shared object is safe only when the field sets are disjoint. Terraform can own a custom resource's spec while an operator owns its status when the CRD enables the status subresource. Two managers writing the same spec field is not sharing; it is a queue of overwrites with an audit trail.

Avoid the classic autoscaler collision. If an HPA owns the scale subresource, Terraform should not also set the Deployment's replica count. The HPA writes replicas on every scale event, Terraform writes its configured value on every apply, and each plan reports a change that is really an ownership dispute.

Client-side apply leaves a second owner. Moving a kubectl-managed object to server-side apply does not erase the old manager entry. The first server-side write can conflict until the old manager releases the field or a deliberate one-time takeover occurs.

Import reads state; it does not transfer ownership. Importing an object populates Terraform's state, but the existing manager entry remains until Terraform applies. If the first plan is a no-op, Terraform never wrote, so it never became the owner of those fields.

One object, one Terraform root. Even with distinct manager names, two roots that both declare the same object are one delete away from fighting over its lifecycle. Split by object, not by field, and let a single root own the object's existence.

Treat Computed Fields and Conflict Overrides Narrowly

Computed fields are a tolerance list, not an ownership transfer. Each path tells Terraform to accept the API's post-apply value for that field instead of raising an inconsistent-result error. The mechanism exists for admission mutation, not for a controller that will keep changing the field forever.

The default list is metadata labels and annotations. Supplying your own list replaces that default rather than extending it, so re-include those paths when you still need the tolerance. An empty list turns the behavior off entirely.

Narrow the path to the field that actually moves. Naming metadata.labels accepts controller-added labels; naming spec would hide every spec drift under one setting. A broad path turns a precise admission fix into a blanket blind spot.

A defaulted field should usually stay out of the manifest. If the CRD defaults a mode field to safe, omit it and let the API write the value. Copying the default into HCL makes Terraform the owner of a value the schema is supposed to govern, and a later schema change cannot take effect.

Force conflicts is resource-wide. Setting force_conflicts = true lets Terraform override any conflicting field in that resource, including fields a controller needs. It is not a per-field override, and leaving it on converts future ownership disputes into silent overwrites.

Prefer release or one deliberate takeover. Remove the field from the competing manager's applied configuration, or perform one explicit server-side apply with Terraform's manager name and force enabled, then remove the setting. A permanent force flag is a policy, and usually the wrong one.

Ignore changes is a Terraform lifecycle tool; on a typed resource it can exclude a named attribute. It does not change who owns the field in the API. Use it for values you deliberately delegate, not to silence a diff you have not explained.

A second plan is the test. After the API mutates the field, a fresh plan should show no change and the state should match the live object. If the value keeps flipping, you have two owners, not a formatting problem.

Figure 3 contrasts a narrow tolerance with a resource-wide override and shows where each one ends.

A narrow computed-field tolerance compared with a resource-wide force override The left panel shows metadata.labels declared as a computed field. Admission adds a label, Terraform accepts the returned value, and the next plan is clean. The right panel shows force_conflicts enabled for the whole resource. Terraform overwrites a controller-owned field, the controller writes it back, and the cycle repeats. A footer states that the first is a field-level tolerance and the second is a resource-wide policy. Tolerate one field, or force every field The left accepts a server change. The right starts a contest. computed_fields = metadata.labels manifest sets a label team equals payments admission adds a label the API returns both keys Terraform accepts the result next plan is clean force_conflicts = true Terraform overwrites the controller-owned field controller writes it back its reconcile loop never stops next plan shows the change again the diff is an ownership dispute A computed field is a named exception. A force flag is a resource-wide policy. Use the first for admission. Use the second only for a deliberate takeover.

The path must match the schema exactly. Object fields use dots, map keys use bracket notation, and list elements use an index. A path that does not resolve is either rejected or silently fails to cover the field, which turns a tolerance into an inconsistent-result error at the worst moment.

Computed fields do not make a field unmanaged. Terraform still sends the value from the manifest on apply; the tolerance only governs what it accepts back. If the controller's value should win permanently, remove the field from your configuration instead of teaching Terraform to ignore the answer.

Import a Disposable Object and Resolve One Ownership Conflict

The lab proves the mechanism without a real operator. A minimal CRD with no controller isolates API field ownership from reconciliation. Terraform 1.17.1 and hashicorp/kubernetes 3.5.0 are enough; the only competing manager is a deliberate kubectl apply.

Lab

Import a Disposable Object and Resolve One Ownership Conflict

Execution status: design-only. These steps were not run against a live cluster for this article. The sequence is written to be executed and recorded, not quoted as a transcript.

Prerequisites. A disposable cluster and namespace, Terraform 1.17.1 with hashicorp/kubernetes 3.5.0, and kubectl permission to create a CRD and a custom resource. No workload, cloud identity or persistent volume is involved.

  1. Stage the CRD first. In a platform root, declare a cluster-scoped CRD for the group lab.example.com, with kind Widget, plural widgets, and one served version v1. Keep the definition out of the application root.
  2. Wait for establishment. Run kubectl wait --for condition=established --timeout=60s crd/widgets.lab.example.com, then confirm the kind appears in kubectl api-resources.
  3. Give it a structural schema. Define spec.message as a string and spec.mode as a string with the default safe. A structural schema is what lets the provider plan updates; a non-structural CR triggers a warning and forced replacement on change.
  4. Create the object outside Terraform. Apply a Widget named hello in namespace manifest-lab with a server-side kubectl apply under the field manager manual, and set its message to hello. This manager now owns the message field.
  5. Import it into Terraform. Run terraform import kubernetes_manifest.hello "apiVersion=lab.example.com/v1,kind=Widget,namespace=manifest-lab,name=hello" against a manifest that matches the live object. Import reads state; it does not apply.
  6. Record the imported baseline. Run terraform plan and expect no changes. That no-op is the trap: Terraform has the object in state but has never written it, so the manual manager still owns every field it set. The provider's import warning asks for an apply; with an empty plan, that apply writes nothing.
  7. Change Terraform's value. Set the message to hello-again and apply. Expect a field manager conflict naming the manual manager and the message field, because import did not transfer ownership.
  8. Recover by releasing the field. Re-apply as manual with a manifest that omits the message field. That releases the manager's ownership, and the next Terraform apply can set its value without any force flag.
  9. Prove the baseline and the new owner. Plan again and expect no changes. A kubectl get widgets.lab.example.com hello -n manifest-lab -o yaml --show-managed-fields read should now show lab-terraform owning the message field, while the defaulted mode remains absent from Terraform's manifest.
  10. Clean up in dependency order. Delete the Widget, then the namespace, then the CRD last, and confirm no cluster-scoped object remains.
CheckEvidencePass looks like
CRD orderstage 1 apply, then discoverythe widget kind is listed before the app root plans
Import baselineplan after importno changes, and no Terraform apply has occurred
Ownership before applymanagedFields of the imported objectmanual owns message; Terraform owns nothing yet
Conflictapply after the message changefailure naming the manual manager and the field
Recoverymanual apply without message, then Terraform applyTerraform succeeds without a force flag
Ownership after applymanagedFields after the successful applylab-terraform owns message
Clean baselineplan after recoveryno changes and no replacement
Cleanupobject listing after destroyWidget and namespace gone, CRD removed last

Expected observation. Import populates state but leaves the existing owner in place, so the first real change conflicts instead of silently taking over. Releasing the field lets Terraform apply cleanly and become the recorded owner. The defaulted mode never enters Terraform's configuration, and the final plan is clean.

Failure checks. If the plan after import wants changes, the manifest does not match the live object's types or defaults; fix the configuration rather than forcing the apply. If the apply says the kind is unknown, discovery has not caught up. If the conflict appears on labels instead of message, a custom computed list replaced the metadata default.

Cost dimensions. The lab is close to free: one CRD, one custom resource and one namespace. It creates no load balancer, node pool or persistent volume, so the only realistic charge is the disposable cluster itself.

Cleanup. Delete the Widget before the CRD, then remove the namespace and confirm the CRD is gone. Run a final plan to prove the roots manage nothing else, and check that the platform root did not leave a cluster-scoped definition behind.

The record is the deliverable. Keep the baseline plan, the managedFields excerpt, the conflict message and the clean plan after recovery together. A reviewer can then see which manager wrote each field, why the apply failed and what actually resolved it, without repeating the experiment.

Next in the Series

In Helm and GitOps Boundaries: One Reconciler per Object, we'll explore Combine Terraform with companion deployment tools without creating competing controllers.