diff --git a/changelog/pending/20221206--sdk-dotnet-nodejs--add-inokesingle-variants-to-dotnet-and-nodejs-sdks.yaml b/changelog/pending/20221206--sdk-dotnet-nodejs--add-inokesingle-variants-to-dotnet-and-nodejs-sdks.yaml new file mode 100644 index 000000000000..cb47bcc7621f --- /dev/null +++ b/changelog/pending/20221206--sdk-dotnet-nodejs--add-inokesingle-variants-to-dotnet-and-nodejs-sdks.yaml @@ -0,0 +1,4 @@ +changes: +- type: feat + scope: sdk/dotnet,nodejs + description: Add InvokeSingle variants to dotnet and nodejs SDKs diff --git a/sdk/dotnet/Pulumi/Deployment/DeploymentInstance.cs b/sdk/dotnet/Pulumi/Deployment/DeploymentInstance.cs index 9bfa46b379fe..4577595ed216 100644 --- a/sdk/dotnet/Pulumi/Deployment/DeploymentInstance.cs +++ b/sdk/dotnet/Pulumi/Deployment/DeploymentInstance.cs @@ -50,6 +50,22 @@ internal DeploymentInstance(IDeployment deployment) public Output Invoke(string token, InvokeArgs args, InvokeOptions? options = null) => _deployment.Invoke(token, args, options); + /// + /// Dynamically invokes the function '', which is offered by a + /// provider plugin. + /// + /// The result of will be a resolved to the + /// result value of the provider plugin. + /// + /// Similar to the earlier , but supports passing input values + /// and returns an Output value. + /// + /// The inputs can be a bag of computed values(including, `T`s, + /// s, s etc.). + /// + public Output InvokeSingle(string token, InvokeArgs args, InvokeOptions? options = null) + => _deployment.InvokeSingle(token, args, options); + /// /// Dynamically invokes the function '', which is offered by a /// provider plugin. @@ -63,6 +79,19 @@ public Output Invoke(string token, InvokeArgs args, InvokeOptions? options public Task InvokeAsync(string token, InvokeArgs args, InvokeOptions? options = null) => _deployment.InvokeAsync(token, args, options); + /// + /// Dynamically invokes the function '', which is offered by a + /// provider plugin. + /// + /// The result of will be a resolved to the + /// result value of the provider plugin which is expected to be a dictionary with single value. + /// + /// The inputs can be a bag of computed values(including, `T`s, + /// s, s etc.). + /// + public Task InvokeSingleAsync(string token, InvokeArgs args, InvokeOptions? options = null) + => _deployment.InvokeSingleAsync(token, args, options); + /// /// Same as , however the /// return value is ignored. diff --git a/sdk/dotnet/Pulumi/Deployment/Deployment_Invoke.cs b/sdk/dotnet/Pulumi/Deployment/Deployment_Invoke.cs index 6e806391040c..b1303275a6e0 100644 --- a/sdk/dotnet/Pulumi/Deployment/Deployment_Invoke.cs +++ b/sdk/dotnet/Pulumi/Deployment/Deployment_Invoke.cs @@ -1,6 +1,7 @@ // Copyright 2016-2021, Pulumi Corporation using System; +using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; using System.Threading.Tasks; @@ -18,9 +19,21 @@ Task IDeployment.InvokeAsync(string token, InvokeArgs args, InvokeOptions? optio Task IDeployment.InvokeAsync(string token, InvokeArgs args, InvokeOptions? options) => InvokeAsync(token, args, options, convertResult: true); + async Task IDeployment.InvokeSingleAsync(string token, InvokeArgs args, InvokeOptions? options) + { + var outputs = await InvokeAsync>(token, args, options, convertResult: true); + return outputs.Values.First(); + } + Output IDeployment.Invoke(string token, InvokeArgs args, InvokeOptions? options) => new Output(RawInvoke(token, args, options)); + Output IDeployment.InvokeSingle(string token, InvokeArgs args, InvokeOptions? options) + { + var outputResult = new Output>(RawInvoke>(token, args, options)); + return outputResult.Apply(outputs => outputs.Values.First()); + } + private async Task> RawInvoke(string token, InvokeArgs args, InvokeOptions? options) { // This method backs all `Fn.Invoke()` calls that generate diff --git a/sdk/dotnet/Pulumi/Deployment/IDeployment.cs b/sdk/dotnet/Pulumi/Deployment/IDeployment.cs index 20e07ab9cf72..282af655a3ac 100644 --- a/sdk/dotnet/Pulumi/Deployment/IDeployment.cs +++ b/sdk/dotnet/Pulumi/Deployment/IDeployment.cs @@ -38,6 +38,18 @@ internal interface IDeployment /// Task InvokeAsync(string token, InvokeArgs args, InvokeOptions? options = null); + /// + /// Dynamically invokes the function '', which is offered by a + /// provider plugin. + /// + /// The result of will be a resolved to the + /// result value of the provider plugin that returns a bag of properties with a single value that is returned. + /// + /// The inputs can be a bag of computed values(including, `T`s, + /// s, s etc.). + /// + Task InvokeSingleAsync(string token, InvokeArgs args, InvokeOptions? options = null); + /// /// Dynamically invokes the function '', which is offered by a /// provider plugin. @@ -50,6 +62,18 @@ internal interface IDeployment /// Output Invoke(string token, InvokeArgs args, InvokeOptions? options = null); + /// + /// Dynamically invokes the function '', which is offered by a + /// provider plugin. + /// + /// The result of will be a resolved to the + /// result value of the provider plugin that returns a bag of properties with a single value that is returned. + /// + /// The inputs can be a bag of computed values(including, `T`s, + /// s, s etc.). + /// + Output InvokeSingle(string token, InvokeArgs args, InvokeOptions? options = null); + /// /// Same as , however the /// return value is ignored. diff --git a/sdk/dotnet/Pulumi/PublicAPI.Shipped.txt b/sdk/dotnet/Pulumi/PublicAPI.Shipped.txt index 9355ea57b3df..9d5dd36bb174 100644 --- a/sdk/dotnet/Pulumi/PublicAPI.Shipped.txt +++ b/sdk/dotnet/Pulumi/PublicAPI.Shipped.txt @@ -91,6 +91,7 @@ Pulumi.DeploymentInstance.Call(string token, Pulumi.CallArgs args, Pulumi.Resour Pulumi.DeploymentInstance.Call(string token, Pulumi.CallArgs args, Pulumi.Resource self = null, Pulumi.CallOptions options = null) -> Pulumi.Output Pulumi.DeploymentInstance.InvokeAsync(string token, Pulumi.InvokeArgs args, Pulumi.InvokeOptions options = null) -> System.Threading.Tasks.Task Pulumi.DeploymentInstance.InvokeAsync(string token, Pulumi.InvokeArgs args, Pulumi.InvokeOptions options = null) -> System.Threading.Tasks.Task +Pulumi.DeploymentInstance.InvokeSingleAsync(string token, Pulumi.InvokeArgs args, Pulumi.InvokeOptions options = null) -> System.Threading.Tasks.Task Pulumi.DeploymentInstance.IsDryRun.get -> bool Pulumi.DeploymentInstance.ProjectName.get -> string Pulumi.DeploymentInstance.StackName.get -> string @@ -395,4 +396,5 @@ static Pulumi.Urn.Create(Pulumi.Input name, Pulumi.Input type, P static readonly Pulumi.CallArgs.Empty -> Pulumi.CallArgs static readonly Pulumi.InvokeArgs.Empty -> Pulumi.InvokeArgs static readonly Pulumi.ResourceArgs.Empty -> Pulumi.ResourceArgs -Pulumi.DeploymentInstance.Invoke(string token, Pulumi.InvokeArgs args, Pulumi.InvokeOptions options = null) -> Pulumi.Output \ No newline at end of file +Pulumi.DeploymentInstance.Invoke(string token, Pulumi.InvokeArgs args, Pulumi.InvokeOptions options = null) -> Pulumi.Output +Pulumi.DeploymentInstance.InvokeSingle(string token, Pulumi.InvokeArgs args, Pulumi.InvokeOptions options = null) -> Pulumi.Output \ No newline at end of file diff --git a/sdk/nodejs/runtime/invoke.ts b/sdk/nodejs/runtime/invoke.ts index 3b278ed01b30..e60f31d190cc 100644 --- a/sdk/nodejs/runtime/invoke.ts +++ b/sdk/nodejs/runtime/invoke.ts @@ -74,6 +74,19 @@ export function invoke(tok: string, props: Inputs, opts: InvokeOptions = {}): Pr return invokeAsync(tok, props, opts); } +/* + * `invokeSingle` dynamically invokes the function, `tok`, which is offered by a provider plugin. + * Similar to `invoke`, but returns a single value instead of an object with a single key. + */ +export function invokeSingle(tok: string, props: Inputs, opts: InvokeOptions = {}): Promise { + return invokeAsync(tok, props, opts).then(outputs => { + // assume outputs have a single key + const keys = Object.keys(outputs); + // return the first key's value from the outputs + return outputs[keys[0]]; + }); +} + export async function streamInvoke( tok: string, props: Inputs,