pulumi/sdk
bors[bot] c231ecd447
Merge #12639
12639: sdk/py: Propagate provider from local and remote component resources r=abhinav a=abhinav

Each commit is individually reviewable.
The first commit just re-applies #12292.

---

This change brings back #12292 (fix for #12161),
which was reverted in #12522 because it broke MLCs (#12520)
and corrects the issue that caused that failure.

- #12161 manifests as local component resources
  not propagating the `provider` option to their children
- #12520 manifests as remote component resources (MLCs)
  not propagating the `provider` option to their children

Roughly, given:

    class MyComponentResource:
      def __init__(self, ...):
        # ...
        self.child = aws.s3.Bucket(..., opts=ResourceOptions(parent=self))

    MyComponentResource(opts=ResourceOptions(provider=my_aws_provider))

Both bugs took the form of the `aws.s3.Bucket` above not getting
`my_aws_provider`.

We previously fixed #12161 by keeping using the provider for the
resource only if its package matched the resource's type; otherwise, we
placed it in the providers bag for the children of that resource.

This had the effect of dropping the provider for component resources
because:

- `_get_providers` returns a provider (None for component resources)
  and a bag of providers for children of the resource.
  It is stored on the resource:

  f76bd5463b/sdk/python/lib/pulumi/resource.py (L866)

- A request is made to `register_resource`, which calls
  `prepare_resource`:

  f76bd5463b/sdk/python/lib/pulumi/resource.py (L880-L882)
  f76bd5463b/sdk/python/lib/pulumi/runtime/resource.py (L811)

- `prepare_resource` re-interprets the `provider` and `providers`
  resource options, based on what's in the **original** `opts` struct
  completely ignoring the second result of `_get_providers`:

  f76bd5463b/sdk/python/lib/pulumi/runtime/resource.py (L210)

So in short, the reason the original change broke was:
It turned `provider=x` into `providers=[x]` when appropriate,
but the consuming code did not consume the transformed option.

To fix this, we put the bag of providers produced by `_get_providers`
back into the `opts` struct so that `prepare_resource` and friends can
use it.

Testing:
An integration test is added that defines an MLC,
and uses it from Pulumi programs in Go, Python, and Node
that instantiate the MLC with no provider, provider option, and providers option,
and verifies that resources were instantiated with the correct providers.

Resolves #12593
Resolves #12161


Co-authored-by: Abhinav Gupta <abhinav@pulumi.com>
2023-04-14 16:29:48 +00:00
..
go Merge #12157 2023-04-14 00:42:27 +00:00
nodejs [sdk/nodejs] Upgrade json5 2023-04-10 12:31:34 -07:00
proto/go Add mapping service to converter 2023-03-24 17:09:17 +00:00
python sdk/py/Resource: Don't drop merged providers 2023-04-13 18:12:20 -07:00
README.md Cleanup sdk/README.md 2023-01-03 17:12:12 -05:00
go.mod Bump go-git to v5.6.0 to remove cgo dependency fixing 2023-02-28 16:01:31 -08:00
go.sum Bump go-git to v5.6.0 to remove cgo dependency fixing 2023-02-28 16:01:31 -08:00

README.md

Pulumi Language SDKs

This directory contains Pulumi SDKs for the following languages:

See the respective READMEs for information about installing and using these libraries.

The language providers work by implementing gRPC interfaces defined in the top level directory proto.