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

如何通过Terraform配置Linux版Azure函数应用的部署中心

配置Azure Linux函数应用的SCM源代码管理(Terraform实现)

你可以直接在azurerm_linux_function_app资源块内添加source_control嵌套块来配置ExternalGit,无需依赖单独的azurerm_app_service_source_control资源——这个资源主要针对传统App Service,Linux函数应用现在支持内嵌配置SCM。

以下是修改后的完整配置示例,包含ExternalGit的SCM设置:

resource "azurerm_linux_function_app" "function-app" {
  name                       = "function-app-${random_string.function_app_suffix.result}"
  location                   = var.location
  resource_group_name        = var.ise_resource_group
  service_plan_id            = azurerm_service_plan.ise-asp.id
  storage_account_name       = azurerm_storage_account.ise-app-storage.name
  storage_account_access_key = azurerm_storage_account.ise-app-storage.primary_access_key

  app_settings = {
    "AzureWebJobsStorage"            = azurerm_storage_account.ise-app-storage.primary_connection_string
    "APPINSIGHTS_INSTRUMENTATIONKEY" = azurerm_application_insights.func-appinsights.instrumentation_key
    "AppConfigConnectionString"      = azurerm_app_configuration.ise_appconf.primary_read_key[0].connection_string
  }

  # 新增SCM源代码管理配置
  source_control {
    repo_url           = "https://github.com/your-username/your-repo.git" # 替换为你的Git仓库地址
    branch             = "main" # 部署目标分支
    git_token          = var.git_personal_access_token # 私有仓库需要,建议用变量或Key Vault引用
    manual_integration = false # 设置为false开启持续集成,提交代码自动触发部署
  }

  site_config {
    application_stack {
      python_version = "3.10"
    }
  }
}

关键参数说明:

  • repo_url: 你的Git仓库的HTTPS地址(支持GitHub、GitLab、Bitbucket等)
  • branch: 指定要部署的代码分支
  • git_token: 私有仓库需提供个人访问令牌(PAT),公仓可省略该参数
  • manual_integration: 设置为false时开启持续集成,代码提交到指定分支后自动触发函数应用部署;设置为true则需要手动触发部署

注意事项:

  1. 不要硬编码git_token,建议通过Terraform变量传入,或使用azurerm_key_vault_secret从Azure Key Vault引用,避免敏感信息泄露
  2. 确保你的Git仓库包含正确的函数应用项目结构(比如Python项目需有requirements.txt和函数代码文件)
  3. 如果需要使用SSH地址而非HTTPS,可替换repo_url为SSH格式,并配置SSH密钥认证(需额外设置ssh_key参数)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 04:07:32