pulumi/tests/integration/dynamic/python-config-separate-module
Julien a3cdbad64c
Allow accessing configuration in Python dynamic providers (#17673)
Python dynamic providers get serialised and deserialised, and run in the
`pulumi-python` plugin process. This causes issues when trying to use
`pulumi.config.Config` in a dynamic provider:

* Using `Config` at runtime fails because the process is not setup with
the current configuration
* When the dynamic provider implementation is in the `__main__` module,
the dynamic provider serialization attempts to serialize the global
`SETTINGS` object, which pulls in protobuf definitions, which are not
serializable by `dill`.

To provide a stable API to access configuration in dynamic providers,
the provider classes (ResourceProvider) can now implement a `configure`
method which is called during provider initialization.
```python
class SimpleProvider(ResourceProvider):
    password: str

    def configure(self, req: ConfigureRequest):
        self.password = req.config.get("password")

    def create(self, props):
        # Use `self.password`.
        ...
```

The `configure` method is called when a provider is deserialized. Since
we cache the deserialization result, we guarantee that this is only
called once per program, and this process level cache serves as a plugin
registry.

Fixes https://github.com/pulumi/pulumi/issues/17050

---------

Co-authored-by: Will Jones <will@sacharissa.co.uk>
2024-11-07 10:12:24 +00:00
..
Pulumi.yaml Allow accessing configuration in Python dynamic providers (#17673) 2024-11-07 10:12:24 +00:00
__main__.py Allow accessing configuration in Python dynamic providers (#17673) 2024-11-07 10:12:24 +00:00
provider.py Allow accessing configuration in Python dynamic providers (#17673) 2024-11-07 10:12:24 +00:00
requirements.txt Allow accessing configuration in Python dynamic providers (#17673) 2024-11-07 10:12:24 +00:00