def do_invoke(): value = invoke("test:index:MyFunction", props={ "value": 41, "value2": get_value2() }).value return value["value"]
async def do_invoke(): await asyncio.sleep(0) value = invoke("test:index:MyFunction", props={"value": 41}).value return value["value"]
from pulumi.runtime import invoke class MyResource(CustomResource): value: Output[str] def __init__(self, name, value, opts): CustomResource.__init__(self, "test:index:MyResource", name, props={ "value": value, }, opts=opts) # We run this invoke first because of the way in which it interacts with the RPC manager. Prior to #3170, the RPC # manager would decide that all outstanding RPCs had finished on any non-zero -> zero transition in the number of # outstanding RPCs. Because an invoke is considered an RPC, running any synchronous invokes before any other RPC # would confuse this logic, which would cause us to drop exceptions that occurred during subsequent RPCs and # incorrectly consider failed programs to have succeeded. invoke("test:index:MyFunction", props={}) resA = MyResource("resourceA", "foo", None) fut = asyncio.Future() fut.set_exception(Exception("oh no")) resB = MyResource("resourceB", fut, ResourceOptions(depends_on=[resA])) resC = MyResource("resourceC", "baz", ResourceOptions(depends_on=[resB]))
# Copyright 2016-2018, Pulumi Corporation. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # 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 CustomResource, ResourceOptions, InvokeOptions from pulumi.runtime import invoke class MyResource(CustomResource): def __init__(self, name, version=None): CustomResource.__init__(self, "test:index:MyResource", name, opts=ResourceOptions(version=version)) res = MyResource("testres", version="0.19.1") res2 = MyResource("testres2", version="0.19.2") res3 = MyResource("testres3") invoke("test:index:doit", {}, opts=InvokeOptions(version="0.19.1")) invoke("test:index:doit_v2", {}, opts=InvokeOptions(version="0.19.2")) invoke("test:index:doit_no_version", {})
# distributed under the License is distributed on an "AS IS" BASIS, # 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 CustomResource, Output, log from pulumi.runtime import invoke def assert_eq(l, r): assert l == r class MyResource(CustomResource): value: Output[int] def __init__(self, name, value): CustomResource.__init__(self, "test:index:MyResource", name, props={ "value": value, }) value = invoke("test:index:MyFunction", props={ "value": 41, }) async def do_invoke(): value = await invoke("test:index:MyFunction", props={"value": 41}) return value["value"] res = MyResource("resourceA", do_invoke()) res.value.apply(lambda v: assert_eq(v, 42))
def do_provider_invoke_with_parent(parent): value = invoke("test:index:MyFunctionWithParent", props={"value": 41}, opts=InvokeOptions(parent=parent)).value return value["value"]
def do_provider_invoke(): value = invoke("test:index:MyFunction", props={"value": 9000}, opts=InvokeOptions(provider=prov)).value return value["value"]