https://pulumi.com logo
#azure
Title
# azure
t

tall-needle-56640

12/07/2020, 11:37 PM
#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

tall-librarian-49374

12/08/2020, 9:16 PM
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

tall-needle-56640

12/10/2020, 4:16 PM
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

tall-librarian-49374

12/10/2020, 8:44 PM
Maybe we could. I think something like that is possible in node.
3 Views