terraform-provider-kubernetes icon indicating copy to clipboard operation
terraform-provider-kubernetes copied to clipboard

kubernetes_manifest can't handle empty map of annotations

Open gwkunze opened this issue 4 years ago • 2 comments

Terraform Version, Provider Version and Kubernetes Version

Terraform version: 0.14.11
Kubernetes provider version: 2.4.1
Kubernetes version: 1.19.12

Affected Resource(s)

  • kubernetes_manifest

Terraform Configuration Files

locals {
  # Labels to be used by every kubernetes resource created in this module
  commonLabels = {
    "example.com/provisionedBy" = "Terraform"
  }

  # Annotations to be used by every kubernetes resource created in this module
  commonAnnotations = {}
}

resource "kubernetes_manifest" "foobar" {
  manifest = {
    ...
    metadata = {
      ...
      labels = merge(local.commonLabels, {"my-foobar-label" = "bazban"})
      annotations = local.commonAnnotations
    }
  }
}

Error Output

Error: Provider produced inconsistent result after apply

When applying changes to
module.foobar.kubernetes_manifest.foobar, provider
"registry.terraform.io/hashicorp/kubernetes" produced an unexpected new value:
.object.metadata.annotations: was cty.MapValEmpty(cty.String), but now null.

This is a bug in the provider, which should be reported in the provider's own
issue tracker.

Steps to Reproduce

Esentially, any kubernetes_manifest where you set the annotations to {}

Expected Behavior

kubernetes_manifest should handle this like other resources, i.e. {} == no annotations

Workaround

resource "kubernetes_manifest" "foobar" {
  manifest = {
    ...
    metadata = {
      ...
      annotations = length(local.commonAnnotations) == 0 ? null : local.commonAnnotations
    }
  }
}

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

gwkunze avatar Aug 30 '21 10:08 gwkunze

I have the same problem with kubernetes_manifest resources. When I want to create my object there is no problem. But when I replay my terraform an issue appear.

My env

  • Terraform = v0.15.1
  • Terragrunt = v0.29.2
  • Kubernetes Provider = v2.4.1

My Object

` resource "kubernetes_manifest" "ceph-object-store" { provider = kubernetes

manifest = {
    apiVersion = "ceph.rook.io/v1"
    kind = "CephObjectStore"
    metadata = {
        name = "${var.objectstore_name}"
        namespace = "rook-ceph"
    }
    spec = {
        metadataPool = {
            failureDomain = "host"
            replicated = {
                size = "${var.replication_number}"
                requireSafeReplicaSize = true
            }
            #compressionMode = "none"
            crushRoot = ""
            erasureCoded = {
                codingChunks = 0
                dataChunks   = 0
            }
        }
        dataPool = {
            failureDomain = "host"
            replicated = {
                size = "${var.replication_number}"
                requireSafeReplicaSize = true
            }
            #compressionMode = "none"
            crushRoot = ""
            erasureCoded    = {
                codingChunks = 0
                dataChunks   = 0
            }
        }
        preservePoolsOnDelete = false
        gateway = {
            port = "80"
            instances = "${var.instances}"
            annotations = {
                "cni.projectcalico.org/ipv4pools": "[\"${format("10.%s.0/%s", var.subnet_bits, var.mask)}\"]"
            }
            labels = {
                k8s-app: "rook-ceph-rgw"
            }
            resources = {
                limits = {
                    cpu = "3"
                    memory = "2048Mi"
                }
                requests = {
                    cpu = "3"
                    memory = "2048Mi"
                }
            }
        }
        zone = {
            name = "${var.zone_name}"
        }
    }
}

} `

My issue

Error: Provider produced inconsistent result after apply
When applying changes to kubernetes_manifest.ceph-object-store, provider
"provider[\"registry.terraform.io/hashicorp/kubernetes\"]" produced an
unexpected new value: .object: wrong final value type: incorrect object
attributes.

This is a bug in the provider, which should be reported in the provider's
own issue tracker.

thibaut1405 avatar Sep 06 '21 12:09 thibaut1405

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!

github-actions[bot] avatar Sep 07 '22 00:09 github-actions[bot]

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

github-actions[bot] avatar Nov 06 '22 02:11 github-actions[bot]