Search code examples
terraformterraform-provider-kubernetes

Terraform resource isn't reading updated value of another resource correctly


I don't know if this is a Terraform issue or the provider has a bug.

I'm using kubernetes_deployment and kubernetes_config_map.

In kubernetes_deployment I have this:

template {
  metadata {
    labels = {
      config_version = kubernetes_config_map.myconfig.metadata[0].resource_version

This is what happens:

  1. I modify the config file the kubernetes_config_map resource is using and run apply
  2. Terraform sees the config map resource change but the kubernetes_deployment resource doesn't show any changes
  3. After I apply I run apply a second time
  4. Now kubernetes_deployment sees the changed value and registers it as a change

This happens with or without an explicit depends_on.

Why is this happening? kubernetes_deployment should be seeing the value has changed and register that as a change too.


Solution

  • I wasn't paying attention to what was happening.

    I think this is a bug in the kubernetes_config_map resource.

    When the config map data is modified the kubernetes_config_map resource only surfaces a change in the "data" attribute and this is the wrong behavior causing my issue.

    If data is modified then the resource_version MUST and will always change, but the resource doesn't register this change. Because of this dependant resources looking at that attribute don't see any changes.

    Too bad because that would be a really clear way to to this.

    Fortunately until that bug is fixed I can use a hash of the data attribute:

    template {
      metadata {
        labels = {
          config_hash = md5(kubernetes_config_map.myconfig.data)