worried-knife-31967
03/10/2021, 4:16 PMbored-oyster-3147
03/10/2021, 4:30 PMDeploymeny.RunAsync<TStack>()
. You could instead do Deployment.RunAsync(() => your work here)
and never use the Pulumi.Stack
object. Similarly if you are using Automation API you can do PulumiFn.Create(() => your work here)
instead of PulumiFn.Create<TStack>()
. If you need to return stack outputs your lambda function can return a dictionary of your outputs. Using a delegate instead of a Stack object has the benefit of allowing you do some additional setup before declaring the lambda (maybe spin up a service collection or something) which can make passing in an HttpClient
dependency much easier, thus making unit testing easier.worried-knife-31967
03/10/2021, 5:36 PMvar keys = await ListWebAppHostKeys.InvokeAsync(new ListWebAppHostKeysArgs
{
Name = functionAppName,
ResourceGroupName = functionAppResourceGroup
});
[Input] Pulumi.AzureNative.Storage.ListStorageAccountKeysArgs.AccountName is required but was not given a value (Parameter 'AccountName')
which looks like something internal in the frameworkbored-oyster-3147
03/10/2021, 5:38 PMAccountName
.worried-knife-31967
03/10/2021, 5:41 PMvar accountKeys = Output.Tuple(args.ResourceGroupName, appStorage.Name)
.Apply(p => ListStorageAccountKeys.InvokeAsync(new ListStorageAccountKeysArgs
{
ResourceGroupName = p.Item1,
AccountName = p.Item2
}));
var storageConnectionString = Output.Format($"DefaultEndpointsProtocol=https;AccountName={appStorage.Name};AccountKey={accountKeys.Apply(a => a.Keys[0].Value)}");
That's for building up the connection string required to build a functionapp with the WebApp object.bored-oyster-3147
03/10/2021, 5:43 PMworried-knife-31967
03/10/2021, 5:43 PMbored-oyster-3147
03/10/2021, 5:47 PMAccountName
within your unit test or not?var keys = await ListWebAppHostKeys.InvokeAsync(new ListWebAppHostKeysArgs
{
Name = functionAppName,
ResourceGroupName = functionAppResourceGroup
});
Is missing AccountName
. So I would expect to see that exceptionworried-knife-31967
03/10/2021, 5:56 PMvar appStorage = new StorageAccount(name.Replace("-", ""), new StorageAccountArgs
{
ResourceGroupName = args.ResourceGroupName,
Sku = new SkuArgs
{
Name = SkuName.Standard_LRS,
},
Kind = Pulumi.AzureNative.Storage.Kind.StorageV2,
});
var accountKeys = Output.Tuple(args.ResourceGroupName, appStorage.Name)
.Apply(p => ListStorageAccountKeys.InvokeAsync(new ListStorageAccountKeysArgs
{
ResourceGroupName = p.Item1 ?? "test",
AccountName = p.Item2 ?? "test"
}));
var storageConnectionString = Output.Format($"DefaultEndpointsProtocol=https;AccountName={appStorage.Name};AccountKey={accountKeys.Apply(a => a.Keys[0].Value)}");
So my guess is that these kinds of methods aren't tied to the same structures, so maybe a limitation of the unit testing? I can't imagine that the Storage account keys are stored and generated interally within the framework to be returned?bored-oyster-3147
03/10/2021, 5:59 PMworried-knife-31967
03/10/2021, 6:00 PMbored-oyster-3147
03/10/2021, 6:23 PMIMock
implementation that will serve dummy outputs when those dependent resources are createdworried-knife-31967
03/10/2021, 6:30 PMbored-oyster-3147
03/10/2021, 6:32 PMxxx:StorageAccount
and the name that you gave it, then you want to return a dictionary that has key “ConnectionString” with your dummy valueworried-knife-31967
03/10/2021, 6:34 PMbored-oyster-3147
03/10/2021, 6:35 PMworried-knife-31967
03/10/2021, 6:42 PMmocks.Setup(m => m.CallAsync("azure-native:storage:listStorageAccountKeys", It.IsAny<ImmutableDictionary<string, object>>(), It.IsAny<string>()))
.ReturnsAsync((string token, ImmutableDictionary<string, object> args, string? provider) => {
return new Dictionary<string, object> {
{ "Keys", new [] { "key1", "key2" } }
}.ToImmutableDictionary();
});
That's what I have... but now I need to find what kind of structure of the dictionary it's expecting...bored-oyster-3147
03/10/2021, 6:58 PMworried-knife-31967
03/10/2021, 7:01 PMbored-oyster-3147
03/10/2021, 7:01 PMworried-knife-31967
03/10/2021, 7:15 PMbored-oyster-3147
03/10/2021, 7:25 PMnew Dictionary<string, object>()
{
["Keys"] = new [] {
new Dictionary<string, string>()
{
["KeyName"] = "xxx",
["Permissions"] = "xxx",
["Value"] = "xxx"
}
}
};
worried-knife-31967
03/10/2021, 7:27 PMmocks.Setup(m => m.CallAsync("azure-native:storage:listStorageAccountKeys", It.IsAny<ImmutableDictionary<string, object>>(), It.IsAny<string>()))
.ReturnsAsync((string token, ImmutableDictionary<string, object> args, string? provider) =>
{
return new Dictionary<string, object> {
{ "keys", new List<object> {
new Dictionary<string, object> {
{ "keyName", "key1" },
{ "value", "blah" }}.ToImmutableDictionary()
}.ToImmutableArray() }
}.ToImmutableDictionary();
});
bored-oyster-3147
03/10/2021, 7:30 PMworried-knife-31967
03/10/2021, 7:32 PMmocks.Setup(m => m.CallAsync("azure-native:storage:listStorageAccountKeys", It.IsAny<ImmutableDictionary<string, object>>(), It.IsAny<string>()))
.ReturnsAsync((string token, ImmutableDictionary<string, object> args, string? provider) =>
{
return new Dictionary<string, object> {
{
"keys", new [] {
new Dictionary<string, object> {
{ "keyName", "key1" },
{ "value", "blah" }
}
}
}
};
});
bored-oyster-3147
03/10/2021, 7:32 PMworried-knife-31967
03/10/2021, 7:33 PMtall-librarian-49374
03/10/2021, 7:57 PMworried-knife-31967
03/10/2021, 8:02 PMtall-librarian-49374
03/10/2021, 8:02 PMworried-knife-31967
03/10/2021, 8:07 PMnew Dictionary<string, object> {
{
"Outputs", new Dictionary<string, object> {
{ "Gateways", new Dictionary<string, object> {
{
"uksouth", new Dictionary<string, object> {
{ "GatewayUrl", "<https://afsgsdf/>"},
{ "ResourceGroup", "asdfgadfs"},
{ "ServiceName", "asdfgsadfgh"}
}
},
{
"ukwest", new Dictionary<string, object> {
{ "GatewayUrl", "<https://afsgsdf/>"},
{ "ResourceGroup", "asdfgadfs"},
{ "ServiceName", "asdfgsadfgh"}
}
}
}
}
}
I have a hierarchial output from the shared stack that looks like
Outputs:
Gateways: ***
uksouth: ***
GatewayUrl : "https://[REDACTED].<http://azure-api.net|azure-api.net>"
ResourceGroup: "[REDACTED]-uksouth-main89dccb89"
ServiceName : "[REDACTED]-uksouth-dev"
***
ukwest : ***
GatewayUrl : "https://[REDACTED].<http://azure-api.net|azure-api.net>"
ResourceGroup: "[REDACTED]-main4f6c847d"
ServiceName : "[REDACTED]-dev"
***
***
bored-oyster-3147
03/10/2021, 8:32 PMworried-knife-31967
03/10/2021, 8:35 PMtall-librarian-49374
03/10/2021, 8:42 PMworried-knife-31967
03/10/2021, 9:01 PMtall-librarian-49374
03/10/2021, 9:22 PM"Outputs"
should probably be "outputs"
worried-knife-31967
03/10/2021, 9:52 PM