c# - 为什么存储帐户未在函数应用中列出?
问题描述
我正在使用 Microsoft.Azure.Management.*.Fluent API 将资源部署到天蓝色。正在部署的资源依次为 { Resource Group
, Storage Account
, App Service Plan
, Function App
}。
我很好奇为什么我的存储帐户没有分配给我的功能应用程序
//Create Resource Group
Logger.Info($"Checking for Resource Group: {ResourceGroupName}");
resourceGroup = (await azure.ResourceGroups.ListAsync()).FirstOrDefault(rg => rg.Name == ResourceGroupName);
if (resourceGroup != null)
{
Logger.Info($"\tFound: {resourceGroup.Name}");
}
else
{
Logger.Info($"\tNot found. Provisioning resource on Azure...");
resourceGroup = azure.ResourceGroups.Define(ResourceGroupName).WithRegion(Region.USCentral).Create();
Logger.Info(
await azure.ResourceGroups.ContainAsync(ResourceGroupName)
? $"\t{ResourceGroupName} Created"
: $"\tFailed to create Resource Group: {ResourceGroupName}."
);
}
//Create Storage Account
Logger.Info($"Checking for storage account: {StorageAccountName} in resource group: {ResourceGroupName}");
storageAccount = (await azure.StorageAccounts.ListByResourceGroupAsync(ResourceGroupName))
.FirstOrDefault(sa => sa.Name == StorageAccountName);
if (storageAccount != null)
{
Logger.Info($"\tFound: {storageAccount.Name}");
}
else
{
Logger.Info($"\tNot found. Provisioning resource on Azure...");
storageAccount = await azure.StorageAccounts.Define(StorageAccountName)
.WithRegion(Region.USCentral)
.WithExistingResourceGroup(resourceGroup)
.WithBlobEncryption()
.WithGeneralPurposeAccountKindV2()
.WithFileEncryption()
.WithOnlyHttpsTraffic()
.WithSku(StorageAccountSkuType.Standard_LRS)
.WithHnsEnabled(true)
.CreateAsync();
Logger.Info(
(await azure.StorageAccounts.ListByResourceGroupAsync(ResourceGroupName)).Any(x => x.Name == StorageAccountName)
? $"\tStorage Account: {StorageAccountName} Created Successfully"
: $"\tFailed to create Storage Account: {StorageAccountName}."
);
}
//Create App Service Plan
Logger.Info($"Checking for App Service Plan: {AppServicePlanName} in resource group: {ResourceGroupName}");
appServicePlan = (await azure.AppServices.AppServicePlans.ListByResourceGroupAsync(ResourceGroupName))
.FirstOrDefault(asp => asp.Name == AppServicePlanName);
if (appServicePlan != null)
{
Logger.Info($"\tFound: {appServicePlan.Name}");
}
else
{
Logger.Info($"\tNot found. Provisioning resource on Azure...");
appServicePlan = await azure.AppServices.AppServicePlans
.Define(AppServicePlanName)
.WithRegion(Region.USCentral)
.WithExistingResourceGroup(resourceGroup)
.WithConsumptionPricingTier()
.CreateAsync();
Logger.Info(
((await azure.AppServices.AppServicePlans.ListByResourceGroupAsync(ResourceGroupName)).Any(x => x.Name == AppServicePlanName))
? $"\tApp Service Plan: {AppServicePlanName} Created Successfully"
: $"\tFailed to create App Service Plan: {AppServicePlanName}."
);
}
//Create Function App
Logger.Info($"Checking for Function App: {FunctionAppName} in resource group: {ResourceGroupName}");
functionApp = (await azure.AppServices.FunctionApps.ListByResourceGroupAsync(ResourceGroupName)).FirstOrDefault(x => x.Name == FunctionAppName);
if (functionApp != null)
{
Logger.Info($"\tFound: {functionApp.Name}");
}
else
{
Logger.Info($"\tNot found. Provisioning resource on Azure...");
functionApp = await azure.AppServices.FunctionApps
.Define(FunctionAppName)
.WithExistingAppServicePlan(appServicePlan)
.WithExistingResourceGroup(resourceGroup)
.WithExistingStorageAccount(storageAccount)
.WithRuntimeVersion("~3")
.WithHttpsOnly(true)
.WithWebSocketsEnabled(true)
.WithPlatformArchitecture(PlatformArchitecture.X64)
.WithSystemAssignedManagedServiceIdentity()
.CreateAsync();
Logger.Info(
((await azure.AppServices.FunctionApps.ListByResourceGroupAsync(ResourceGroupName)).Any(x => x.Name == FunctionAppName))
? $"\tFunction app: {FunctionAppName} Created Successfully"
: $"\tFailed to create Function App: {FunctionAppName}."
);
}
Logger.Info("\n");
在构建函数应用程序时,我指定.WithExistingStorageAccount(storageAccount)
,我相信它将存储帐户添加到函数应用程序。
虽然,当我检查返回值时,functionApp.StorageAccount
是null
. 我登录门户并查看函数应用的部署模板中的存储帐户值,发现 azureStorageAccounts 集合也是空的。
解决方案
资源组实际上被添加到 azure 函数中 - 但不是作为 ARM 模板本身的一部分。
使用添加的存储帐户.WithExistingStorageAccount(storageAccount)
作为键值对添加到应用程序设置。
该azureStorageAccounts
属性是另一个资源 的属性Microsoft.Web/sites/config
,它依赖于函数应用。
推荐阅读
- python - 领英自动化
- r - 将折线图更改为堆叠折线图 ggplot
- swift - 在 swift 5 中,图像文字数组得到“表达式类型不明确,没有更多上下文”
- python - 我想从本地分支运行我的 Django 项目。有没有办法做到这一点?
- java - 主启动器 =true 在 Xamarin android 中不起作用(system.typeloadexception)
- python - Flask 无法从 html 表单中选择数据
- azure - 从 Azure SQL 导出数据后如何添加主键和外键约束
- javascript - Javascript - 如何创建过滤的嵌套数组
- javascript - 创建反应应用程序构建在服务器中不起作用:错误:缩小反应错误#130;
- javascript - Webpack 在运行时导入模块而不知道在构建期间是哪个