pulumi icon indicating copy to clipboard operation
pulumi copied to clipboard

Diff doesn't work for python dynamic resource in pulumi up in case of drift

Open bernhardloos opened this issue 2 years ago • 2 comments
trafficstars

What happened?

Consider this dynamic resource:

from pulumi import dynamic

class TestProvider(dynamic.ResourceProvider):
    def __init__(self):
        pass

    def check(self, olds: dict, news: dict) -> dynamic.CheckResult:
        return dynamic.CheckResult(news, [])

    def diff(self, id_: str, olds: dict, news: dict) -> dynamic.DiffResult:
        return dynamic.DiffResult(changes=olds != news, replaces=[])

    def create(self, props: dict) -> dynamic.CreateResult:
        return dynamic.CreateResult(id_="id", outs=props)

    def read(self, id_: str, props: dict) -> dynamic.ReadResult:
        props["test"] = "newval" # simulate config drift

        return dynamic.ReadResult(id_=id_, outs=props)

    def update(self, id_: str, olds: dict, news: dict) -> dynamic.UpdateResult:
        return dynamic.UpdateResult(outs=news)

    def delete(self, id_: str, props: dict) -> None:
        pass

class TestResource(dynamic.Resource, module=__name__, name="TestResource"):
    def __init__(self, name: str, opts=None):
        props = {
            "test": "oldval"
        }
        super().__init__(TestProvider(), name, props, opts=opts)

If you run pulumi up, pulumi refresh and then pulumi up again and view the details, the resource shows up as changed but no actual changes are shown. The changes are made correctly but this makes it really annoying to figure out what a pulumi up is actually going to change.

Expected Behavior

The newval -> oldval change is shown in the details of pulumi up after a refresh.

Steps to reproduce

  • Create a TestResource
  • run pulumi up
  • adjust oldval in TestResource to oldval2
  • run pulumi up, in the details, notice the the oldval -> oldval2 change, accept the change
  • run pulumi refresh, check the details and notice the oldval2 -> newval change, accept the change
  • run pulumi up, the resource is marked as changed but the details don't show what

Output of pulumi about

CLI
Version 3.77.1 Go Version go1.20.6 Go Compiler gc

Plugins NAME VERSION kubernetes 4.0.3 kubernetes_crds 4.0.3 python unknown random 4.13.2 tls 4.10.0 vault 5.13.0

Host
OS fedora Version 38 Arch x86_64

This project is written in python: executable='/usr/bin/python3' version='3.11.4'

Dependencies: NAME VERSION pip 22.3.1 pulumi-kubernetes 4.0.3 pulumi-kubernetes-crds 4.0.3 pulumi-random 4.13.2 pulumi-tls 4.10.0 pulumi-vault 5.13.0 python-ldap 3.4.3 setuptools 65.5.1

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

bernhardloos avatar Aug 08 '23 18:08 bernhardloos

I think this is because there's no way for dynamic providers to fully fill in a diff response. Should just be a case of exposing a load more of the diff fields on DiffResult to enable this.

Frassle avatar Aug 08 '23 20:08 Frassle

After https://github.com/pulumi/pulumi/pull/16146 this now also affects refresh (if the old behavior isn't enabled), so some solution here would be very welcome.

bernhardloos avatar Jun 14 '24 14:06 bernhardloos