pulumi/tests/integration/get_resource/python/__main__.py
Pat Gavlin 20f7720869
Add support for getResource to the Python SDK. (#5694)
Just what it says on the tin.

The SDK code generator will be updated to use the new `urn`
resource option inside of each module's implementation of
`ResourceModule.construct`.

Part of #2430.

Co-authored-by: Justin Van Patten <jvp@justinvp.com>
2020-11-20 13:13:23 -08:00

38 lines
968 B
Python

# Copyright 2016-2020, Pulumi Corporation. All rights reserved.
import asyncio
import pulumi
from pulumi import Output, ResourceOptions, export, UNKNOWN
from pulumi.dynamic import Resource, ResourceProvider, CreateResult
from pulumi.runtime import is_dry_run
class MyProvider(ResourceProvider):
def create(self, props):
return CreateResult("0", props)
class MyResource(Resource):
foo: Output
def __init__(self, name, props, opts = None):
super().__init__(MyProvider(), name, props, opts)
class GetResource(pulumi.Resource):
foo: Output
def __init__(self, urn):
props = {"foo": None}
super().__init__("unused", "unused:unused:unused", True, props, ResourceOptions(urn=urn), False, False)
a = MyResource("a", {
"foo": "foo",
})
async def check_get():
a_urn = await a.urn.future()
a_get = GetResource(a_urn)
a_foo = await a_get.foo.future()
assert a_foo == "foo"
export("o", check_get())