pulumi/sdk/python/lib/test
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
..
automation auto: support refresh consistently in up/preview/destroy (#17209) 2024-09-17 09:39:02 +00:00
data/lazy_import_test [sdk/python] Workaround lazy module regression (#16038) 2024-04-24 06:53:59 +00:00
dynamic Allow accessing configuration in Python dynamic providers (#17673) 2024-11-07 10:12:24 +00:00
langhost [sdk/python] Always unwrap value from InvokeResult in invoke_async (#17349) 2024-09-24 10:24:51 +00:00
provider Use black to format lib/test (#16028) 2024-04-23 08:29:58 +00:00
runtime Use black to format lib/test (#16028) 2024-04-23 08:29:58 +00:00
__init__.py Fix a couple of issues when projecting Protobuf and UNKNOWN in Python (#1468) 2018-06-06 16:09:07 -07:00
conftest.py Use black to format lib/test (#16028) 2024-04-23 08:29:58 +00:00
helpers.py Use black to format lib/test (#16028) 2024-04-23 08:29:58 +00:00
test_broken_dynamic_provider.py Fixing a few pylint errors in the python test folder (#16962) 2024-08-14 08:26:34 +00:00
test_config.py Use black to format lib/test (#16028) 2024-04-23 08:29:58 +00:00
test_deprecated.py Fixing a few pylint errors in the python test folder (#16962) 2024-08-14 08:26:34 +00:00
test_invoke.py Use black to format lib/test (#16028) 2024-04-23 08:29:58 +00:00
test_monitor_termination.py Fixing a few pylint errors in the python test folder (#16962) 2024-08-14 08:26:34 +00:00
test_next_serialize.py [sdk/python] Handle nested structures properly when unwrapping secrets from invoke inputs (#17482) 2024-10-07 11:40:12 +00:00
test_output.py Allow Python dynamic providers to capture secrets (#15864) 2024-08-02 23:51:52 +00:00
test_resource.py Fixing a few pylint errors in the python test folder (#16962) 2024-08-14 08:26:34 +00:00
test_runtime_to_json.py Use black to format lib/test (#16028) 2024-04-23 08:29:58 +00:00
test_stack_reference.py Fixing a few pylint errors in the python test folder (#16962) 2024-08-14 08:26:34 +00:00
test_stack_registers_outputs.py Fixing a few pylint errors in the python test folder (#16962) 2024-08-14 08:26:34 +00:00
test_translate_output_properties.py Start mypy linting lib/test (#16040) 2024-04-30 12:54:13 +00:00
test_types_input_type.py Fixing a few pylint errors in the python test folder (#16962) 2024-08-14 08:26:34 +00:00
test_types_input_type_types.py Start mypy linting lib/test (#16040) 2024-04-30 12:54:13 +00:00
test_types_output_type.py Fixing a few pylint errors in the python test folder (#16962) 2024-08-14 08:26:34 +00:00
test_types_resource_types.py Start mypy linting lib/test (#16040) 2024-04-30 12:54:13 +00:00
test_urn.py Use black to format lib/test (#16028) 2024-04-23 08:29:58 +00:00
test_utils.py Start mypy linting lib/test (#16040) 2024-04-30 12:54:13 +00:00