3

I have the following bicep file to create an Azure Function App with a staging slot:

module functionAppTemplate 'functionApp.bicep' = {
  name: 'functionAppTemplate'
  params: {
    name: '${functionAppName}'
    kind: functionAppKind
    location: location
    servicePlanName: servicePlanName
    secretSettings: union(appSettings, productionSettings)
  }
  dependsOn: [
    servicePlanTemplate
  ]
}

module functionAppSlotTemplate 'functionAppSlot.bicep' = {
  name: 'functionAppSlotTemplate'
  params: {
    name: '${functionAppName}/staging'
    kind: functionAppKind
    location: location
    servicePlanName: servicePlanName
    secretSettings: union(appSettings, stagingSettings)
  }
  dependsOn: [
    functionAppTemplate
  ]
}

functionApp.bicep

resource functionApp 'Microsoft.Web/sites@2018-02-01' = {
  name: name
  location: location
  kind: kind
  properties: {
    serverFarmId: resourceId('Microsoft.Web/serverfarms', servicePlanName)
    clientAffinityEnabled: false
    httpsOnly: true
    siteConfig: {
      use32BitWorkerProcess : false
      appSettings: secretSettings
    }
  }
  identity: {
    type: 'SystemAssigned'
  }
}

functionAppSlot.bicep

resource functionAppSlot 'Microsoft.Web/sites/slots@2018-11-01' = {
  name: name
  kind: kind
  location: location
  properties: {
    clientAffinityEnabled: true
    enabled: true
    httpsOnly: true
    serverFarmId: resourceId('Microsoft.Web/serverfarms', servicePlanName)
    siteConfig: {
      use32BitWorkerProcess : false
      appSettings: secretSettings
    }
  }
  identity: {
    type: 'SystemAssigned'
  }
}

Is there a way to run functionApp.bicep and create Function App resource ONLY IF that resource doesn't exist?

Thomas
  • 24,234
  • 6
  • 81
  • 125
user989988
  • 3,006
  • 7
  • 44
  • 91
  • 1
    bicep/arm is idempotent so you shouldn't need to deploy only if the resource does not exists. What is the issue you are facing ? – Thomas Aug 23 '22 at 21:31
  • After deployment, I see functions in production slot missing. – user989988 Aug 23 '22 at 22:14
  • 1
    is it related to this question: https://stackoverflow.com/questions/73171955/functions-missing-in-production-slot-after-deploying-to-staging-slot ? – Thomas Aug 23 '22 at 22:32
  • the app settings `WEBSITE_RUN_FROM_PACKAGE=1` did not work ? https://github.com/projectkudu/kudu/wiki/WEBSITE_RUN_FROM_PACKAGE-and-WEBSITE_CONTENTAZUREFILECONNECTIONSTRING-Best-Practices#devops-runfrompackage-common-issue – Thomas Aug 23 '22 at 22:33
  • 1
    Yes I think it could be because functions are getting recreated during deployment. No adding WEBSITE_RUN_FROM_PACKAGE=1 didn't work. – user989988 Aug 23 '22 at 23:23

0 Answers0