You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Terraform配置Azure Function App的Deployment Center?

自动化配置Azure Function App Deployment Center方案

Terraform配置方案

通过azurerm_windows_function_app资源的source_control块可直接配置Deployment Center,以下是GitHub自动部署的示例:

resource "azurerm_resource_group" "example" {
  name     = "example-resources"
  location = "West Europe"
}

resource "azurerm_storage_account" "example" {
  name                     = "examplestorageacc"
  resource_group_name      = azurerm_resource_group.example.name
  location                 = azurerm_resource_group.example.location
  account_tier             = "Standard"
  account_replication_type = "LRS"
}

resource "azurerm_service_plan" "example" {
  name                = "example-service-plan"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location
  os_type             = "Windows"
  sku_name            = "Y1"
}

resource "azurerm_windows_function_app" "example" {
  name                       = "example-function-app"
  resource_group_name        = azurerm_resource_group.example.name
  location                   = azurerm_resource_group.example.location
  service_plan_id            = azurerm_service_plan.example.id
  storage_account_name       = azurerm_storage_account.example.name
  storage_account_access_key = azurerm_storage_account.example.primary_access_key

  # 配置Deployment Center(GitHub源)
  source_control {
    repo_url           = "https://github.com/your-username/your-repo.git"
    branch             = "main"
    manual_integration = false
    github_action_configuration {
      code_configuration {
        runtime_stack {
          runtime         = "dotnet-isolated"
          runtime_version = "6.0"
        }
      }
      os_type = "Windows"
    }
  }
}

若需关联Azure Repos,可将github_action_configuration替换为azure_devops_repo_configuration并调整对应参数即可。配置完成后,仓库代码推送会自动触发函数部署,无需重建Terraform资源。

Azure CLI配置方案

使用CLI命令快速配置Deployment Center,以GitHub源为例:

az functionapp deployment source config \
  --name <your-function-app-name> \
  --resource-group <your-resource-group-name> \
  --repo-url https://github.com/your-username/your-repo.git \
  --branch main \
  --manual-integration false \
  --github-action-enable true \
  --runtime dotnet-isolated \
  --runtime-version 6.0 \
  --os Windows

关联Azure Repos的命令示例:

az functionapp deployment source config \
  --name <your-function-app-name> \
  --resource-group <your-resource-group-name> \
  --repo-url https://dev.azure.com/your-org/your-project/_git/your-repo \
  --branch main \
  --manual-integration false

ARM模板配置方案

在ARM模板的Function App资源中添加sourceControl配置段:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "functionAppName": { "type": "string" },
    "location": { "type": "string" },
    "servicePlanName": { "type": "string" },
    "storageAccountName": { "type": "string" }
  },
  "resources": [
    {
      "type": "Microsoft.Web/sites",
      "apiVersion": "2022-03-01",
      "name": "[parameters('functionAppName')]",
      "location": "[parameters('location')]",
      "kind": "functionapp,windows",
      "properties": {
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('servicePlanName'))]",
        "storageAccountName": "[parameters('storageAccountName')]",
        "storageAccountAccessKey": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2021-04-01').keys[0].value]",
        "sourceControl": {
          "repoUrl": "https://github.com/your-username/your-repo.git",
          "branch": "main",
          "isManualIntegration": false,
          "githubActionConfiguration": {
            "codeConfiguration": {
              "runtimeStack": {
                "runtime": "dotnet-isolated",
                "runtimeVersion": "6.0"
              }
            },
            "osType": "Windows"
          }
        }
      }
    }
  ]
}

内容的提问来源于stack exchange,提问作者user1751825

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 17:42:56