Support remote components in .NET (#5485)

This commit is contained in:
Justin Van Patten 2020-10-06 10:19:22 -07:00 committed by GitHub
parent 1803eb2978
commit df75f0ed95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 680 additions and 50 deletions

View file

@ -12,6 +12,8 @@ CHANGELOG
- Fixing gzip compression for alternative backends.
[#5484](https://github.com/pulumi/pulumi/pull/5484)
- Add internal scaffolding for using cross-language components from .NET.
[#5485](https://github.com/pulumi/pulumi/pull/5485)
## 2.11.2 (2020-10-01)

View file

@ -94,7 +94,8 @@ namespace Pulumi.Tests
mock.Setup(d => d.ProjectName).Returns("TestProject");
mock.Setup(d => d.StackName).Returns("TestStack");
mock.SetupSet(content => content.Stack = It.IsAny<Stack>());
mock.Setup(d => d.ReadOrRegisterResource(It.IsAny<Stack>(), It.IsAny<ResourceArgs>(), It.IsAny<ResourceOptions>()));
mock.Setup(d => d.ReadOrRegisterResource(It.IsAny<Stack>(), It.IsAny<bool>(),
It.IsAny<Func<string, Resource>>(), It.IsAny<ResourceArgs>(), It.IsAny<ResourceOptions>()));
mock.Setup(d => d.RegisterResourceOutputs(It.IsAny<Stack>(), It.IsAny<Output<IDictionary<string, object?>>>()))
.Callback((Resource _, Output<IDictionary<string, object?>> o) => outputs = o);

View file

@ -11,7 +11,8 @@ namespace Pulumi
public partial class Deployment
{
void IDeploymentInternal.ReadOrRegisterResource(
Resource resource, ResourceArgs args, ResourceOptions options)
Resource resource, bool remote, Func<string, Resource> newDependency, ResourceArgs args,
ResourceOptions options)
{
// ReadOrRegisterResource is called in a fire-and-forget manner. Make sure we keep
// track of this task so that the application will not quit until this async work
@ -31,11 +32,12 @@ namespace Pulumi
_runner.RegisterTask(
$"{nameof(IDeploymentInternal.ReadOrRegisterResource)}: {resource.GetResourceType()}-{resource.GetResourceName()}",
CompleteResourceAsync(resource, args, options, completionSources));
CompleteResourceAsync(resource, remote, newDependency, args, options, completionSources));
}
private async Task<(string urn, string id, Struct data)> ReadOrRegisterResourceAsync(
Resource resource, ResourceArgs args, ResourceOptions options)
private async Task<(string urn, string id, Struct data, ImmutableDictionary<string, ImmutableHashSet<Resource>> dependencies)> ReadOrRegisterResourceAsync(
Resource resource, bool remote, Func<string, Resource> newDependency, ResourceArgs args,
ResourceOptions options)
{
if (options.Id != null)
{
@ -54,7 +56,7 @@ namespace Pulumi
// resource's properties will be resolved asynchronously after the operation completes,
// so that dependent computations resolve normally. If we are just planning, on the
// other hand, values will never resolve.
return await RegisterResourceAsync(resource, args, options).ConfigureAwait(false);
return await RegisterResourceAsync(resource, remote, newDependency, args, options).ConfigureAwait(false);
}
/// <summary>
@ -63,14 +65,16 @@ namespace Pulumi
/// the results of it.
/// </summary>
private async Task CompleteResourceAsync(
Resource resource, ResourceArgs args, ResourceOptions options,
ImmutableDictionary<string, IOutputCompletionSource> completionSources)
Resource resource, bool remote, Func<string, Resource> newDependency, ResourceArgs args,
ResourceOptions options, ImmutableDictionary<string, IOutputCompletionSource> completionSources)
{
// Run in a try/catch/finally so that we always resolve all the outputs of the resource
// regardless of whether we encounter an errors computing the action.
try
{
var response = await ReadOrRegisterResourceAsync(resource, args, options).ConfigureAwait(false);
var response = await ReadOrRegisterResourceAsync(
resource, remote, newDependency, args, options).ConfigureAwait(false);
completionSources[Constants.UrnPropertyName].SetStringValue(response.urn, isKnown: true);
if (resource is CustomResource customResource)
{
@ -94,8 +98,13 @@ namespace Pulumi
// rest.
if (response.data.Fields.TryGetValue(fieldName, out var value))
{
var converted = Converter.ConvertValue(
$"{resource.GetType().FullName}.{fieldName}", value, completionSource.TargetType);
if (!response.dependencies.TryGetValue(fieldName, out var dependencies))
{
dependencies = ImmutableHashSet<Resource>.Empty;
}
var converted = Converter.ConvertValue($"{resource.GetType().FullName}.{fieldName}", value,
completionSource.TargetType, dependencies);
completionSource.SetValue(converted);
}
}

View file

@ -1,6 +1,7 @@
// Copyright 2016-2019, Pulumi Corporation
using System;
using System.Collections.Immutable;
using System.Threading.Tasks;
using Google.Protobuf.WellKnownTypes;
using Pulumi.Serialization;
@ -10,7 +11,7 @@ namespace Pulumi
{
public partial class Deployment
{
private async Task<(string urn, string id, Struct data)> ReadResourceAsync(
private async Task<(string urn, string id, Struct data, ImmutableDictionary<string, ImmutableHashSet<Resource>> dependencies)> ReadResourceAsync(
Resource resource, string id, ResourceArgs args, ResourceOptions options)
{
var name = resource.GetResourceName();
@ -43,7 +44,7 @@ namespace Pulumi
// Now run the operation, serializing the invocation if necessary.
var response = await this.Monitor.ReadResourceAsync(resource, request);
return (response.Urn, id, response.Properties);
return (response.Urn, id, response.Properties, ImmutableDictionary<string, ImmutableHashSet<Resource>>.Empty);
}
}
}

View file

@ -1,6 +1,7 @@
// Copyright 2016-2019, Pulumi Corporation
using System;
using System.Collections.Immutable;
using System.Threading.Tasks;
using Google.Protobuf.WellKnownTypes;
using Pulumirpc;
@ -9,28 +10,41 @@ namespace Pulumi
{
public partial class Deployment
{
private async Task<(string urn, string id, Struct data)> RegisterResourceAsync(
Resource resource, ResourceArgs args, ResourceOptions options)
private async Task<(string urn, string id, Struct data, ImmutableDictionary<string, ImmutableHashSet<Resource>> dependencies)> RegisterResourceAsync(
Resource resource, bool remote, Func<string, Resource> newDependency, ResourceArgs args,
ResourceOptions options)
{
var name = resource.GetResourceName();
var type = resource.GetResourceType();
var custom = resource is CustomResource;
var label = $"resource:{name}[{type}]";
Log.Debug($"Registering resource start: t={type}, name={name}, custom={custom}");
Log.Debug($"Registering resource start: t={type}, name={name}, custom={custom}, remote={remote}");
var request = CreateRegisterResourceRequest(type, name, custom, options);
var request = CreateRegisterResourceRequest(type, name, custom, remote, options);
Log.Debug($"Preparing resource: t={type}, name={name}, custom={custom}");
Log.Debug($"Preparing resource: t={type}, name={name}, custom={custom}, remote={remote}");
var prepareResult = await PrepareResourceAsync(label, resource, custom, args, options).ConfigureAwait(false);
Log.Debug($"Prepared resource: t={type}, name={name}, custom={custom}");
Log.Debug($"Prepared resource: t={type}, name={name}, custom={custom}, remote={remote}");
PopulateRequest(request, prepareResult);
Log.Debug($"Registering resource monitor start: t={type}, name={name}, custom={custom}");
Log.Debug($"Registering resource monitor start: t={type}, name={name}, custom={custom}, remote={remote}");
var result = await this.Monitor.RegisterResourceAsync(resource, request);
Log.Debug($"Registering resource monitor end: t={type}, name={name}, custom={custom}");
return (result.Urn, result.Id, result.Object);
Log.Debug($"Registering resource monitor end: t={type}, name={name}, custom={custom}, remote={remote}");
var dependencies = ImmutableDictionary.CreateBuilder<string, ImmutableHashSet<Resource>>();
foreach (var (key, propertyDependencies) in result.PropertyDependencies)
{
var urns = ImmutableHashSet.CreateBuilder<Resource>();
foreach (var urn in propertyDependencies.Urns)
{
urns.Add(newDependency(urn));
}
dependencies[key] = urns.ToImmutable();
}
return (result.Urn, result.Id, result.Object, dependencies.ToImmutable());
}
private static void PopulateRequest(RegisterResourceRequest request, PrepareResult prepareResult)
@ -49,7 +63,8 @@ namespace Pulumi
}
}
private static RegisterResourceRequest CreateRegisterResourceRequest(string type, string name, bool custom, ResourceOptions options)
private static RegisterResourceRequest CreateRegisterResourceRequest(
string type, string name, bool custom, bool remote, ResourceOptions options)
{
var customOpts = options as CustomResourceOptions;
var deleteBeforeReplace = customOpts?.DeleteBeforeReplace;
@ -71,6 +86,7 @@ namespace Pulumi
Delete = TimeoutString(options.CustomTimeouts?.Delete),
Update = TimeoutString(options.CustomTimeouts?.Update),
},
Remote = remote,
};
if (customOpts != null)

View file

@ -1,8 +1,7 @@
// Copyright 2016-2019, Pulumi Corporation
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Pulumirpc;
namespace Pulumi
{
@ -15,7 +14,9 @@ namespace Pulumi
ILogger Logger { get; }
IRunner Runner { get; }
void ReadOrRegisterResource(Resource resource, ResourceArgs args, ResourceOptions opts);
void ReadOrRegisterResource(
Resource resource, bool remote, Func<string, Resource> newDependency, ResourceArgs args,
ResourceOptions opts);
void RegisterResourceOutputs(Resource resource, Output<IDictionary<string, object?>> outputs);
}
}

View file

@ -23,6 +23,7 @@ Pulumi.AssetArchive.AssetArchive(System.Collections.Generic.IDictionary<string,
Pulumi.AssetOrArchive
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
Pulumi.ComponentResource.RegisterOutputs() -> void
Pulumi.ComponentResource.RegisterOutputs(Pulumi.Output<System.Collections.Generic.IDictionary<string, object>> outputs) -> void
Pulumi.ComponentResource.RegisterOutputs(System.Collections.Generic.IDictionary<string, object> outputs) -> void

View file

@ -9,7 +9,7 @@ namespace Pulumi
{
/// <summary>
/// A <see cref="Resource"/> that aggregates one or more other child resources into a higher
/// level abstraction.The component resource itself is a resource, but does not require custom
/// level abstraction. The component resource itself is a resource, but does not require custom
/// CRUD operations for provisioning.
/// </summary>
public class ComponentResource : Resource
@ -21,11 +21,30 @@ namespace Pulumi
/// for this component, and [options.dependsOn] is an optional list of other resources that
/// this resource depends on, controlling the order in which we perform resource operations.
/// </summary>
#pragma warning disable RS0022 // Constructor make noninheritable base class inheritable
/// <param name="type">The type of the resource.</param>
/// <param name="name">The unique name of the resource.</param>
/// <param name="options">A bag of options that control this resource's behavior.</param>
public ComponentResource(string type, string name, ComponentResourceOptions? options = null)
: base(type, name, custom: false,
args: ResourceArgs.Empty,
options ?? new ComponentResourceOptions())
: this(type, name, ResourceArgs.Empty, options)
{
}
/// <summary>
/// Creates and registers a new component resource. <paramref name="type"/> is the fully
/// qualified type token and <paramref name="name"/> is the "name" part to use in creating a
/// stable and globally unique URN for the object. <c>options.parent</c> is the optional parent
/// for this component, and [options.dependsOn] is an optional list of other resources that
/// this resource depends on, controlling the order in which we perform resource operations.
/// </summary>
/// <param name="type">The type of the resource.</param>
/// <param name="name">The unique name of the resource.</param>
/// <param name="args">The arguments to use to populate the new resource.</param>
/// <param name="options">A bag of options that control this resource's behavior.</param>
/// <param name="remote">True if this is a remote component resource.</param>
#pragma warning disable RS0022 // Constructor make noninheritable base class inheritable
public ComponentResource(
string type, string name, ResourceArgs? args, ComponentResourceOptions? options = null, bool remote = false)
: base(type, name, custom: false, args ?? ResourceArgs.Empty, options ?? new ComponentResourceOptions(), remote)
#pragma warning restore RS0022 // Constructor make noninheritable base class inheritable
{
}

View file

@ -5,7 +5,7 @@ using Pulumi.Serialization;
namespace Pulumi
{
/// <summary>
/// CustomResource is a resource whose create, read, update, and delete(CRUD) operations are
/// CustomResource is a resource whose create, read, update, and delete (CRUD) operations are
/// managed by performing external operations on some physical entity. The engine understands
/// how to diff and perform partial updates of them, and these CRUD operations are implemented
/// in a dynamically loaded plugin for the defining package.
@ -18,22 +18,49 @@ namespace Pulumi
/// </summary>
// Set using reflection, so we silence the NRT warnings with `null!`.
[Output(Constants.IdPropertyName)]
public Output<string> Id { get; private set; } = null!;
public Output<string> Id { get; private protected set; } = null!;
/// <summary>
/// Creates and registers a new managed resource. t is the fully qualified type token and
/// name is the "name" part to use in creating a stable and globally unique URN for the
/// object. dependsOn is an optional list of other resources that this resource depends on,
/// controlling the order in which we perform resource operations.Creating an instance does
/// not necessarily perform a create on the physical entity which it represents, and
/// instead, this is dependent upon the diffing of the new goal state compared to the
/// current known resource state.
/// Creates and registers a new managed resource. <paramref name="type"/> is the fully
/// qualified type token and <paramref name="name"/> is the "name" part to use in creating a
/// stable and globally unique URN for the object. <see cref="ResourceOptions.DependsOn"/>
/// is an optional list of other resources that this resource depends on, controlling the
/// order in which we perform resource operations. Creating an instance does not necessarily
/// perform a create on the physical entity which it represents, and instead, this is
/// dependent upon the diffing of the new goal state compared to the current known resource
/// state.
/// </summary>
/// <param name="type">The type of the resource.</param>
/// <param name="name">The unique name of the resource.</param>
/// <param name="args">The arguments to use to populate the new resource.</param>
/// <param name="options">A bag of options that control this resource's behavior.</param>
#pragma warning disable RS0022 // Constructor make noninheritable base class inheritable
public CustomResource(string type, string name, ResourceArgs? args, CustomResourceOptions? options = null)
: base(type, name, custom: true, args ?? ResourceArgs.Empty, options ?? new CustomResourceOptions())
: this(type, name, args, options, dependency: false)
#pragma warning restore RS0022 // Constructor make noninheritable base class inheritable
{
}
/// <summary>
/// Creates and registers a new managed resource. <paramref name="type"/> is the fully
/// qualified type token and <paramref name="name"/> is the "name" part to use in creating a
/// stable and globally unique URN for the object. <see cref="ResourceOptions.DependsOn"/>
/// is an optional list of other resources that this resource depends on, controlling the
/// order in which we perform resource operations. Creating an instance does not necessarily
/// perform a create on the physical entity which it represents, and instead, this is
/// dependent upon the diffing of the new goal state compared to the current known resource
/// state.
/// </summary>
/// <param name="type">The type of the resource.</param>
/// <param name="name">The unique name of the resource.</param>
/// <param name="args">The arguments to use to populate the new resource.</param>
/// <param name="options">A bag of options that control this resource's behavior.</param>
/// <param name="dependency">True if this is a synthetic resource used internally for dependency tracking.</param>
private protected CustomResource(
string type, string name, ResourceArgs? args, CustomResourceOptions? options = null, bool dependency = false)
: base(type, name, custom: true, args ?? ResourceArgs.Empty, options ?? new CustomResourceOptions(),
remote: false, dependency: dependency)
{
}
}
}

View file

@ -0,0 +1,36 @@
// Copyright 2016-2020, Pulumi Corporation
using System;
using System.Collections.Immutable;
using System.Threading.Tasks;
using Pulumi.Serialization;
namespace Pulumi
{
/// <summary>
/// <see cref="DependencyProviderResource"/> is a <see cref="Resource"/> that is used by the provider SDK as a
/// stand-in for a provider that is only used for its reference. Its only valid properties are its URN and ID.
/// </summary>
internal sealed class DependencyProviderResource : ProviderResource
{
public DependencyProviderResource(string reference)
: base(package: "", name: "", args: ResourceArgs.Empty, dependency: true)
{
int lastSep = reference.LastIndexOf("::", StringComparison.Ordinal);
if (lastSep == -1)
{
throw new ArgumentException($"Expected \"::\" in provider reference ${reference}.");
}
string urn = reference.Substring(0, lastSep);
string id = reference.Substring(lastSep + 2);
var resources = ImmutableHashSet.Create<Resource>(this);
var urnData = OutputData.Create(resources, urn, isKnown: true, isSecret: false);
this.Urn = new Output<string>(Task.FromResult(urnData));
var idData = OutputData.Create(resources, id, isKnown: true, isSecret: false);
this.Id = new Output<string>(Task.FromResult(idData));
}
}
}

View file

@ -0,0 +1,24 @@
// Copyright 2016-2020, Pulumi Corporation
using System.Collections.Immutable;
using System.Threading.Tasks;
using Pulumi.Serialization;
namespace Pulumi
{
/// <summary>
/// <see cref="DependencyResource"/> is a <see cref="Resource"/> that is used to indicate that an
/// <see cref="Output"/> has a dependency on a particular resource. These resources are only created when dealing
/// with remote component resources.
/// </summary>
internal sealed class DependencyResource : CustomResource
{
public DependencyResource(string urn)
: base(type: "", name: "", args: ResourceArgs.Empty, dependency: true)
{
var resources = ImmutableHashSet.Create<Resource>(this);
var data = OutputData.Create(resources, urn, isKnown: true, isSecret: false);
this.Urn = new Output<string>(Task.FromResult(data));
}
}
}

View file

@ -19,10 +19,27 @@ namespace Pulumi
/// <summary>
/// Creates and registers a new provider resource for a particular package.
/// </summary>
public ProviderResource(
/// <param name="package">The package associated with this provider.</param>
/// <param name="name">The unique name of the provider.</param>
/// <param name="args">The configuration to use for this provider.</param>
/// <param name="options">A bag of options that control this provider's behavior.</param>
public ProviderResource(string package, string name, ResourceArgs args, CustomResourceOptions? options = null)
: this(package, name, args, options, dependency: false)
{
}
/// <summary>
/// Creates and registers a new provider resource for a particular package.
/// </summary>
/// <param name="package">The package associated with this provider.</param>
/// <param name="name">The unique name of the provider.</param>
/// <param name="args">The configuration to use for this provider.</param>
/// <param name="options">A bag of options that control this provider's behavior.</param>
/// <param name="dependency">True if this is a synthetic resource used internally for dependency tracking.</param>
private protected ProviderResource(
string package, string name,
ResourceArgs args, CustomResourceOptions? options = null)
: base($"pulumi:providers:{package}", name, args, options)
ResourceArgs args, CustomResourceOptions? options = null, bool dependency = false)
: base($"pulumi:providers:{package}", name, args, options, dependency)
{
this.Package = package;
}

View file

@ -64,7 +64,7 @@ namespace Pulumi
/// </summary>
// Set using reflection, so we silence the NRT warnings with `null!`.
[Output(Constants.UrnPropertyName)]
public Output<string> Urn { get; private set; } = null!;
public Output<string> Urn { get; private protected set; } = null!;
/// <summary>
/// When set to true, protect ensures this resource cannot be deleted.
@ -110,10 +110,22 @@ namespace Pulumi
/// <param name="custom">True to indicate that this is a custom resource, managed by a plugin.</param>
/// <param name="args">The arguments to use to populate the new resource.</param>
/// <param name="options">A bag of options that control this resource's behavior.</param>
/// <param name="remote">True if this is a remote component resource.</param>
/// <param name="dependency">True if this is a synthetic resource used internally for dependency tracking.</param>
private protected Resource(
string type, string name, bool custom,
ResourceArgs args, ResourceOptions options)
ResourceArgs args, ResourceOptions options,
bool remote = false, bool dependency = false)
{
if (dependency)
{
_type = "";
_name = "";
_protect = false;
_providers = ImmutableDictionary<string, ProviderResource>.Empty;
return;
}
if (string.IsNullOrEmpty(type))
throw new ArgumentException("'type' cannot be null or empty.", nameof(type));
@ -243,7 +255,7 @@ namespace Pulumi
}
this._aliases = aliases.ToImmutable();
Deployment.InternalInstance.ReadOrRegisterResource(this, args, options);
Deployment.InternalInstance.ReadOrRegisterResource(this, remote, urn => new DependencyResource(urn), args, options);
}
/// <summary>

View file

@ -20,14 +20,19 @@ namespace Pulumi.Serialization
}
public static OutputData<object?> ConvertValue(string context, Value value, System.Type targetType)
{
return ConvertValue(context, value, targetType, ImmutableHashSet<Resource>.Empty);
}
public static OutputData<object?> ConvertValue(
string context, Value value, System.Type targetType, ImmutableHashSet<Resource> resources)
{
CheckTargetType(context, targetType, new HashSet<System.Type>());
var (deserialized, isKnown, isSecret) = Deserializer.Deserialize(value);
var converted = ConvertObject(context, deserialized, targetType);
return new OutputData<object?>(
ImmutableHashSet<Resource>.Empty, converted, isKnown, isSecret);
return new OutputData<object?>(resources, converted, isKnown, isSecret);
}
private static object? ConvertObject(string context, object? val, System.Type targetType)

View file

@ -45,7 +45,7 @@ namespace Pulumi.Serialization
public void SetValue(OutputData<object?> data)
=> _taskCompletionSource.SetResult(new OutputData<T>(
_resources, (T)data.Value!, data.IsKnown, data.IsSecret));
_resources.Union(data.Resources), (T)data.Value!, data.IsKnown, data.IsSecret));
public void TrySetDefaultResult(bool isKnown)
=> _taskCompletionSource.TrySetResult(new OutputData<T>(

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,23 @@
// Copyright 2016-2020, Pulumi Corporation. All rights reserved.
using Pulumi;
class ComponentArgs : Pulumi.ResourceArgs
{
[Input("echo")]
public Input<object>? Echo { get; set; }
}
class Component : Pulumi.ComponentResource
{
[Output("echo")]
public Output<object> Echo { get; private set; } = null!;
[Output("childId")]
public Output<string> ChildId { get; private set; } = null!;
public Component(string name, ComponentArgs args, ComponentResourceOptions opts = null)
: base("testcomponent:index:Component", name, args, opts, remote: true)
{
}
}

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,13 @@
// Copyright 2016-2020, Pulumi Corporation. All rights reserved.
using Pulumi;
class MyStack : Stack
{
public MyStack()
{
var componentA = new Component("a", new ComponentArgs { Echo = 42 });
var componentB = new Component("b", new ComponentArgs { Echo = componentA.Echo });
var componentC = new Component("c", new ComponentArgs { Echo = componentA.ChildId });
}
}

View file

@ -0,0 +1,7 @@
using System.Threading.Tasks;
using Pulumi;
class Program
{
static Task<int> Main() => Deployment.RunAsync<MyStack>();
}

View file

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

View file

@ -170,3 +170,54 @@ func TestLargeResourceDotNet(t *testing.T) {
Dir: filepath.Join("large_resource", "dotnet"),
})
}
// Test remote component construction in .NET.
func TestConstructDotnet(t *testing.T) {
pathEnv, err := testComponentPathEnv()
if err != nil {
t.Fatalf("failed to build test component PATH: %v", err)
}
// TODO[pulumi/pulumi#5455]: Dynamic providers fail to load when used from multi-lang components.
// Until we've addressed this, set PULUMI_TEST_YARN_LINK_PULUMI, which tells the integration test
// module to run `yarn install && yarn link @pulumi/pulumi` in the .NET program's directory, allowing
// the Node.js dynamic provider plugin to load.
// When the underlying issue has been fixed, the use of this environment variable inside the integration
// test module should be removed.
const testYarnLinkPulumiEnv = "PULUMI_TEST_YARN_LINK_PULUMI=true"
var opts *integration.ProgramTestOptions
opts = &integration.ProgramTestOptions{
Env: []string{pathEnv, testYarnLinkPulumiEnv},
Dir: filepath.Join("construct_component", "dotnet"),
Dependencies: []string{"Pulumi"},
Quick: true,
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
assert.NotNil(t, stackInfo.Deployment)
if assert.Equal(t, 9, len(stackInfo.Deployment.Resources)) {
stackRes := stackInfo.Deployment.Resources[0]
assert.NotNil(t, stackRes)
assert.Equal(t, resource.RootStackType, stackRes.Type)
assert.Equal(t, "", string(stackRes.Parent))
// Check that dependencies flow correctly between the originating program and the remote component
// plugin.
urns := make(map[string]resource.URN)
for _, res := range stackInfo.Deployment.Resources[1:] {
assert.NotNil(t, res)
urns[string(res.URN.Name())] = res.URN
switch res.URN.Name() {
case "child-a", "child-b":
for _, deps := range res.PropertyDependencies {
assert.Empty(t, deps)
}
case "child-c":
assert.Equal(t, []resource.URN{urns["child-a"]}, res.PropertyDependencies["echo"])
}
}
}
},
}
integration.ProgramTest(t, opts)
}