Support string properties in CustomResource creation
This commit is contained in:
parent
a9e00887a5
commit
deacf9f55e
2 changed files with 30 additions and 3 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
using Google.Protobuf.WellKnownTypes;
|
||||||
using Pulumirpc;
|
using Pulumirpc;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
@ -27,8 +28,9 @@ namespace Pulumi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Figure out the parent URN. If an explicit parent was passed in, use that. Otherwise use the global root URN. In the case where that hasn't been set yet, we must be creating
|
||||||
|
// the ComponentResource that represents the global stack object, so pass along no parent.
|
||||||
Task<string> parentUrn;
|
Task<string> parentUrn;
|
||||||
|
|
||||||
if (options.Parent != null) {
|
if (options.Parent != null) {
|
||||||
parentUrn = options.Parent.Urn;
|
parentUrn = options.Parent.Urn;
|
||||||
} else if (Runtime.Root != null) {
|
} else if (Runtime.Root != null) {
|
||||||
|
@ -44,7 +46,7 @@ namespace Pulumi
|
||||||
Name = name,
|
Name = name,
|
||||||
Custom = custom,
|
Custom = custom,
|
||||||
Protect = false,
|
Protect = false,
|
||||||
Object = new Google.Protobuf.WellKnownTypes.Struct(),
|
Object = SerializeProperties(properties),
|
||||||
Parent = parentUrn.Result
|
Parent = parentUrn.Result
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -52,5 +54,27 @@ namespace Pulumi
|
||||||
Urn = res.ResponseAsync.ContinueWith((x) => x.Result.Urn);
|
Urn = res.ResponseAsync.ContinueWith((x) => x.Result.Urn);
|
||||||
return res.ResponseAsync;
|
return res.ResponseAsync;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Struct SerializeProperties(Dictionary<string, object> properties) {
|
||||||
|
if (properties == null) {
|
||||||
|
return new Struct();
|
||||||
|
}
|
||||||
|
|
||||||
|
var s = new Struct();
|
||||||
|
|
||||||
|
foreach (var kvp in properties) {
|
||||||
|
s.Fields.Add(kvp.Key, SerializeProperty(kvp.Value));
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Value SerializeProperty(object o) {
|
||||||
|
if (o.GetType() == typeof(string)) {
|
||||||
|
return Value.ForString((string)o);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new NotImplementedException($"cannot marshal object of type ${o.GetType()}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,7 +1,10 @@
|
||||||
#r "/home/matell/go/src/github.com/pulumi/pulumi/sdk/dotnet/Pulumi/bin/Debug/netstandard2.0/Pulumi.dll"
|
#r "/home/matell/go/src/github.com/pulumi/pulumi/sdk/dotnet/Pulumi/bin/Debug/netstandard2.0/Pulumi.dll"
|
||||||
using Pulumi;
|
using Pulumi;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
Config config = new Config("hello-dotnet");
|
Config config = new Config("hello-dotnet");
|
||||||
CustomResource r = new CustomResource("aws:s3/bucket:Bucket", config["name"]);
|
CustomResource r = new CustomResource("aws:s3/bucket:Bucket", config["name"], new Dictionary<string, object> {
|
||||||
|
{ "acl", "public-read" }
|
||||||
|
});
|
||||||
Console.WriteLine($"provided assigned id: {r.Id.Result}");
|
Console.WriteLine($"provided assigned id: {r.Id.Result}");
|
||||||
|
|
Loading…
Reference in a new issue