Support returning inner resource references
This commit is contained in:
parent
b3a20dfe47
commit
e2d6058d2e
|
@ -12,7 +12,15 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
import pulumi
|
||||
from pulumi_aws import ec2
|
||||
|
||||
from mycomponent.python import MyComponent, MyComponentArgs
|
||||
# pulumi.runtime.register_proxy_constructor("aws:ec2/securityGroup:SecurityGroup", ec2.SecurityGroup);
|
||||
|
||||
MyComponent("n", input1=42)
|
||||
from mycomponent.python import MyComponent
|
||||
|
||||
res = MyComponent("n", input1=42)
|
||||
|
||||
pulumi.export("id2", res.myid)
|
||||
pulumi.export("output1", res.output1)
|
||||
pulumi.export("innerComponent", res.innerComponent.data)
|
||||
pulumi.export("nodeSecurityGroupId", res.nodeSecurityGroup)
|
||||
|
|
|
@ -14,21 +14,34 @@
|
|||
|
||||
import asyncio
|
||||
from pulumi import ComponentResource, CustomResource, Output, InvokeOptions, ResourceOptions, log, Input
|
||||
from pulumi.runtime import register_proxy_constructor
|
||||
from typing import Callable, Any, Dict, List, Optional
|
||||
from pulumi_aws import ec2
|
||||
|
||||
from .remote import construct
|
||||
|
||||
class MyComponentArgs:
|
||||
input1: Input[int]
|
||||
def __init__(self,
|
||||
input1: Input[int]) -> None:
|
||||
self.input1 = input1
|
||||
class MyInnerComponent(ComponentResource):
|
||||
data: Output[str]
|
||||
def __init__(__self__, resource_name: str, opts: Optional[ResourceOptions]=None, xxx=None) -> None:
|
||||
__props__ = dict()
|
||||
if opts is None or opts.urn is None:
|
||||
async def do_construct():
|
||||
r = await construct("..", "MyInnerComponent", resource_name, __props__, opts)
|
||||
return r["urn"]
|
||||
urn = asyncio.ensure_future(do_construct())
|
||||
opts = ResourceOptions.merge(opts, ResourceOptions(urn=urn))
|
||||
props = {
|
||||
"data": None,
|
||||
}
|
||||
super().__init__("my:mod:MyInnerComponent", resource_name, props, opts)
|
||||
|
||||
register_proxy_constructor("my:mod:MyInnerComponent", lambda name, opts: MyInnerComponent(name, ResourceOptions(**opts)))
|
||||
|
||||
class MyComponent(ComponentResource):
|
||||
myid: Output[str]
|
||||
output1: Output[int]
|
||||
# innerComponent: MyInnerComponent
|
||||
# nodeSecurityGroup: SecurityGroup
|
||||
innerComponent: MyInnerComponent
|
||||
nodeSecurityGroup: ec2.SecurityGroup
|
||||
def __init__(__self__, resource_name: str, opts: Optional[ResourceOptions]=None, input1=None) -> None:
|
||||
__props__ = dict()
|
||||
__props__["input1"] = input1
|
||||
|
@ -46,7 +59,6 @@ class MyComponent(ComponentResource):
|
|||
"nodeSecurityGroup": None,
|
||||
}
|
||||
super().__init__("my:mod:MyComponent", resource_name, props, opts)
|
||||
|
||||
|
||||
register_proxy_constructor("my:mod:MyComponent", MyComponent)
|
||||
|
||||
|
|
@ -44,3 +44,7 @@ from .stack import (
|
|||
from .invoke import (
|
||||
invoke,
|
||||
)
|
||||
|
||||
from .rpc import (
|
||||
register_proxy_constructor,
|
||||
)
|
||||
|
|
|
@ -356,7 +356,8 @@ def _get_resource(res: 'Resource', ty: str, name: str, custom: bool, props: 'Inp
|
|||
f"exception when preparing or executing rpc: {traceback.format_exc()}")
|
||||
rpc.resolve_outputs_due_to_exception(resolvers, exn)
|
||||
resolve_urn_exn(exn)
|
||||
resolve_id(None, False, exn)
|
||||
if custom:
|
||||
resolve_id(None, False, exn)
|
||||
raise
|
||||
|
||||
log.debug(f"resource read successful: ty={ty}, urn={resp['urn']}")
|
||||
|
|
|
@ -250,7 +250,7 @@ def deserialize_properties(props_struct: struct_pb2.Struct, keep_unknowns: Optio
|
|||
proxy_constructor = PROXY_CONSTRUCTORS.get(typ, None)
|
||||
if proxy_constructor is not None:
|
||||
urn_name = urn_parts[3]
|
||||
return proxy_constructor(urn_name, {}, { 'urn': urn })
|
||||
return proxy_constructor(urn_name, { 'urn': urn })
|
||||
print(f"Saw valid URN {urn} during deserialization, but no proxy constructor is registered for type {typ}.")
|
||||
return urn
|
||||
|
||||
|
|
Loading…
Reference in a new issue