hashicorp / terraform-provider-kubernetes

Terraform Kubernetes provider
https://www.terraform.io/docs/providers/kubernetes/
Mozilla Public License 2.0
1.56k stars 966 forks source link

kuberenetes_manifest doesn't recongnize out of band changes #2259

Open shysank opened 10 months ago

shysank commented 10 months ago

Terraform Version, Provider Version and Kubernetes Version

Terraform version: 1.4.6
Kubernetes provider version: 2.23.0
Kubernetes version: 1.24

Steps to Reproduce

  1. Define kubernetes_manifest terraform resource that points to a yaml file which contains a k8s manifest
  2. terraform plan and apply
  3. kubectl edit $resource_created_in_1 => add a labelfoo: bar`
  4. terraform plan

Expected Behavior

What should have happened? Plan should show that label foo" bar should be removed

Actual Behavior

Plan showed no changes

Is this the expected behavior?

shysank commented 10 months ago

I guess it's because computed fields defaults to metadata.labels, metadata.annotations. Is there a way to mark a specific label as computed field? eg. computed_fields: [metadata.labels["resourceVersion"]]

alexsomesan commented 10 months ago

@shysank The computed_fields attribute can only address fields that are defined by the Kubernetes OpenAPI schema and metadata.labels is a map type in the Kubernetes schema. However, individual map elements are arbitrary and not part of the schema therefore they cannot be used in computed fields.

You can try to remove metadata.labels from the list of computed fields by explicitly setting a value for computed_fields, for example:

  computed_fields = ["metadata.annotations"]

Let us know if that helps.

shysank commented 10 months ago

@alexsomesan Yes, thats what I'm doing right now. The problem is, since annotations are completely ignored in plan, we are missing some changes that we'd like to see. That was the motivation for my original question to have targeted keys as computed fields.

n1ngu commented 2 months ago

Related https://github.com/hashicorp/terraform-provider-kubernetes/issues/1568

The issue extends beyond annotations.