Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a self reference to CallRequest and ConstructRequest #533

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pulumi
Submodule pulumi updated 238 files
3 changes: 3 additions & 0 deletions sdk/Pulumi.Tests/Provider/ComponentProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public async Task Construct_ValidComponent_ShouldThrowExpectedDeploymentExceptio
}.ToImmutableDictionary();
var options = new ComponentResourceOptions();
var request = new ConstructRequest(
null,
"test-package:index:TestComponent",
name,
inputs,
Expand All @@ -62,6 +63,7 @@ public async Task Construct_ValidComponent_ShouldThrowExpectedDeploymentExceptio
public async Task Construct_InvalidPackageName_ShouldThrowException()
{
var request = new ConstructRequest(
null,
"wrong:index:TestComponent",
"test",
ImmutableDictionary<string, PropertyValue>.Empty,
Expand All @@ -79,6 +81,7 @@ public async Task Construct_InvalidPackageName_ShouldThrowException()
public async Task Construct_NonExistentComponent_ShouldThrowException()
{
var request = new ConstructRequest(
null,
"test-package:index:NonExistentComponent",
"test",
ImmutableDictionary<string, PropertyValue>.Empty,
Expand Down
33 changes: 29 additions & 4 deletions sdk/Pulumi/Provider/Provider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,15 @@ public DeleteRequest(Urn urn, string id, ImmutableDictionary<string, PropertyVal

public sealed class ConstructRequest
{
public ProviderResource? Provider { get; init; }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arguably this should be non-nullable and throw with a message like "self provider references aren't supported update your pulumi CLI", that would match how we handle other cases like this that depend on engine support.

public string Type { get; init; }
public string Name { get; init; }
public ImmutableDictionary<string, PropertyValue> Inputs { get; init; }
public ComponentResourceOptions Options { get; init; }

public ConstructRequest(string type, string name, ImmutableDictionary<string, PropertyValue> inputs, ComponentResourceOptions options)
public ConstructRequest(ProviderResource? provider, string type, string name, ImmutableDictionary<string, PropertyValue> inputs, ComponentResourceOptions options)
{
Provider = provider;
Type = type;
Name = name;
Inputs = inputs;
Expand All @@ -393,12 +395,14 @@ public ConstructResponse(Urn urn, IDictionary<string, PropertyValue> state, IDic

public sealed class CallRequest
{
public ProviderResource? Provider { get; init; }
public ResourceReference? Self { get; }
public string Tok { get; init; }
public ImmutableDictionary<string, PropertyValue> Args { get; init; }

public CallRequest(ResourceReference? self, string tok, ImmutableDictionary<string, PropertyValue> args)
public CallRequest(ProviderResource? provider, ResourceReference? self, string tok, ImmutableDictionary<string, PropertyValue> args)
{
Provider = provider;
Self = self;
Tok = tok;
Args = args;
Expand Down Expand Up @@ -611,6 +615,9 @@ class ResourceProviderService : ResourceProvider.ResourceProviderBase, IDisposab
private Provider? implementation;
private readonly string version;
private string? engineAddress;
// More recent versions of the engine send URN and ID of the provider to `Configure`. With that we can construct
// a `DependencyProviderResource` to use in `Construct` and `Call` to refer to the provider itself.
private string? providerSelfReference;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no value in sending a ProviderResource to any of the normal CRUD methods, but maybe we should send the URN for logging reasons? That would allow you to log a message to the provider resource, while performing a Create/Update for another resource.


Provider Implementation
{
Expand Down Expand Up @@ -876,6 +883,12 @@ private ImmutableDictionary<string, PropertyValue> Unmarshal(Struct? properties)
{
return WrapProviderCall(async () =>
{
// Save the URN and ID for self provider references in Construct/Call later.
if (request.HasId && request.HasUrn)
{
this.providerSelfReference = request.Urn + "::" + request.Id;
}

var domRequest = new ConfigureRequest(request.Variables.ToImmutableDictionary(), Unmarshal(request.Args), request.AcceptSecrets,
request.AcceptResources);
using var cts = GetToken(context);
Expand Down Expand Up @@ -1057,7 +1070,13 @@ public override Task<Empty> Delete(Pulumirpc.DeleteRequest request, ServerCallCo
},
};

var domRequest = new ConstructRequest(request.Type, request.Name,
ProviderResource? provider = null;
if (providerSelfReference != null)
{
provider = new DependencyProviderResource(providerSelfReference);
}

var domRequest = new ConstructRequest(provider, request.Type, request.Name,
Unmarshal(request.Inputs), opts);
using var cts = GetToken(context);

Expand Down Expand Up @@ -1098,7 +1117,13 @@ public override Task<Empty> Delete(Pulumirpc.DeleteRequest request, ServerCallCo

domArgs = PatchArgDependencies(request, domArgs);

var domRequest = new CallRequest(self, request.Tok, domArgs);
ProviderResource? provider = null;
if (providerSelfReference != null)
{
provider = new DependencyProviderResource(providerSelfReference);
}

var domRequest = new CallRequest(provider, self, request.Tok, domArgs);
using var cts = GetToken(context);

var inlineDeploymentSettings = new InlineDeploymentSettings(logger, EngineAddress, request.MonitorEndpoint, request.Config,
Expand Down
Loading
Loading