async def test_unwrap_input_type_dict(self): x = Output.from_input( OutputFromInputTests.FooArgs( baz={"hello": Output.from_input("world")})) x_val = cast(OutputFromInputTests.FooArgs, await x.future()) self.assertIsInstance(x_val, OutputFromInputTests.FooArgs) self.assertEqual(x_val.baz, {"hello": "world"})
async def test_unwrap_input_type_nested(self): nested = OutputFromInputTests.NestedArgs( hello=Output.from_input("world")) x = Output.from_input(OutputFromInputTests.FooArgs(nested=nested)) x_val = cast(OutputFromInputTests.FooArgs, await x.future()) self.assertIsInstance(x_val, OutputFromInputTests.FooArgs) self.assertIsInstance(x_val.nested, OutputFromInputTests.NestedArgs) self.assertEqual(x_val.nested.hello, "world")
def __init__(self, name: str, inputs: Inputs, opts: Optional[ResourceOptions] = None): super().__init__('testcomponent:index:Component', name, {}, opts) Output.from_input(inputs['message']).apply( lambda v: panic("should not run (message)")) Output.from_input( inputs['nested']).apply(lambda v: panic("should not run (nested)"))
async def test_deeply_nested_objects(self): o1 = { "a": { "a": { "a": { "a": { "a": { "a": { "a": { "a": { "a": { "a": { "a": Output.from_input("a") } } } } } } } } } } } o2 = { "a": { "a": { "a": { "a": { "a": { "a": { "a": { "a": { "a": { "a": { "a": "a" } } } } } } } } } } } x = Output.from_input(o1) x_val = await x.future() self.assertEqual(x_val, o2)
def eks_role_policy(oidc_provider, namespace, service_account): return Output.from_input( { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Federated": oidc_provider.arn, }, "Action": "sts:AssumeRoleWithWebIdentity", "Condition": { "StringEquals": { Output.concat(oidc_provider.url, ":sub"): Output.concat( "system:serviceaccount:", namespace, ":", service_account, ) } }, } ], } ).apply(json.dumps)
async def test_lifted_unknown(self): settings.SETTINGS.dry_run = True fut = asyncio.Future() fut.set_result(UNKNOWN) out = Output.from_input({ "foo": "foo", "bar": UNKNOWN, "baz": fut}) self.assertFalse(await out.is_known()) r1 = out["foo"] self.assertTrue(await r1.is_known()) self.assertEqual(await r1.future(with_unknowns=True), "foo") r2 = out["bar"] self.assertFalse(await r2.is_known()) self.assertEqual(await r2.future(with_unknowns=True), UNKNOWN) r3 = out["baz"] self.assertFalse(await r3.is_known()) self.assertEqual(await r3.future(with_unknowns=True), UNKNOWN) r4 = out["baz"]["qux"] self.assertFalse(await r4.is_known()) self.assertEqual(await r4.future(with_unknowns=True), UNKNOWN) out = Output.from_input([ "foo", UNKNOWN ]) r5 = out[0] self.assertTrue(await r5.is_known()) self.assertEqual(await r5.future(with_unknowns=True), "foo") r6 = out[1] self.assertFalse(await r6.is_known()) self.assertEqual(await r6.future(with_unknowns=True), UNKNOWN) out = Output.all(Output.from_input("foo"), Output.from_input(UNKNOWN), Output.from_input([ Output.from_input(UNKNOWN), Output.from_input("bar") ])) self.assertFalse(await out.is_known()) r7 = out[0] self.assertTrue(await r7.is_known()) self.assertEqual(await r7.future(with_unknowns=True), "foo") r8 = out[1] self.assertFalse(await r8.is_known()) self.assertEqual(await r8.future(with_unknowns=True), UNKNOWN) r9 = out[2] self.assertFalse(await r9.is_known()) r10 = r9[0] self.assertFalse(await r10.is_known()) self.assertEqual(await r10.future(with_unknowns=True), UNKNOWN) r11 = r9[1] self.assertTrue(await r11.is_known()) self.assertEqual(await r11.future(with_unknowns=True), "bar")
async def test_output_all_failure_mixed_inputs(self): res = FakeCustomResource("some-resource") fut = asyncio.Future() fut.set_result(42) known_fut = asyncio.Future() known_fut.set_result(True) out = Output({res}, fut, known_fut) other = Output.from_input(99) self.assertRaises(ValueError, Output.all, out, other=other) self.assertRaisesRegex( ValueError, "Output.all() was supplied a mix of named and unnamed inputs")
async def test_output_all(self): res = TestCustomResource("some-resource") fut = asyncio.Future() fut.set_result(42) known_fut = asyncio.Future() known_fut.set_result(True) out = Output({res}, fut, known_fut) other = Output.from_input(99) combined = Output.all(out, other) deps = [] prop = await rpc.serialize_property(combined, deps) self.assertListEqual(deps, [res]) self.assertEqual([42, 99], prop)
async def test_output_all(self): res = FakeCustomResource("some-resource") fut = asyncio.Future() fut.set_result(42) known_fut = asyncio.Future() known_fut.set_result(True) out = Output({res}, fut, known_fut) other = Output.from_input(99) combined = Output.all(out, other) combined_dict = Output.all(out=out, other=other) deps = [] prop = await rpc.serialize_property(combined, deps) prop_dict = await rpc.serialize_property(combined_dict, deps) self.assertSetEqual(set(deps), {res}) self.assertEqual([42, 99], prop) self.assertEqual({"out": 42, "other": 99}, prop_dict)
def test_cross_project_registry(): bucket_name = "my-bucketname" target_project_number = "target_project_number" args = CrossProjectCloudRunAccessArgs( bucket_name, Output.from_input(target_project_number) ) cloud_run_access = CrossProjectCloudRunAccess( "my-cloudrun-cross-registry-access", args, None ) def test_properties(args): observed_bucket_name, observed_member = args assert observed_bucket_name == bucket_name assert observed_member == _cloudrun_service_account(target_project_number) return Output.all( cloud_run_access.bucket_policy.bucket, cloud_run_access.bucket_policy.member ).apply(test_properties)
def transform(args: ResourceTransformationArgs): print("res4 transformation") if args.name.endswith("-child2"): # Resolve the child2 promise with the child2 resource. child2_future.set_result(args.resource) return None elif args.name.endswith("-child1"): # Overwrite the `input` to child2 with a dependency on the `output2` from child1. async def getOutput2(input): if input != "hello": # Not strictly necessary - but shows we can confirm invariants we expect to be # true. raise Exception("unexpected input value") child2 = await child2_future return child2.output2 child2_input = Output.from_input( args.props["input"]).apply(getOutput2) # Finally - overwrite the input of child2. return ResourceTransformationResult(props={ **args.props, "input": child2_input }, opts=args.opts)
class MyProvider(ResourceProvider): def create(self, props): return CreateResult("0", props) class MyResource(Resource): foo: Output bar: Output baz: Output def __init__(self, name, props, opts=None): super().__init__(MyProvider(), name, props, opts) unknown = Output.from_input(UNKNOWN if is_dry_run() else "foo") a = MyResource( "a", { "foo": "foo", "bar": { "value": "foo", "unknown": unknown }, "baz": ["foo", unknown], }) async def check_knowns(): assert await a.foo.is_known() assert await a.bar["value"].is_known()
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from pulumi import Output, CustomResource class MyResource(CustomResource): nested_numbers: Output[dict] def __init__(self, name): CustomResource.__init__(self, "test:index:MyResource", name, { "nested_numbers": None, }) class SumResource(CustomResource): sum: Output[int] def __init__(self, name, sum): CustomResource.__init__(self, "test:index:SumResource", name, { "sum": sum, }) res1 = MyResource("testResource1") res2 = MyResource("testResource2") sum = Output.from_input( res1.nested_numbers).apply(lambda d: d["foo"]["bar"] + d["baz"]) sumRes = SumResource("sumResource", sum)
async def test_unwrap_list_list(self): x = Output.from_input(["hello", ["foo", Output.from_input("bar")]]) x_val = await x.future() self.assertEqual(x_val, ["hello", ["foo", "bar"]])
async def test_unwrap_list_dict(self): x = Output.from_input(["hello", {"foo": Output.from_input("bar")}]) x_val = await x.future() self.assertEqual(x_val, ["hello", {"foo": "bar"}])
async def test_no_iter(self): x = Output.from_input([1, 2, 3]) with self.assertRaises(TypeError): for i in x: print(i)
async def test_unwrap_list(self): x = Output.from_input(["hello", Output.from_input("world")]) x_val = await x.future() self.assertEqual(x_val, ["hello", "world"])
"mylambda-role", assume_role_policy=instance_assume_role_policy.json, ) policy = aws.iam.RolePolicy( "mylambda-policy", role=role, policy=Output.from_input({ "Version": "2012-10-17", "Statement": [{ "Action": [ "dynamodb:UpdateItem", "dynamodb:PutItem", "dynamodb:GetItem", "dynamodb:DescribeTable" ], "Resource": counter_table.arn, "Effect": "Allow", }, { "Action": ["logs:*", "cloudwatch:*"], "Resource": "*", "Effect": "Allow", }], }), ) # Read the config of whether to provision fixed concurrency for Lambda config = pulumi.Config() provisioned_concurrent_executions = config.get_float('provisionedConcurrency') # Create a Lambda function, using code from the `./app` folder.
async def test_unwrap_empty_list(self): x = Output.from_input([]) x_val = await x.future() self.assertEqual(x_val, [])
# Copyright 2016-2020, Pulumi Corporation. All rights reserved. from pulumi import export, Input, Output, ResourceOptions from pulumi.dynamic import Resource, ResourceProvider, CreateResult class Provider(ResourceProvider): def create(self, props): return CreateResult("1", {"prefix": props["prefix"]}) class R(Resource): prefix: Output[str] def __init__(self, name, prefix: Input[str], opts: ResourceOptions = None): super().__init__(Provider(), name, {"prefix": prefix}, opts) without_secret = R("without_secret", prefix=Output.from_input("it's a secret to everybody")) with_secret = R("with_secret", prefix=Output.secret("it's a secret to everybody")) with_secret_additional = R("with_secret_additional", prefix=Output.from_input("it's a secret to everybody"), opts=ResourceOptions(additional_secret_outputs=["prefix"])) export("withoutSecret", without_secret) export("withSecret", with_secret) export("withSecretAdditional", with_secret_additional)
async def test_unwrap_input_type_list(self): x = Output.from_input( OutputFromInputTests.FooArgs(bar=["a", Output.from_input("b")])) x_val = cast(OutputFromInputTests.FooArgs, await x.future()) self.assertIsInstance(x_val, OutputFromInputTests.FooArgs) self.assertEqual(x_val.bar, ["a", "b"])
async def test_unwrap_input_type(self): x = Output.from_input( OutputFromInputTests.FooArgs(foo=Output.from_input("bar"))) x_val = cast(OutputFromInputTests.FooArgs, await x.future()) self.assertIsInstance(x_val, OutputFromInputTests.FooArgs) self.assertEqual(x_val.foo, "bar")
# Read in some configurable settings for our cluster: config = Config(None) # nodeCount is the number of cluster nodes to provision. Defaults to 3 if unspecified. NODE_COUNT = config.get('node_count') or 3 # nodeMachineType is the machine type to use for cluster nodes. Defaults to n1-standard-1 if unspecified. # See https://cloud.google.com/compute/docs/machine-types for more details on available machine types. NODE_MACHINE_TYPE = config.get('node_machine_type') or 'n1-standard-1' # username is the admin username for the cluster. USERNAME = config.get('username') or 'admin' # password is the password for the admin user in the cluster. PASSWORD = config.get_secret('password') or RandomString( "password", length=20, special=True).result engine_version = Output.from_input(get_engine_versions()).latest_master_version # Now, actually create the GKE cluster. k8s_cluster = Cluster( 'gke-cluster', initial_node_count=NODE_COUNT, node_version=engine_version, min_master_version=engine_version, master_auth={ 'username': USERNAME, 'password': PASSWORD }, node_config={ 'machine_type': NODE_MACHINE_TYPE, 'oauth_scopes': [
async def test_unwrap_empty_dict(self): x = Output.from_input({}) x_val = await x.future() self.assertEqual(x_val, {})
class FinalResource(CustomResource): number: Output[str] def __init__(self, name, number): CustomResource.__init__(self, "test:index:FinalResource", name, { "number": number, }) def assert_eq(lhs, rhs): assert lhs == rhs res1 = MyResource("testResource1") res2 = MyResource("testResource2") res1.number.apply(lambda n: assert_eq(n, 2)) res2.number.apply(lambda n: assert_eq(n, 3)) # Output.all combines a list of outputs into an output of a list. resSum = Output.all(res1.number, res2.number).apply(lambda l: l[0] + l[1]) FinalResource("testResource3", resSum) # Test additional Output helpers hello_world = Output.concat( "Hello ", Output.from_input("world!")).apply(lambda s: assert_eq(s, "Hello world!")) export("helloworld", hello_world)
async def test_unwrap_dict_secret(self): x = Output.from_input({"hello": Output.secret("world")}) x_val = await x.future() self.assertEqual(x_val, {"hello": "world"})
vpc = ec2.Vpc('test', cidr_block="10.11.0.0/16", enable_dns_hostnames=True, enable_dns_support=True) internet_gateway = ec2.InternetGateway('test', vpc_id=vpc.id) route_table = ec2.RouteTable('test', vpc_id=vpc.id, routes=[ ec2.RouteTableRouteArgs( cidr_block="0.0.0.0/0", gateway_id=internet_gateway.id) ]) zones = Output.from_input(get_availability_zones()) zone_names = zones.apply(lambda zs: zs.names) subnet0 = ec2.Subnet( "test0", vpc_id=vpc.id, availability_zone=zone_names.apply(lambda names: names[0]), cidr_block="10.11.0.0/24", map_public_ip_on_launch=True) subnet1 = ec2.Subnet( "test1", vpc_id=vpc.id, availability_zone=zone_names.apply(lambda names: names[1]), cidr_block="10.11.1.0/24", map_public_ip_on_launch=True)
async def test_unwrap_dict_list(self): x = Output.from_input({"hello": ["foo", Output.from_input("bar")]}) x_val = await x.future() self.assertEqual(x_val, {"hello": ["foo", "bar"]})
def __init__(self, urn): self.__dict__["urn"] = Output.from_input(urn)
async def test_attr(self): o = Output.from_input(Obj("hello")) x = o.x x_val = await x.future() self.assertEqual(x_val, "hello")