使用Pulumi.Azure部署现有App Service时出错

问题描述

当我尝试将现有的App Service部署到Azure时,我得到2020-10-29T22:27:58.8724283Z I1029 22:27:58.870264 4596 eventsink.go:78] eventSink::Infoerr(<{%reset%}>panic: interface conversion: interface {} is nil,not map[string]interface {} 2020-10-29T22:27:58.8728827Z <{%reset%}>) 2020-10-29T22:27:58.8735984Z I1029 22:27:58.870264 4596 eventsink.go:78] eventSink::Infoerr(<{%reset%}>goroutine 199 [running]: 2020-10-29T22:27:58.8767921Z <{%reset%}>) 2020-10-29T22:27:58.8778359Z I1029 22:27:58.870264 4596 eventsink.go:78] eventSink::Infoerr(<{%reset%}>github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/web.expandAppServiceLogs(0x47f6180,0xc0013eca00,0x4,0x47f6180,0x1)

错误使我的堆栈无法部署到Azure。

   var webApi = new AppService(appServiceName,new AppServiceArgs
                {
                    Name = appServiceName,ResourceGroupName = resourceGroupName,Identity = new AppServiceIdentityArgs {Type = "SystemAssigned"},AppServicePlanId = appServicePlanId,AppSettings =
                    {
                        {"WEBSITE_RUN_FROM_PACKAGE",webApiCodeBlob},{"AzureStorage__AccountName",storageAccountName},{"AzureStorage__AccountKey",storageAccountPrimaryAccessKey},{"APPINSIGHTS_INSTRUMENTATIONKEY",appInsightsInstrumentationKey},{
                            "APPLICATIONINSIGHTS_CONNECTION_STRING",appInsightsConnectionString
                        },{"ApplicationInsightsAgent_EXTENSION_VERSION","~2"}
                    },ConnectionStrings =
                    {
                        new AppServiceConnectionStringArgs
                        {
                            Name = "AzureServiceBusConnectionString",Value = serviceBusConnectionString,Type = "Custom"
                        },new AppServiceConnectionStringArgs
                        {
                            Name = "BlobStorageConnectionString",Value = blobConnectionString,new AppServiceConnectionStringArgs
                        {
                            Name = "MongoConnectionString",Value = cosmosAccountConnectionString,Type = "Custom"
                        }
                    },SiteConfig = new AppServiceSiteConfigArgs
                    {
                        AlwaysOn = true,Cors = new AppServiceSiteConfigCorsArgs
                        {
                            AllowedOrigins = allowedOrigins
                        }
                    },Tags = new InputMap<string>()
                    {
                        {"team",Team},{"product",Product},{"productId",ProductId},{"environment",environment},{"service",ServiceName}
                    },});

如果App Service不存在,它将在第一次运行。仅当它部署现有的App Service时,此操作才会失败。只有在App Service中没有定义“日志”部分时,才会发生这种情况。

我正在使用Pulumi 3.28.0

解决方法

我找到了一种解决方法,它基于此https://github.com/pulumi/pulumi-azure/issues/383#issuecomment-549192628

在App Service中没有配置“日志”部分时,它试图将您的C#堆栈转换为Pulumi的内部表示,这是一个无法映射的nil值,请打开链接以查看有关的更准确的详细信息根本原因。

这就是我能够使其工作的方式。

将“日志”部分添加到您的AppService

 Logs = new AppServiceLogsArgs
                    {
                        ApplicationLogs = new AppServiceLogsApplicationLogsArgs
                        {
                            AzureBlobStorage = new AppServiceLogsApplicationLogsAzureBlobStorageArgs
                            {
                                Level = "Information",RetentionInDays = 1,SasUrl = $"${storageAccount.PrimaryBlobEndpoint}{blobSas}"
                            }
                        },HttpLogs = new AppServiceLogsHttpLogsArgs
                        {
                            FileSystem = new AppServiceLogsHttpLogsFileSystemArgs
                            {
                                RetentionInDays = 1,RetentionInMb = 100
                            }
                        }
                    },