Skip to content

Commit df6a2d4

Browse files
committed
Add a self reference to CallRequest and ConstructRequest
1 parent 9be2d7b commit df6a2d4

File tree

4 files changed

+401
-127
lines changed

4 files changed

+401
-127
lines changed

pulumi

Submodule pulumi updated 238 files

sdk/Pulumi.Tests/Provider/ComponentProviderTests.cs

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public async Task Construct_ValidComponent_ShouldThrowExpectedDeploymentExceptio
4141
}.ToImmutableDictionary();
4242
var options = new ComponentResourceOptions();
4343
var request = new ConstructRequest(
44+
null,
4445
"test-package:index:TestComponent",
4546
name,
4647
inputs,
@@ -62,6 +63,7 @@ public async Task Construct_ValidComponent_ShouldThrowExpectedDeploymentExceptio
6263
public async Task Construct_InvalidPackageName_ShouldThrowException()
6364
{
6465
var request = new ConstructRequest(
66+
null,
6567
"wrong:index:TestComponent",
6668
"test",
6769
ImmutableDictionary<string, PropertyValue>.Empty,
@@ -79,6 +81,7 @@ public async Task Construct_InvalidPackageName_ShouldThrowException()
7981
public async Task Construct_NonExistentComponent_ShouldThrowException()
8082
{
8183
var request = new ConstructRequest(
84+
null,
8285
"test-package:index:NonExistentComponent",
8386
"test",
8487
ImmutableDictionary<string, PropertyValue>.Empty,

sdk/Pulumi/Provider/Provider.cs

+29-4
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,15 @@ public DeleteRequest(Urn urn, string id, ImmutableDictionary<string, PropertyVal
363363

364364
public sealed class ConstructRequest
365365
{
366+
public ProviderResource? Provider { get; init; }
366367
public string Type { get; init; }
367368
public string Name { get; init; }
368369
public ImmutableDictionary<string, PropertyValue> Inputs { get; init; }
369370
public ComponentResourceOptions Options { get; init; }
370371

371-
public ConstructRequest(string type, string name, ImmutableDictionary<string, PropertyValue> inputs, ComponentResourceOptions options)
372+
public ConstructRequest(ProviderResource? provider, string type, string name, ImmutableDictionary<string, PropertyValue> inputs, ComponentResourceOptions options)
372373
{
374+
Provider = provider;
373375
Type = type;
374376
Name = name;
375377
Inputs = inputs;
@@ -393,12 +395,14 @@ public ConstructResponse(Urn urn, IDictionary<string, PropertyValue> state, IDic
393395

394396
public sealed class CallRequest
395397
{
398+
public ProviderResource? Provider { get; init; }
396399
public ResourceReference? Self { get; }
397400
public string Tok { get; init; }
398401
public ImmutableDictionary<string, PropertyValue> Args { get; init; }
399402

400-
public CallRequest(ResourceReference? self, string tok, ImmutableDictionary<string, PropertyValue> args)
403+
public CallRequest(ProviderResource? provider, ResourceReference? self, string tok, ImmutableDictionary<string, PropertyValue> args)
401404
{
405+
Provider = provider;
402406
Self = self;
403407
Tok = tok;
404408
Args = args;
@@ -611,6 +615,9 @@ class ResourceProviderService : ResourceProvider.ResourceProviderBase, IDisposab
611615
private Provider? implementation;
612616
private readonly string version;
613617
private string? engineAddress;
618+
// More recent versions of the engine send URN and ID of the provider to `Configure`. With that we can construct
619+
// a `DependencyProviderResource` to use in `Construct` and `Call` to refer to the provider itself.
620+
private string? providerSelfReference;
614621

615622
Provider Implementation
616623
{
@@ -876,6 +883,12 @@ private ImmutableDictionary<string, PropertyValue> Unmarshal(Struct? properties)
876883
{
877884
return WrapProviderCall(async () =>
878885
{
886+
// Save the URN and ID for self provider references in Construct/Call later.
887+
if (request.HasId && request.HasUrn)
888+
{
889+
this.providerSelfReference = request.Urn + "::" + request.Id;
890+
}
891+
879892
var domRequest = new ConfigureRequest(request.Variables.ToImmutableDictionary(), Unmarshal(request.Args), request.AcceptSecrets,
880893
request.AcceptResources);
881894
using var cts = GetToken(context);
@@ -1057,7 +1070,13 @@ public override Task<Empty> Delete(Pulumirpc.DeleteRequest request, ServerCallCo
10571070
},
10581071
};
10591072

1060-
var domRequest = new ConstructRequest(request.Type, request.Name,
1073+
ProviderResource? provider = null;
1074+
if (providerSelfReference != null)
1075+
{
1076+
provider = new DependencyProviderResource(providerSelfReference);
1077+
}
1078+
1079+
var domRequest = new ConstructRequest(provider, request.Type, request.Name,
10611080
Unmarshal(request.Inputs), opts);
10621081
using var cts = GetToken(context);
10631082

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

10991118
domArgs = PatchArgDependencies(request, domArgs);
11001119

1101-
var domRequest = new CallRequest(self, request.Tok, domArgs);
1120+
ProviderResource? provider = null;
1121+
if (providerSelfReference != null)
1122+
{
1123+
provider = new DependencyProviderResource(providerSelfReference);
1124+
}
1125+
1126+
var domRequest = new CallRequest(provider, self, request.Tok, domArgs);
11021127
using var cts = GetToken(context);
11031128

11041129
var inlineDeploymentSettings = new InlineDeploymentSettings(logger, EngineAddress, request.MonitorEndpoint, request.Config,

0 commit comments

Comments
 (0)