当我重新部署逻辑应用程序 IaC 部分时,Azure 逻辑应用程序(标准)工作流被删除,如何避免这种情况?

标签 azure azure-pipelines azure-logic-apps azure-rm-template azure-bicep

我通过以下方式在 IaC 中设置了逻辑应用程序:

param environmentType string
param location string
param storageAccountSku string
param vnetIntegrationSubnetId string
param storageAccountTempEndpoint string
param ResourceGroupName string

/// Just a single minimum instance to start with and max scaling of 3 ///
var minimumElasticSize = 1
var maximumElasticSize = 3
var name = 'somename'
var logicAppName = 'logic-app-${name}-${environmentType}'

/// Storage account for service ///
resource logicAppStorage 'Microsoft.Storage/storageAccounts@2019-06-01' = {
  name: 'st4logicapp${name}${environmentType}'
  location: location
  kind: 'StorageV2'
  sku: {
    name: storageAccountSku
  }
  properties: {
    allowBlobPublicAccess: false
    accessTier: 'Hot'
    supportsHttpsTrafficOnly: true
    minimumTlsVersion: 'TLS1_2'
  }
}

/// Existing temp storage for extracting variables ///
resource storageAccountTemp 'Microsoft.Storage/storageAccounts@2021-08-01' existing = {
  scope: resourceGroup(ResourceGroupName)
  name: 'tmpst${environmentType}'
}

/// Dedicated app plan for the service ///
resource servicePlanLogicApp 'Microsoft.Web/serverfarms@2021-02-01' = {
  name: 'plan-${name}-logic-app-${environmentType}'
  location: location
  sku: {
    tier: 'WorkflowStandard'
    name: 'WS1'
  }
  properties: {
    targetWorkerCount: minimumElasticSize
    maximumElasticWorkerCount: maximumElasticSize
    elasticScaleEnabled: true
    isSpot: false
    zoneRedundant: ((environmentType == 'prd') ? true : false)
  }
}

// Create log analytics workspace
resource logAnalyticsWorkspacelogicApp 'Microsoft.OperationalInsights/workspaces@2021-06-01' = {
  name: '${name}-logicapp-loganalytics-workspace-${environmentType}'
  location: location
  properties: {
    sku: {
      name: 'PerGB2018' // Standard
    }
  }
}

/// Log analytics workspace insights ///
resource applicationInsightsLogicApp 'Microsoft.Insights/components@2020-02-02' = {
  name: 'application-insights-${name}-logic-${environmentType}'
  location: location
  kind: 'web'
  properties: {
    Application_Type: 'web'
    Flow_Type: 'Bluefield'
    publicNetworkAccessForIngestion: 'Enabled'
    publicNetworkAccessForQuery: 'Enabled'
    Request_Source: 'rest'
    RetentionInDays: 30
    WorkspaceResourceId: logAnalyticsWorkspacelogicApp.id
  }
}

// App service containing the workflow runtime ///
resource siteLogicApp 'Microsoft.Web/sites@2021-02-01' = {
  name: logicAppName
  location: location
  kind: 'functionapp,workflowapp'
  properties: {
    httpsOnly: true
    siteConfig: {
      appSettings: [
        {
          name: 'FUNCTIONS_EXTENSION_VERSION'
          value: '~3'
        }
        {
          name: 'FUNCTIONS_WORKER_RUNTIME'
          value: 'node'
        }
        {
          name: 'WEBSITE_NODE_DEFAULT_VERSION'
          value: '~12'
        }
        {
          name: 'AzureWebJobsStorage'
          value: 'DefaultEndpointsProtocol=https;AccountName=${logicAppStorage.name};AccountKey=${listKeys(logicAppStorage.id, '2019-06-01').keys[0].value};EndpointSuffix=core.windows.net'
        }
        {
          name: 'WEBSITE_CONTENTAZUREFILECONNECTIONSTRING'
          value: 'DefaultEndpointsProtocol=https;AccountName=${logicAppStorage.name};AccountKey=${listKeys(logicAppStorage.id, '2019-06-01').keys[0].value};EndpointSuffix=core.windows.net'
        }
        {
          name: 'WEBSITE_CONTENTSHARE'
          value: 'app-${toLower(name)}-logicservice-${toLower(environmentType)}a6e9'
        }
        {
          name: 'AzureFunctionsJobHost__extensionBundle__id'
          value: 'Microsoft.Azure.Functions.ExtensionBundle.Workflows'
        }
        {
          name: 'AzureFunctionsJobHost__extensionBundle__version'
          value: '[1.*, 2.0.0)'
        }
        {
          name: 'APP_KIND'
          value: 'workflowApp'
        }
        {
          name: 'APPINSIGHTS_INSTRUMENTATIONKEY'
          value: applicationInsightsLogicApp.properties.InstrumentationKey
        }
        {
          name: 'ApplicationInsightsAgent_EXTENSION_VERSION'
          value: '~2'
        }
        {
          name: 'APPLICATIONINSIGHTS_CONNECTION_STRING'
          value: applicationInsightsLogicApp.properties.ConnectionString
        }
        {
          name: 'AzureBlob_connectionString'
          value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccountTemp.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${listKeys(storageAccountTemp.id, storageAccountTemp.apiVersion).keys[0].value}'
        }
        {
          name: 'azurequeues_connectionString'
          value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccountTemp.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${listKeys(storageAccountTemp.id, storageAccountTemp.apiVersion).keys[0].value}'
        }
      ]
      use32BitWorkerProcess: true
    }
    serverFarmId: servicePlanLogicApp.id
    clientAffinityEnabled: false
  }

  /// VNET integration so flows can access storage and queue accounts ///
  resource vnetIntegration 'networkConfig' = {
    name: 'virtualNetwork'
    properties: {
      subnetResourceId: vnetIntegrationSubnetId
      swiftSupported: true
    }
  }
}

一切顺利,标准逻辑应用程序已部署。

接下来,我通过 azure pipelines(通过 zipdeploy)使用代码定义一些工作流程:

trigger:
  branches:
    include:
      - '*'

pool:
  name: "Ubuntu hosted"

stages:
- stage: logicAppBuild
  displayName: 'Logic App Build'
  jobs:
  - job: logic_app_build
    displayName: 'Build and publish logic app'
    steps:

    - task: CopyFiles@2
      displayName: 'Create project folder'
      inputs:
        SourceFolder: '$(System.DefaultWorkingDirectory)/logicapp'
        Contents: |
          **
        TargetFolder: 'project_output'

    - task: ArchiveFiles@2
      displayName: 'Create project zip'
      inputs:
        rootFolderOrFile: '$(System.DefaultWorkingDirectory)/project_output'
        includeRootFolder: false
        archiveType: 'zip'
        archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
        replaceExistingArchive: true

    - task: PublishPipelineArtifact@1
      displayName: 'Publish project zip artifact'
      inputs:
        targetPath: '$(Build.ArtifactStagingDirectory)'
        artifactName: 'artifectdev'
        publishLocation: 'pipeline'   

- stage: logicAppDeploy
  displayName: 'Logic app deployment'
  jobs:
  - job: logicAppDeploy
    displayName: 'Deploy the Logic apps'
    steps:
    - task: DownloadPipelineArtifact@2
      inputs:
        buildType: 'current'
        artifactName: 'artifectdev'
        targetPath: '$(Build.ArtifactStagingDirectory)'

    - task: AzureFunctionApp@1 # Add this at the end of your file
      inputs:
        azureSubscription: SC-DEV
        appType: functionApp # default is functionApp
        appName: logic-app-name-dev
        package: $(Build.ArtifactStagingDirectory)/**/*.zip

首先在管道中运行 IaC 代码(在 main.bicep 中与其他一些基础代码一起调用)会导致 LogicApp 的成功部署。然后使用 zip-deploy 运行管道后,logicapp 目录中定义的流程、连接等都得到了很好的部署。

但是,当 IaC 管道再次运行时,我在第二个管道中使用 zip-deploy 部署的所有定义的工作流现在都消失了。即使我没有更改 IaC 代码中的任何内容。

有什么办法可以避免这个问题吗?每次部署 IaC 代码时(例如添加一些应用程序设置时)都发生这种情况,对我来说是完全行不通的。

最佳答案

分享所讨论的决议 here如果有人正在寻找类似的问题。

对于 zip 部署,您需要将 AzureFunctionApp 任务与工作流应用程序类型结合使用

task: AzureFunctionApp@1
displayName: Deploy Logic App Workflows
inputs:
azureSubscription: ${<!-- -->{variables.azureSubscription}}
appName: $(pv_logicAppName)
appType: 'workflowapp'
package: '$(Pipeline.Workspace)/LogicApps/$(Build.BuildNumber).zip'
deploymentMethod: 'zipDeploy'

关于当我重新部署逻辑应用程序 IaC 部分时,Azure 逻辑应用程序(标准)工作流被删除,如何避免这种情况?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73952651/

相关文章:

python - 使用 native Windows 数据库驱动程序在 Windows 上运行 django 迁移以获取远程 mssql 数据库

azure - 使用 ARM 模板和 Key Vault 创建 Azure SQL 的最佳实践是什么

azure - 无法连接到端口 9000 的 SonarQube 私有(private) IP

azure - 基于脚本的 Azure 警报

azure - 从 Azure 逻辑应用程序中的 IBM MQ 队列读取消息

Azure逻辑应用HTTP请求500

powershell - 调用 New-AzureStorageTable cmdlet 时 VSTS 发布 Azure Powershell 任务失败

.net - Azure 管道 : task PublishBuildArtifacts avoid zip

Azure Web App 虚拟应用程序,您正在查找的资源已被删除、名称已更改或暂时不可用

json - 将 JSON HTTP 请求转换并转换为 XML