terraform-provider-kubernetes
terraform-provider-kubernetes copied to clipboard
Can't use both kubernetes_annotations and kubernetes_labels on the same resource
Terraform Version, Provider Version and Kubernetes Version
Terraform version: v1.5.5
Kubernetes provider version: v2.23.0
Kubernetes version: v1.26.7
Affected Resource(s)
- kubernetes_labels
- kubernetes_annotations
Terraform Configuration Files
data "kubernetes_config_map" "main" {
metadata {
name = "test"
namespace = "default"
}
}
resource "kubernetes_annotations" "main" {
api_version = "v1"
kind = "ConfigMap"
metadata {
name = "test"
}
annotations = {
"name" = "value"
}
}
resource "kubernetes_labels" "main" {
api_version = "v1"
kind = "ConfigMap"
labels = {
"name" = "value"
}
metadata {
name = "test"
}
}
###Output
Plan: 2 to add, 0 to change, 0 to destroy.
kubernetes_annotations.main: Creating...
kubernetes_labels.main: Creating...
kubernetes_labels.main: Creation complete after 1s [id=apiVersion=v1,kind=ConfigMap,name=test]
kubernetes_annotations.main: Creation complete after 1s [id=apiVersion=v1,kind=ConfigMap,name=test]
Apply complete! Resources: 2 added, 0 changed, 0 destroyed.
Steps to Reproduce
- Create a ConfigMap in a cluster, which is used as a data resource in Terraform
- Run
terraform applywith the resources written above
Expected Behavior
Both labels and annotations are applied.
Actual Behavior
Terraform only applies (in this case) the annotation to the ConfigMap. Running terrafrom apply again, replaces the annotation with the labels. Running terraform apply again, replaces the label with the annotation, etc.
❯ terraform apply -auto-approve
kubernetes_labels.main: Refreshing state... [id=apiVersion=v1,kind=ConfigMap,name=test]
data.kubernetes_config_map.name: Reading...
kubernetes_annotations.main: Refreshing state... [id=apiVersion=v1,kind=ConfigMap,name=test]
data.kubernetes_config_map.name: Read complete after 0s [id=default/test]
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
~ update in-place
Terraform will perform the following actions:
# kubernetes_labels.main will be updated in-place
~ resource "kubernetes_labels" "main" {
id = "apiVersion=v1,kind=ConfigMap,name=test"
~ labels = {
+ "name" = "value"
}
# (3 unchanged attributes hidden)
# (1 unchanged block hidden)
}
Plan: 0 to add, 1 to change, 0 to destroy.
kubernetes_labels.main: Modifying... [id=apiVersion=v1,kind=ConfigMap,name=test]
kubernetes_labels.main: Modifications complete after 0s [id=apiVersion=v1,kind=ConfigMap,name=test]
Apply complete! Resources: 0 added, 1 changed, 0 destroyed.
❯ terraform apply -auto-approve
data.kubernetes_config_map.name: Reading...
kubernetes_labels.main: Refreshing state... [id=apiVersion=v1,kind=ConfigMap,name=test]
kubernetes_annotations.main: Refreshing state... [id=apiVersion=v1,kind=ConfigMap,name=test]
data.kubernetes_config_map.name: Read complete after 0s [id=default/test]
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
~ update in-place
Terraform will perform the following actions:
# kubernetes_annotations.main will be updated in-place
~ resource "kubernetes_annotations" "main" {
~ annotations = {
+ "name" = "value"
}
id = "apiVersion=v1,kind=ConfigMap,name=test"
# (4 unchanged attributes hidden)
# (1 unchanged block hidden)
}
Plan: 0 to add, 1 to change, 0 to destroy.
kubernetes_annotations.main: Modifying... [id=apiVersion=v1,kind=ConfigMap,name=test]
kubernetes_annotations.main: Modifications complete after 0s [id=apiVersion=v1,kind=ConfigMap,name=test]
Apply complete! Resources: 0 added, 1 changed, 0 destroyed.
Hello @edwin-bruurs, thank you for opening this issue! This seems to be an issue related to https://github.com/hashicorp/terraform-provider-kubernetes/issues/2247
kubernetes_labels does a server-side apply patch which could be reason for their being conflicts with kubernetes_annotations Some planning is being done to address this issue.
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!