Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
tests/integration/resource_refs_get_resource/python/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
*.pyc | ||
/.pulumi/ | ||
/dist/ | ||
/*.egg-info | ||
venv/ |
3 changes: 3 additions & 0 deletions
3
tests/integration/resource_refs_get_resource/python/Pulumi.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name: resource_refs_get_resource_py | ||
description: A program that ensures invoking 'pulumi:pulumi:getResource' returns resource refs | ||
runtime: python |
93 changes: 93 additions & 0 deletions
93
tests/integration/resource_refs_get_resource/python/__main__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# Copyright 2016-2022, Pulumi Corporation. All rights reserved. | ||
|
||
from typing import Optional | ||
|
||
import pulumi | ||
|
||
|
||
class Child(pulumi.ComponentResource): | ||
@pulumi.input_type | ||
class ChildArgs: | ||
pass | ||
|
||
def __init__( | ||
self, | ||
resource_name: str, | ||
message: Optional[str] = None, | ||
opts: Optional[pulumi.ResourceOptions] = None, | ||
): | ||
props = Container.ContainerArgs.__new__(Container.ContainerArgs) | ||
props.__dict__["message"] = message | ||
super().__init__("test:index:Child", resource_name, props, opts) | ||
if opts and opts.urn: | ||
return | ||
self.register_outputs({ "message": message }) | ||
|
||
@property | ||
@pulumi.getter | ||
def message(self) -> pulumi.Output[str]: | ||
return pulumi.get(self, "message") | ||
|
||
|
||
class Container(pulumi.ComponentResource): | ||
@pulumi.input_type | ||
class ContainerArgs: | ||
pass | ||
|
||
def __init__( | ||
self, | ||
resource_name: str, | ||
child: Optional[Child] = None, | ||
opts: Optional[pulumi.ResourceOptions] = None, | ||
): | ||
props = Container.ContainerArgs.__new__(Container.ContainerArgs) | ||
props.__dict__["child"] = child | ||
super().__init__("test:index:Container", resource_name, props, opts) | ||
if opts and opts.urn: | ||
return | ||
self.register_outputs({ "child": child }) | ||
|
||
@property | ||
@pulumi.getter | ||
def child(self) -> pulumi.Output[Child]: | ||
return pulumi.get(self, "child") | ||
|
||
|
||
class Module(pulumi.runtime.ResourceModule): | ||
def version(self): | ||
return "0.0.1" | ||
|
||
def construct(self, name: str, typ: str, urn: str) -> pulumi.Resource: | ||
if typ == "test:index:Child": | ||
return Child(name, opts=pulumi.ResourceOptions(urn=urn)) | ||
else: | ||
raise Exception(f"unknown resource type {typ}") | ||
|
||
|
||
pulumi.runtime.register_resource_module("test", "index", Module()) | ||
|
||
|
||
child = Child("mychild", message="hello world!") | ||
container = Container("mycontainer", child=child) | ||
|
||
|
||
def assert_equal(args): | ||
expected_urn = args["expected_urn"] | ||
actual_urn = args["actual_urn"] | ||
actual_message = args["actual_message"] | ||
assert expected_urn == actual_urn, \ | ||
f"expected urn '{expected_urn}' not equal to actual urn '{actual_urn}'" | ||
assert "hello world!" == actual_message, \ | ||
f"expected message 'hello world!' not equal to actual message '{actual_message}'" | ||
|
||
|
||
def round_trip(urn: str): | ||
round_tripped_container = Container("mycontainer", opts=pulumi.ResourceOptions(urn=urn)) | ||
pulumi.Output.all( | ||
expected_urn=child.urn, | ||
actual_urn=round_tripped_container.child.urn, | ||
actual_message=round_tripped_container.child.message, | ||
).apply(assert_equal) | ||
|
||
|
||
container.urn.apply(round_trip) |
Empty file.