Skip to content

Commit 7ccddd1

Browse files
committed
update
1 parent 047d046 commit 7ccddd1

File tree

1 file changed

+70
-53
lines changed

1 file changed

+70
-53
lines changed

articles/azure-functions/functions-infrastructure-as-code.md

Lines changed: 70 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,9 @@ ms.custom: fasttrack-edit, devx-track-azurepowershell
1010

1111
# Automate resource deployment for your function app in Azure Functions
1212

13-
You can use a Bicep file or an Azure Resource Manager template to deploy a function app. This article outlines the required resources and parameters for doing so. You might need to deploy other resources, depending on the [triggers and bindings](functions-triggers-bindings.md) in your function app.
13+
You can use a Bicep file or an Azure Resource Manager template to deploy a function app. This article outlines the required resources and parameters for doing so. You might need to deploy other resources, depending on the [triggers and bindings](functions-triggers-bindings.md) in your function app. For more information about creating Bicep files, see [Understand the structure and syntax of Bicep files](../azure-resource-manager/bicep/file.md). For more information about creating templates, see [Authoring Azure Resource Manager templates](../azure-resource-manager/templates/syntax.md).
1414

15-
# [Bicep](#tab/bicep)
16-
17-
For more information about creating Bicep files, see [Understand the structure and syntax of Bicep files](../azure-resource-manager/bicep/file.md).
18-
19-
# [JSON](#tab/json)
20-
21-
For more information about creating templates, see [Authoring Azure Resource Manager templates](../azure-resource-manager/templates/syntax.md).
22-
23-
---
24-
25-
For sample templates, see:
15+
For sample Bicep files and ARM templates, see:
2616

2717
- [ARM templates for function app deployment](https://github.com/Azure-Samples/function-app-arm-templates)
2818
- [Function app on Consumption plan]
@@ -103,7 +93,7 @@ These properties are specified in the `appSettings` collection in the `siteConfi
10393
# [Bicep](#tab/bicep)
10494

10595
```bicep
106-
resource site 'Microsoft.Web/sites@2022-03-01' = {
96+
resource functionApp 'Microsoft.Web/sites@2022-03-01' = {
10797
...
10898
properties: {
10999
...
@@ -201,7 +191,7 @@ In addition, the instrumentation key needs to be provided to the function app us
201191
# [Bicep](#tab/bicep)
202192

203193
```bicep
204-
resource site 'Microsoft.Web/sites@2022-03-01' = {
194+
resource functionApp 'Microsoft.Web/sites@2022-03-01' = {
205195
...
206196
properties: {
207197
...
@@ -326,7 +316,7 @@ These properties are specified in the `appSettings` collection in the `siteConfi
326316
# [Bicep](#tab/bicep)
327317

328318
```bicep
329-
resource site 'Microsoft.Web/sites@2022-03-01' = {
319+
resource functionApp 'Microsoft.Web/sites@2022-03-01' = {
330320
...
331321
properties: {
332322
...
@@ -514,7 +504,7 @@ For a sample Bicep file/Azure Resource Manager template, see [Azure Function App
514504
# [Bicep](#tab/bicep)
515505

516506
```bicep
517-
resource site 'Microsoft.Web/sites@2022-03-01' = {
507+
resource functionApp 'Microsoft.Web/sites@2022-03-01' = {
518508
name: functionAppName
519509
location: location
520510
kind: 'functionapp'
@@ -625,7 +615,7 @@ For a sample Bicep file/Azure Resource Manager template, see [Azure Function App
625615
# [Bicep](#tab/bicep)
626616

627617
```bicep
628-
resource site 'Microsoft.Web/sites@2022-03-01' = {
618+
resource functionApp 'Microsoft.Web/sites@2022-03-01' = {
629619
name: functionAppName
630620
location: location
631621
kind: 'functionapp,linux'
@@ -918,7 +908,7 @@ The function app must have set `"kind": "functionapp,linux"`, and it must have s
918908
# [Bicep](#tab/bicep)
919909

920910
```bicep
921-
resource site 'Microsoft.Web/sites@2021-02-01' = {
911+
resource functionApp 'Microsoft.Web/sites@2021-02-01' = {
922912
name: functionAppName
923913
location: location
924914
kind: 'functionapp,linux'
@@ -1122,7 +1112,7 @@ The settings required by a function app running in Dedicated plan differ between
11221112
# [Bicep](#tab/bicep)
11231113

11241114
```bicep
1125-
resource site 'Microsoft.Web/sites@2022-03-01' = {
1115+
resource functionApp 'Microsoft.Web/sites@2022-03-01' = {
11261116
name: functionAppName
11271117
location: location
11281118
kind: 'functionapp'
@@ -1211,7 +1201,7 @@ The function app must have set `"kind": "functionapp,linux"`, and it must have s
12111201
# [Bicep](#tab/bicep)
12121202

12131203
```bicep
1214-
resource site 'Microsoft.Web/sites@2022-03-01' = {
1204+
resource functionApp 'Microsoft.Web/sites@2022-03-01' = {
12151205
name: functionAppName
12161206
location: location
12171207
kind: 'functionapp,linux'
@@ -1296,7 +1286,7 @@ If you're [deploying a custom container image](./functions-create-function-linux
12961286
# [Bicep](#tab/bicep)
12971287

12981288
```bicep
1299-
resource site 'Microsoft.Web/sites@2022-03-01' = {
1289+
resource functionApp 'Microsoft.Web/sites@2022-03-01' = {
13001290
name: functionAppName
13011291
location: location
13021292
kind: 'functionapp'
@@ -1408,7 +1398,7 @@ resource site 'Microsoft.Web/sites@2022-03-01' = {
14081398

14091399
Azure Functions can be deployed to [Azure Arc-enabled Kubernetes](../app-service/overview-arc-integration.md). This process largely follows [deploying to an App Service plan](#deploy-on-app-service-plan), with a few differences to note.
14101400

1411-
To create the app and plan resources, you must have already [created an App Service Kubernetes environment](../app-service/manage-create-arc-environment.md) for an Azure Arc-enabled Kubernetes cluster. These examples assume you have the resource ID of the custom location and App Service Kubernetes environment that you're deploying to. For most templates, you can supply these values as parameters.
1401+
To create the app and plan resources, you must have already [created an App Service Kubernetes environment](../app-service/manage-create-arc-environment.md) for an Azure Arc-enabled Kubernetes cluster. These examples assume you have the resource ID of the custom location and App Service Kubernetes environment that you're deploying to. For most Bicep files/ARM templates, you can supply these values as parameters.
14121402

14131403
# [Bicep](#tab/bicep)
14141404

@@ -1519,7 +1509,7 @@ The function app resource should have its `kind` field set to **functionapp,linu
15191509
# [Bicep](#tab/bicep)
15201510

15211511
```bicep
1522-
resource site 'Microsoft.Web/sites@2022-03-01' = {
1512+
resource functionApp 'Microsoft.Web/sites@2022-03-01' = {
15231513
name: functionAppName
15241514
kind: 'kubernetes,functionapp,linux,container'
15251515
location: location
@@ -1607,12 +1597,12 @@ A function app has many child resources that you can use in your deployment, inc
16071597
# [Bicep](#tab/bicep)
16081598

16091599
```bicep
1610-
resource site 'Microsoft.Web/sites@2022-03-01' = {
1600+
resource functionApp 'Microsoft.Web/sites@2022-03-01' = {
16111601
name: functionAppName
1612-
kind: 'functionapp'
16131602
location: location
1603+
kind: 'functionapp'
16141604
properties: {
1615-
serverFarmId: hostingPlanName
1605+
serverFarmId: hostingPlan.id
16161606
siteConfig: {
16171607
alwaysOn: true
16181608
appSettings: [
@@ -1629,12 +1619,12 @@ resource site 'Microsoft.Web/sites@2022-03-01' = {
16291619
}
16301620
dependsOn: [
16311621
storageAccount
1632-
hostingPlan
16331622
]
16341623
}
16351624
16361625
resource config 'Microsoft.Web/sites/config@2022-03-01' = {
1637-
name: '${functionAppName}/appsettings'
1626+
parent: functionApp
1627+
name: 'appsettings'
16381628
properties: {
16391629
AzureWebJobsStorage: 'DefaultEndpointsProtocol=https;AccountName=${storageAccountName};AccountKey=${storageAccount.listKeys().keys[0].value}'
16401630
AzureWebJobsDashboard: 'DefaultEndpointsProtocol=https;AccountName=${storageAccountName};AccountKey=${storageAccount.listKeys().keys[0].value}'
@@ -1643,13 +1633,13 @@ resource config 'Microsoft.Web/sites/config@2022-03-01' = {
16431633
Project: 'src'
16441634
}
16451635
dependsOn: [
1646-
site
1636+
sourcecontrol
16471637
storageAccount
16481638
]
16491639
}
16501640
16511641
resource sourcecontrol 'Microsoft.Web/sites/sourcecontrols@2022-03-01' = {
1652-
parent: site
1642+
parent: functionApp
16531643
name: 'web'
16541644
properties: {
16551645
repoUrl: repoUrl
@@ -1665,11 +1655,11 @@ resource sourcecontrol 'Microsoft.Web/sites/sourcecontrols@2022-03-01' = {
16651655
{
16661656
"type": "Microsoft.Web/sites",
16671657
"apiVersion": "2022-03-01",
1668-
"name": "[parameters('functionAppName')]",
1669-
"kind": "functionapp",
1658+
"name": "[variables('functionAppName')]",
16701659
"location": "[parameters('location')]",
1660+
"kind": "functionapp",
16711661
"properties": {
1672-
"serverFarmId": "[parameters('hostingPlanName')]",
1662+
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
16731663
"siteConfig": {
16741664
"alwaysOn": true,
16751665
"appSettings": [
@@ -1685,57 +1675,69 @@ resource sourcecontrol 'Microsoft.Web/sites/sourcecontrols@2022-03-01' = {
16851675
}
16861676
},
16871677
"dependsOn": [
1688-
"[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]",
1689-
"[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]"
1678+
"[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
1679+
"[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
16901680
]
16911681
},
16921682
{
16931683
"type": "Microsoft.Web/sites/config",
16941684
"apiVersion": "2022-03-01",
1695-
"name": "[format('{0}/appsettings', parameters('functionAppName'))]",
1685+
"name": "[format('{0}/{1}', variables('functionAppName'), 'appsettings')]",
16961686
"properties": {
1697-
"AzureWebJobsStorage": "[format('DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}', parameters('storageAccountName'), listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2021-09-01').keys[0].value)]",
1698-
"AzureWebJobsDashboard": "[format('DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}', parameters('storageAccountName'), listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2021-09-01').keys[0].value)]",
1687+
"AzureWebJobsStorage": "[format('DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}', variables('storageAccountName'), listKeys(variables('storageAccountName'), '2021-09-01').keys[0].value)]",
1688+
"AzureWebJobsDashboard": "[format('DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}', variables('storageAccountName'), listKeys(variables('storageAccountName'), '2021-09-01').keys[0].value)]",
16991689
"FUNCTIONS_EXTENSION_VERSION": "~3",
17001690
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
17011691
"Project": "src"
17021692
},
17031693
"dependsOn": [
1704-
"[resourceId('Microsoft.Web/sites', parameters('functionAppName'))]",
1705-
"[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]"
1694+
"[resourceId('Microsoft.Web/sites', variables('functionAppName'))]",
1695+
"[resourceId('Microsoft.Web/sites/sourcecontrols', variables('functionAppName'), 'web')]",
1696+
"[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
17061697
]
17071698
},
17081699
{
17091700
"type": "Microsoft.Web/sites/sourcecontrols",
17101701
"apiVersion": "2022-03-01",
1711-
"name": "[format('{0}/{1}', parameters('functionAppName'), 'web')]",
1702+
"name": "[format('{0}/{1}', variables('functionAppName'), 'web')]",
17121703
"properties": {
1713-
"repoUrl": "[parameters('repoUrl')]",
1704+
"repoUrl": "[parameters('repoURL')]",
17141705
"branch": "[parameters('branch')]",
17151706
"isManualIntegration": true
17161707
},
17171708
"dependsOn": [
1718-
"[resourceId('Microsoft.Web/sites', parameters('functionAppName'))]"
1709+
"[resourceId('Microsoft.Web/sites', variables('functionAppName'))]"
17191710
]
17201711
}
17211712
```
17221713

17231714
---
17241715

17251716
> [!TIP]
1726-
> This template uses the [Project](https://github.com/projectkudu/kudu/wiki/Customizing-deployments#using-app-settings-instead-of-a-deployment-file) app settings value, which sets the base directory in which the Functions deployment engine (Kudu) looks for deployable code. In our repository, our functions are in a subfolder of the **src** folder. So, in the preceding example, we set the app settings value to `src`. If your functions are in the root of your repository, or if you're not deploying from source control, you can remove this app settings value.
1717+
> This Bicep/ARM template uses the [Project](https://github.com/projectkudu/kudu/wiki/Customizing-deployments#using-app-settings-instead-of-a-deployment-file) app settings value, which sets the base directory in which the Functions deployment engine (Kudu) looks for deployable code. In our repository, our functions are in a subfolder of the **src** folder. So, in the preceding example, we set the app settings value to `src`. If your functions are in the root of your repository, or if you're not deploying from source control, you can remove this app settings value.
17271718
17281719
## Deploy your template
17291720

1730-
You can use any of the following ways to deploy your template:
1721+
You can use any of the following ways to deploy your Bicep file and template:
1722+
1723+
# [Bicep](#tab/bicep)
1724+
1725+
- [Azure CLI](../azure-resource-manager/bicep/deploy-cli.md)
1726+
- [PowerShell](../azure-resource-manager/bicep/deploy-powershell.md)
1727+
1728+
# [JSON](#tab/json)
17311729

1732-
- [PowerShell](../azure-resource-manager/templates/deploy-powershell.md)
1733-
- [Azure CLI](../azure-resource-manager/templates/deploy-cli.md)
17341730
- [Azure portal](../azure-resource-manager/templates/deploy-portal.md)
1735-
- [REST API](../azure-resource-manager/templates/deploy-rest.md)
1731+
- [Azure CLI](../azure-resource-manager/templates/deploy-cli.md)
1732+
- [PowerShell](../azure-resource-manager/templates/deploy-powershell.md)
1733+
1734+
---
17361735

17371736
### Deploy to Azure button
17381737

1738+
> [!NOTE]
1739+
> This method doesn't support deploying Bicep files currently.
1740+
17391741
Replace ```<url-encoded-path-to-azuredeploy-json>``` with a [URL-encoded](https://www.bing.com/search?q=url+encode) version of the raw path of your `azuredeploy.json` file in GitHub.
17401742

17411743
Here's an example that uses markdown:
@@ -1752,7 +1754,9 @@ Here's an example that uses HTML:
17521754

17531755
### Deploy using PowerShell
17541756

1755-
The following PowerShell commands create a resource group and deploy a template that creates a function app with its required resources. To run locally, you must have [Azure PowerShell](/powershell/azure/install-az-ps) installed. Run [`Connect-AzAccount`](/powershell/module/az.accounts/connect-azaccount) to sign in.
1757+
The following PowerShell commands create a resource group and deploy a Bicep file/ARM template that creates a function app with its required resources. To run locally, you must have [Azure PowerShell](/powershell/azure/install-az-ps) installed. Run [`Connect-AzAccount`](/powershell/module/az.accounts/connect-azaccount) to sign in.
1758+
1759+
# [Bicep](#tab/bicep)
17561760

17571761
```powershell
17581762
# Register Resource Providers if they're not already registered
@@ -1762,14 +1766,27 @@ Register-AzResourceProvider -ProviderNamespace "microsoft.storage"
17621766
# Create a resource group for the function app
17631767
New-AzResourceGroup -Name "MyResourceGroup" -Location 'West Europe'
17641768
1765-
# Create the parameters for the file, which for this template is the function app name.
1766-
$TemplateParams = @{"appName" = "<function-app-name>"}
1769+
# Deploy the template
1770+
New-AzResourceGroupDeployment -ResourceGroupName "MyResourceGroup" -TemplateFile main.bicep -Verbose
1771+
```
1772+
1773+
# [JSON](#tab/json)
1774+
1775+
```powershell
1776+
# Register Resource Providers if they're not already registered
1777+
Register-AzResourceProvider -ProviderNamespace "microsoft.web"
1778+
Register-AzResourceProvider -ProviderNamespace "microsoft.storage"
1779+
1780+
# Create a resource group for the function app
1781+
New-AzResourceGroup -Name "MyResourceGroup" -Location 'West Europe'
17671782
17681783
# Deploy the template
1769-
New-AzResourceGroupDeployment -ResourceGroupName "MyResourceGroup" -TemplateFile template.json -TemplateParameterObject $TemplateParams -Verbose
1784+
New-AzResourceGroupDeployment -ResourceGroupName "MyResourceGroup" -TemplateFile azuredeploy.json -Verbose
17701785
```
17711786

1772-
To test out this deployment, you can use a [template like this one](https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.web/function-app-create-dynamic/azuredeploy.json) that creates a function app on Windows in a Consumption plan. Replace `<function-app-name>` with a unique name for your function app.
1787+
---
1788+
1789+
To test out this deployment, you can use a [template like this one](https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.web/function-app-create-dynamic) that creates a function app on Windows in a Consumption plan.
17731790

17741791
## Next steps
17751792

0 commit comments

Comments
 (0)