Closed plallin closed 1 month ago
Hi @plallin,
Thank you for reporting this issue. It happens during the patch operation on a Config Map object. Here we pick up only name and namespace and don't take into account annotations
and labels
that an object can have. As a result, they get overwritten.
This seems to be a relatively simple change. I will discuss this with my colleagues to see if I am missing something and if all looks good, I will raise a PR to address this issue.
Thanks!
Hi @plallin,
I went through this issue one more time today and I think we don't need to change our code. The reason why labels get wiped out is the field manager's name. By default, the field manager name is equal to Terraform
and used by both resources from your example. That cause the labels to overwrite when kubernetes_config_map_v1_data
is applied. In order to avoid this, you can change the manager name via the option field_manager
.
For example:
resource "kubernetes_config_map_v1_data" "my_cm_data" {
metadata {
name = "my-configmap"
namespace = "default"
}
force = true
depends_on = [
kubernetes_manifest.my_configmap
]
data = {
"foo" = "bar"
}
field_manager = "TerraformConfigMap"
}
Alternatively, you can simplify your code by moving the data
block to the kubernetes_manifest
resource, instead of managing it by a separate resource:
resource "kubernetes_manifest" "my_configmap" {
manifest = {
"apiVersion" = "v1"
"kind" = "ConfigMap"
"metadata" = {
"labels" = {
"label" = "value"
}
"name" = "my-configmap"
"namespace" = "default"
}
data = {
"foo" = "bar"
}
}
}
Marking this issue as stale due to inactivity. If this issue receives no comments in the next 30 days it will automatically be closed. If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. This helps our maintainers find and focus on the active issues. Maintainers may also remove the stale label at their discretion. Thank you!
Terraform Version, Provider Version and Kubernetes Version
Affected Resource(s)
Terraform Configuration Files
Debug Output
I may provide this later.
Panic Output
n/a
Steps to Reproduce
Expected Behavior
What should have happened?
The configmap including its labels should have been created as per the plan. The terraform plan is:
Actual Behavior
What actually happened?
The configmap was created but all labels are missing
Important Factoids
The labels are still referenced in the statefile and running a new plan/apply does not detect that labels are missing and does not reapply them to the configmap. They need to be added manually.
References
n/a
Community Note