Update/replace resource when a dependency is changed #8099

I’m creating this topic to continue discussion from
Update/replace resource when a dependency is changed
, which I’m locking so that people can continue to subscribe just to . I’m happy to see people are helping each other work around this, and I’m hoping moving the discussion here will support that without creating excess noise for people who just want succinct “it’s done” type updates in GitHub.

1 Like

Hi, I would like to have some help with a workaround to this exact issue, till Hashicorp will release something official.
My problem is the kubernetes config-map resource which a pod have a dependency on.
I would like that every time a Variable is changed in the config-map, the parent resource (pod) will be recreated to grab the change, as for now I need to manually recreate it through kubectl. Thanks.

Hi. I think the replace_on_change is a good idea.
My case is also with the kubernetes. I have a Pod use a PVC and use a PV. When the PV is modified, it should delete the Pod, then the PVC, then the PV, then create PV, PVC, and Pod again.
What happening now is that the PV stuck in Still destroying... til timeout.

I had a similar issue. This is how I ended up solving it:

  1. Populated kubernetes_config_map resource with local_file resource
resource local_file conf {
 filename = "files/config.conf"
 content = "some content"
}

resource kubernetes_config_map conf {
  metadata {
    name = "conf"
    namespace = "apps"
  }
  data = {
    config-file = local_file.conf.content
  }
}
  1. In the deployment I set up an environment variable which was a sha hash of the config file. This forces a new deployment when the config file changes:
resource kubernetes_deployment deploy {
 ...
  spec {
    template {
      spec {
        container {
           env {
             name = "CONFIG_SHA1"
             value = sha1(local_file.conf.content)
           }
  ...
}

Hope that helps.