[sdk/dotnet] Support for calling methods (#7582)

This commit is contained in:
Justin Van Patten 2021-08-24 20:17:05 -07:00 committed by GitHub
parent bee803a970
commit 8112872b61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 1190 additions and 1 deletions

View file

@ -10,6 +10,9 @@
easier to compose functions/datasources with Pulumi resources.
[#7784](https://github.com/pulumi/pulumi/pull/7784)
- [sdk/dotnet] - Support for calling methods.
[#7582](https://github.com/pulumi/pulumi/pull/7582)
### Bug Fixes
- [cli] - Avoid `missing go.sum entry for module` for new Go projects.

View file

@ -0,0 +1,28 @@
// Copyright 2016-2021, Pulumi Corporation
namespace Pulumi
{
/// <summary>
/// Options to help control the behavior of <see cref="Deployment.Call{T}"/>.
/// </summary>
public class CallOptions
{
/// <summary>
/// An optional parent to use for default options for this call (e.g. the default provider
/// to use).
/// </summary>
public Resource? Parent { get; set; }
/// <summary>
/// An optional provider to use for this call. If no provider is supplied, the default
/// provider for the called function's package will be used.
/// </summary>
public ProviderResource? Provider { get; set; }
/// <summary>
/// An optional version, corresponding to the version of the provider plugin that should be
/// used when performing this call.
/// </summary>
public string? Version { get; set; }
}
}

View file

@ -8,7 +8,7 @@ namespace Pulumi
public sealed class DeploymentInstance : IDeployment
{
private readonly IDeployment _deployment;
internal DeploymentInstance(IDeployment deployment)
{
_deployment = deployment;
@ -49,6 +49,25 @@ namespace Pulumi
public Task InvokeAsync(string token, InvokeArgs args, InvokeOptions? options = null)
=> _deployment.InvokeAsync(token, args, options);
/// <summary>
/// Dynamically calls the function '<paramref name="token"/>', which is offered by a
/// provider plugin.
/// <para/>
/// The result of <see cref="Call{T}"/> will be a <see cref="Output{T}"/> resolved to the
/// result value of the provider plugin.
/// <para/>
/// The <paramref name="args"/> inputs can be a bag of computed values(including, `T`s,
/// <see cref="Task{TResult}"/>s, <see cref="Output{T}"/>s etc.).
/// </summary>
public Output<T> Call<T>(string token, CallArgs args, Resource? self = null, CallOptions? options = null)
=> _deployment.Call<T>(token, args, self, options);
/// <summary>
/// Same as <see cref="Call{T}"/>, however the return value is ignored.
/// </summary>
public void Call(string token, CallArgs args, Resource? self = null, CallOptions? options = null)
=> _deployment.Call(token, args, self, options);
internal IDeploymentInternal Internal => (IDeploymentInternal)_deployment;
}
}

View file

@ -0,0 +1,138 @@
// Copyright 2016-2021, Pulumi Corporation
using System;
using System.Collections.Immutable;
using System.Threading.Tasks;
using Google.Protobuf.WellKnownTypes;
using Pulumi.Serialization;
using Pulumirpc;
namespace Pulumi
{
public sealed partial class Deployment
{
void IDeployment.Call(string token, CallArgs args, Resource? self, CallOptions? options)
=> Call<object>(token, args, self, options, convertResult: false);
Output<T> IDeployment.Call<T>(string token, CallArgs args, Resource? self, CallOptions? options)
=> Call<T>(token, args, self, options, convertResult: true);
private Output<T> Call<T>(string token, CallArgs args, Resource? self, CallOptions? options, bool convertResult)
=> new Output<T>(CallAsync<T>(token, args, self, options, convertResult));
private async Task<OutputData<T>> CallAsync<T>(
string token, CallArgs args, Resource? self, CallOptions? options, bool convertResult)
{
var (result, deps) = await CallRawAsync(token, args, self, options).ConfigureAwait(false);
if (convertResult)
{
var converted = Converter.ConvertValue<T>($"{token} result", new Value { StructValue = result });
return new OutputData<T>(deps, converted.Value, converted.IsKnown, converted.IsSecret);
}
return new OutputData<T>(ImmutableHashSet<Resource>.Empty, default!, isKnown: true, isSecret: false);
}
private async Task<(Struct Return, ImmutableHashSet<Resource> Dependencies)> CallRawAsync(
string token, CallArgs args, Resource? self, CallOptions? options)
{
var label = $"Calling function: token={token} asynchronously";
Log.Debug(label);
// Be resilient to misbehaving callers.
// ReSharper disable once ConstantNullCoalescingCondition
args ??= CallArgs.Empty;
// Wait for all values to be available, and then perform the RPC.
var argsDict = await args.ToDictionaryAsync().ConfigureAwait(false);
// If we have a self arg, include it in the args.
if (self != null)
{
argsDict = argsDict.SetItem("__self__", self);
}
var (serialized, argDependencies) = await SerializeFilteredPropertiesAsync(
$"call:{token}",
argsDict, _ => true, keepResources: true).ConfigureAwait(false);
Log.Debug($"Call RPC prepared: token={token}" +
(_excessiveDebugOutput ? $", obj={serialized}" : ""));
// Determine the provider and version to use.
ProviderResource? provider;
string? version;
if (self != null)
{
provider = self._provider;
version = self._version;
}
else
{
provider = GetProvider(token, options);
version = options?.Version;
}
var providerReference = await ProviderResource.RegisterAsync(provider).ConfigureAwait(false);
// Create the request.
var request = new CallRequest
{
Tok = token,
Provider = providerReference ?? "",
Version = version ?? "",
Args = serialized,
};
// Add arg dependencies to the request.
foreach (var (argName, directDependencies) in argDependencies)
{
var urns = await GetAllTransitivelyReferencedResourceUrnsAsync(directDependencies).ConfigureAwait(false);
var deps = new CallRequest.Types.ArgumentDependencies();
deps.Urns.AddRange(urns);
request.ArgDependencies.Add(argName, deps);
}
// Kick off the call.
var result = await Monitor.CallAsync(request).ConfigureAwait(false);
// Handle failures.
if (result.Failures.Count > 0)
{
var reasons = "";
foreach (var reason in result.Failures)
{
if (reasons != "")
{
reasons += "; ";
}
reasons += $"{reason.Reason} ({reason.Property})";
}
throw new CallException($"Call of '{token}' failed: {reasons}");
}
// Unmarshal return dependencies.
var dependencies = ImmutableHashSet.CreateBuilder<Resource>();
foreach (var (_, returnDependencies) in result.ReturnDependencies)
{
foreach (var urn in returnDependencies.Urns)
{
dependencies.Add(new DependencyResource(urn));
}
}
return (result.Return, dependencies.ToImmutable());
}
private static ProviderResource? GetProvider(string token, CallOptions? options)
=> options?.Provider ?? options?.Parent?.GetProvider(token);
private sealed class CallException : Exception
{
public CallException(string error)
: base(error)
{
}
}
}
}

View file

@ -24,6 +24,9 @@ namespace Pulumi
public async Task<InvokeResponse> InvokeAsync(InvokeRequest request)
=> await this._client.InvokeAsync(request);
public async Task<CallResponse> CallAsync(CallRequest request)
=> await this._client.CallAsync(request);
public async Task<ReadResourceResponse> ReadResourceAsync(Resource resource, ReadResourceRequest request)
=> await this._client.ReadResourceAsync(request);

View file

@ -38,5 +38,23 @@ namespace Pulumi
/// return value is ignored.
/// </summary>
Task InvokeAsync(string token, InvokeArgs args, InvokeOptions? options = null);
/// <summary>
/// Dynamically calls the function '<paramref name="token"/>', which is offered by a
/// provider plugin. <see cref="Call{T}"/> returns immediately while the operation takes
/// place asynchronously in the background, similar to Resource constructors.
/// <para/>
/// The result of <see cref="Call{T}"/> will be a <see cref="Output{T}"/> resolved to the
/// result value of the provider plugin.
/// <para/>
/// The <paramref name="args"/> inputs can be a bag of computed values(including, `T`s,
/// <see cref="Task{TResult}"/>s, <see cref="Output{T}"/>s etc.).
/// </summary>
Output<T> Call<T>(string token, CallArgs args, Resource? self = null, CallOptions? options = null);
/// <summary>
/// Same as <see cref="Call{T}"/>, however the return value is ignored.
/// </summary>
void Call(string token, CallArgs args, Resource? self = null, CallOptions? options = null);
}
}

View file

@ -10,6 +10,8 @@ namespace Pulumi
Task<SupportsFeatureResponse> SupportsFeatureAsync(SupportsFeatureRequest request);
Task<InvokeResponse> InvokeAsync(InvokeRequest request);
Task<CallResponse> CallAsync(CallRequest request);
Task<ReadResourceResponse> ReadResourceAsync(Resource resource, ReadResourceRequest request);

View file

@ -21,6 +21,16 @@ Pulumi.Asset
Pulumi.AssetArchive
Pulumi.AssetArchive.AssetArchive(System.Collections.Generic.IDictionary<string, Pulumi.AssetOrArchive> assets) -> void
Pulumi.AssetOrArchive
Pulumi.CallArgs
Pulumi.CallArgs.CallArgs() -> void
Pulumi.CallOptions
Pulumi.CallOptions.CallOptions() -> void
Pulumi.CallOptions.Parent.get -> Pulumi.Resource
Pulumi.CallOptions.Parent.set -> void
Pulumi.CallOptions.Provider.get -> Pulumi.ProviderResource
Pulumi.CallOptions.Provider.set -> void
Pulumi.CallOptions.Version.get -> string
Pulumi.CallOptions.Version.set -> void
Pulumi.ComponentResource
Pulumi.ComponentResource.ComponentResource(string type, string name, Pulumi.ComponentResourceOptions options = null) -> void
Pulumi.ComponentResource.ComponentResource(string type, string name, Pulumi.ResourceArgs args, Pulumi.ComponentResourceOptions options = null, bool remote = false) -> void
@ -73,6 +83,8 @@ Pulumi.DictionaryResourceArgs
Pulumi.DictionaryResourceArgs.DictionaryResourceArgs(System.Collections.Immutable.ImmutableDictionary<string, object> dictionary) -> void
Pulumi.Deployment
Pulumi.DeploymentInstance
Pulumi.DeploymentInstance.Call(string token, Pulumi.CallArgs args, Pulumi.Resource self = null, Pulumi.CallOptions options = null) -> void
Pulumi.DeploymentInstance.Call<T>(string token, Pulumi.CallArgs args, Pulumi.Resource self = null, Pulumi.CallOptions options = null) -> Pulumi.Output<T>
Pulumi.DeploymentInstance.InvokeAsync(string token, Pulumi.InvokeArgs args, Pulumi.InvokeOptions options = null) -> System.Threading.Tasks.Task
Pulumi.DeploymentInstance.InvokeAsync<T>(string token, Pulumi.InvokeArgs args, Pulumi.InvokeOptions options = null) -> System.Threading.Tasks.Task<T>
Pulumi.DeploymentInstance.IsDryRun.get -> bool
@ -357,5 +369,6 @@ static Pulumi.Union<T0, T1>.FromT1(T1 input) -> Pulumi.Union<T0, T1>
static Pulumi.Union<T0, T1>.implicit operator Pulumi.Union<T0, T1>(T0 t) -> Pulumi.Union<T0, T1>
static Pulumi.Union<T0, T1>.implicit operator Pulumi.Union<T0, T1>(T1 t) -> Pulumi.Union<T0, T1>
static Pulumi.Urn.Create(Pulumi.Input<string> name, Pulumi.Input<string> type, Pulumi.Resource parent = null, Pulumi.Input<string> parentUrn = null, Pulumi.Input<string> project = null, Pulumi.Input<string> stack = null) -> Pulumi.Output<string>
static readonly Pulumi.CallArgs.Empty -> Pulumi.CallArgs
static readonly Pulumi.InvokeArgs.Empty -> Pulumi.InvokeArgs
static readonly Pulumi.ResourceArgs.Empty -> Pulumi.ResourceArgs

View file

@ -0,0 +1,23 @@
// Copyright 2016-2021, Pulumi Corporation
using System;
namespace Pulumi
{
/// <summary>
/// Base type for all call argument classes.
/// </summary>
public abstract class CallArgs : InputArgs
{
public static readonly CallArgs Empty = new EmptyCallArgs();
private protected override void ValidateMember(Type memberType, string fullName)
{
// No validation. A member may or may not be IInput.
}
private sealed class EmptyCallArgs : CallArgs
{
}
}
}

View file

@ -93,6 +93,16 @@ namespace Pulumi
/// </summary>
private readonly ImmutableDictionary<string, ProviderResource> _providers;
/// <summary>
/// The specified provider or provider determined from the parent for custom resources.
/// </summary>
internal readonly ProviderResource? _provider;
/// <summary>
/// The specified provider version.
/// </summary>
internal readonly string? _version;
/// <summary>
/// Creates and registers a new resource object. <paramref name="type"/> is the fully
/// qualified type token and <paramref name="name"/> is the "name" part to use in creating a
@ -241,6 +251,8 @@ namespace Pulumi
}
this._protect = options.Protect == true;
this._provider = custom ? options.Provider : null;
this._version = options.Version;
// Collapse any 'Alias'es down to URNs. We have to wait until this point to do so
// because we do not know the default 'name' and 'type' to apply until we are inside the

View file

@ -58,6 +58,21 @@ namespace Pulumi.Testing
return new InvokeResponse { Return = await SerializeAsync(result).ConfigureAwait(false) };
}
public async Task<CallResponse> CallAsync(CallRequest request)
{
// For now, we'll route both Invoke and Call through IMocks.CallAsync.
var args = ToDictionary(request.Args);
var result = await _mocks.CallAsync(new MockCallArgs
{
Token = request.Tok,
Args = args,
Provider = request.Provider,
})
.ConfigureAwait(false);
return new CallResponse { Return = await SerializeAsync(result).ConfigureAwait(false) };
}
public async Task<ReadResourceResponse> ReadResourceAsync(Resource resource, ReadResourceRequest request)
{
var (id, state) = await _mocks.NewResourceAsync(new MockResourceArgs

View file

@ -0,0 +1,353 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/

View file

@ -0,0 +1,41 @@
// Copyright 2016-2021, Pulumi Corporation. All rights reserved.
using Pulumi;
class ComponentArgs : ResourceArgs
{
[Input("first")]
public Input<string> First { get; set; } = null!;
[Input("second")]
public Input<string> Second { get; set; } = null!;
}
class Component : ComponentResource
{
public Component(string name, ComponentArgs args, ComponentResourceOptions? opts = null)
: base("testcomponent:index:Component", name, args, opts, remote: true)
{
}
public Output<GetMessageResult> GetMessage(GetMessageArgs args)
=> Deployment.Instance.Call<GetMessageResult>("testcomponent:index:Component/getMessage", args, this);
}
public class GetMessageArgs : CallArgs
{
[Input("name")]
public Input<string> Name { get; set; } = null!;
}
[OutputType]
public sealed class GetMessageResult
{
public readonly string Message;
[OutputConstructor]
private GetMessageResult(string message)
{
Message = message;
}
}

View file

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View file

@ -0,0 +1,16 @@
// Copyright 2016-2021, Pulumi Corporation. All rights reserved.
using Pulumi;
class MyStack : Stack
{
[Output("message")]
public Output<string> Message { get; set; }
public MyStack()
{
var component = new Component("component", new ComponentArgs { First = "Hello", Second = "World" });
var result = component.GetMessage(new GetMessageArgs { Name = "Alice" });
Message = result.Apply(v => v.Message);
}
}

View file

@ -0,0 +1,9 @@
// Copyright 2016-2021, Pulumi Corporation. All rights reserved.
using System.Threading.Tasks;
using Pulumi;
class Program
{
static Task<int> Main() => Deployment.RunAsync<MyStack>();
}

View file

@ -0,0 +1,3 @@
name: construct_component_methods_dotnet
description: A program that constructs remote component resources with methods.
runtime: dotnet

View file

@ -0,0 +1,353 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/

View file

@ -0,0 +1,32 @@
// Copyright 2016-2021, Pulumi Corporation. All rights reserved.
using Pulumi;
class Component : ComponentResource
{
public Component(string name, ComponentResourceOptions? opts = null)
: base("testcomponent:index:Component", name, ResourceArgs.Empty, opts, remote: true)
{
}
public Output<ComponentGetMessageResult> GetMessage(ComponentGetMessageArgs args)
=> Deployment.Instance.Call<ComponentGetMessageResult>("testcomponent:index:Component/getMessage", args, this);
}
public class ComponentGetMessageArgs : CallArgs
{
[Input("echo")]
public Input<string> Echo { get; set; } = null!;
}
[OutputType]
public sealed class ComponentGetMessageResult
{
public readonly string Message;
[OutputConstructor]
private ComponentGetMessageResult(string message)
{
Message = message;
}
}

View file

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View file

@ -0,0 +1,23 @@
// Copyright 2016-2021, Pulumi Corporation. All rights reserved.
using System;
using Pulumi;
class MyStack : Stack
{
[Output("result")]
public Output<string> Result { get; set; }
public MyStack()
{
var r = new Random("resource", new RandomArgs { Length = 10 });
var component = new Component("component");
Result = component.GetMessage(new ComponentGetMessageArgs { Echo = r.Id }).Apply(v =>
{
Console.WriteLine("should not run (result)");
Environment.Exit(1);
return v.Message;
});
}
}

View file

@ -0,0 +1,9 @@
// Copyright 2016-2021, Pulumi Corporation. All rights reserved.
using System.Threading.Tasks;
using Pulumi;
class Program
{
static Task<int> Main() => Deployment.RunAsync<MyStack>();
}

View file

@ -0,0 +1,3 @@
name: construct_component_methods_unknown_dotnet
description: A program that constructs remote component resources with methods and unknowns.
runtime: dotnet

View file

@ -0,0 +1,17 @@
// Copyright 2016-2021, Pulumi Corporation. All rights reserved.
using Pulumi;
class RandomArgs : ResourceArgs
{
[Input("length")]
public Input<int> Length { get; set; } = null!;
}
class Random : CustomResource
{
public Random(string name, RandomArgs args, CustomResourceOptions? opts = null)
: base("testprovider:index:Random", name, args, opts)
{
}
}

View file

@ -491,6 +491,44 @@ func TestConstructUnknownDotnet(t *testing.T) {
testConstructUnknown(t, "dotnet", "Pulumi")
}
// Test methods on remote components.
func TestConstructMethodsDotnet(t *testing.T) {
tests := []struct {
componentDir string
env []string
}{
{
componentDir: "testcomponent",
},
{
componentDir: "testcomponent-python",
env: []string{pulumiRuntimeVirtualEnv(t, filepath.Join("..", ".."))},
},
{
componentDir: "testcomponent-go",
},
}
for _, test := range tests {
t.Run(test.componentDir, func(t *testing.T) {
pathEnv := pathEnv(t, filepath.Join("construct_component_methods", test.componentDir))
integration.ProgramTest(t, &integration.ProgramTestOptions{
Env: append(test.env, pathEnv),
Dir: filepath.Join("construct_component_methods", "dotnet"),
Dependencies: []string{"Pulumi"},
Quick: true,
NoParallel: true, // avoid contention for Dir
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
assert.Equal(t, "Hello World, Alice!", stackInfo.Outputs["message"])
},
})
})
}
}
func TestConstructMethodsUnknownDotnet(t *testing.T) {
testConstructMethodsUnknown(t, "dotnet", "Pulumi")
}
func TestConstructProviderDotnet(t *testing.T) {
const testDir = "construct_component_provider"
tests := []struct {