<#CRVK66N5U|azure> <#CQ2QFLNFL|dotnet> I'm trying ...
# azure
t
#azure #dotnet I'm trying to create a factory that returns resources with a logical set of defaults. In order for this to work in
Pulumi.Azure
, I did this:
Copy code
args.AppSettings = InputMap<string>.Merge(defaultAppSettings, args.AppSettings);
Now I'm trying to migrate that code to
AzureNextGen
, but I'm not sure how to get it to work. I tried:
Copy code
var appSettings = args.SiteConfig.Apply(c => c.AppSettings);
args.SiteConfig.Apply(s => 
    s.AppSettings = InputMap<string>.Merge(defaultAppSettings, appSettings));
But I get an error:
Argument 2: cannot convert from 'Pulumi.Output<Pulumi.InputList<Pulumi.AzureNextGen.Web.Latest.Inputs.NameValuePairArgs>>' to 'Pulumi.InputMap<string>'
So what do I do to make this work? Note
defaultAppSettings
is of type
Dictionary<string, string>
.
NOTE: This all happens before any resources are created, but due to
Input
and
Output
casts, I can't accomplish what should be easily achievable.
Still looking for help on merging `InputList`'s.
t
Copy code
var merged = args.SiteConfig
    .Apply(c => c.AppSettings.ToOutput())
    .Apply(settings =>
        Output.All(settings.Select(s => Output.Tuple(s.Name, s.Value))))
    .Apply(settings =>
    {
        var dict = new Dictionary<string, string>(defaultAppSettings);
        foreach (var (k, v) in settings)
            dict[k] = v;
        return dict.Select(kv => new NameValuePairArgs {Name = kv.Key, Value = kv.Value});
    });
args.SiteConfig.Apply(s => s.AppSettings = merged);
🙌 1
I’m not really proud of writing this code…
t
Wow
Input
/
Output
is pretty slick. But man can it be annoying at the same time. 🙂
Would it be possible to have something like this:
Copy code
var value = "someValue";
Input<T> inputValue = value;
var newValue = inputValue.Value;
Assert.Equal(value, newValue);
Maybe
Input<T>.Value
is only non-null if it was implicitly cast from type T
Copy code
class Input<T>
{
	public T? Value;
	public static implicit operator Input<T>([MaybeNull]T value)
	{
		Value = value;
		return Output.Create(value);
	}
}
t
Maybe we could. I think something like that is possible in node.