gpt4 book ai didi

Azure Function App - 使用 Terraform 配置 "Deployment Center"

转载 作者:行者123 更新时间:2023-12-03 06:13:07 26 4
gpt4 key购买 nike

我正在尝试使用 Terraform 设置 Azure Function App。

azurerm_windows_function_app_function 资源允许直接从 terraform 配置创建脚本。但是,由于某种原因,更改文件内容需要重新创建应用程序功能。这使得它无法使用,因为销毁/重新创建错误。

在门户中,可以配置要通过 SCM 部署的功能代码。但是我找不到通过 Terraform 配置“部署中心”的方法。

有什么方法可以自动配置功能应用的“部署中心”。 Terraform 是理想的选择,但如果可以使用 ARM 甚至 cli 命令来完成,那就没问题了。

最佳答案

azurerm_windows_function_app 中没有直接配置 SCM 或源代码控制的方法地形提供商。源代码控制 block 位于azurerm_function_app中提供商。

可以引用我的SO thread answer通过存储帐户将功能代码部署为通过存储帐户 URL 的 zip 文件。

我的main.tf:-

terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.59.0"
}
}
}


provider "azurerm" {

subscription_id = "xxxx4fd-e2b6e97cb2a7"
tenant_id = "xxxxce4-99ed-af9038592395"
client_id = "xxxxx8-6d26a31435cb"
client_secret = "xxxxxRt8313-CS0ifbLE"
features {
resource_group {
prevent_deletion_if_contains_resources = false
}
}

}

resource "azurerm_resource_group" "example" {
name = "azure-functions-example-rgsiddhesh"
location = "West Europe"
}

resource "azurerm_storage_account" "example" {
name = "examlpesasiliconstrg32"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
account_tier = "Standard"
account_replication_type = "LRS"
depends_on = [ azurerm_resource_group.example ]
}

resource "azurerm_app_service_plan" "example" {
name = "azure-functions-example-sp-siliconweb"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
kind = "Linux"
reserved = true
depends_on = [ azurerm_resource_group.example ]

sku {
tier = "Dynamic"
size = "Y1"
}

lifecycle {
ignore_changes = [
kind
]
}
}

resource "azurerm_function_app" "example" {
name = "example-azure-function-siliconfunc65"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
app_service_plan_id = azurerm_app_service_plan.example.id
storage_account_name = azurerm_storage_account.example.name
storage_account_access_key = azurerm_storage_account.example.primary_access_key
os_type = "linux"
version = "~4"
depends_on = [ azurerm_storage_account.example ]
app_settings = {
"FUNCTIONS_WORKER_RUNTIME" = "python",
"AzureWebJobsDisableHomepage" = "true",
"SCM_DO_BUILD_DURING_DEPLOYMENT" = "true"
}
site_config {
linux_fx_version = "python|3.10"
}
source_control {
repo_url = "https://github.com/username/functionrepo"
branch = "main"
}
}

您还可以通过 here 中的 Azure CLI 命令创建 github 操作工作流如下所示:-

命令:-

az functionapp deployment github-actions add --repo "sid24desai/funchttp" --branch main -g siliconrg5 -n siliconfunc32 --token github_pat_xxxxxxxxYA5UEkAZqq

输出:-

enter image description here

您可以在 terraform 脚本中运行相同的命令,如下所示:-

terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.62.1"
}
}
}


provider "azurerm" {
features {}
}


resource "azurerm_resource_group" "example" {
name = "azure-functions-example-rgsiddhesh"
location = "West Europe"
}

resource "azurerm_storage_account" "example" {
name = "eeeesasiliconstrg32"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
account_tier = "Standard"
account_replication_type = "LRS"
depends_on = [ azurerm_resource_group.example ]
}

resource "azurerm_app_service_plan" "example" {
name = "eeesiliconweb"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
kind = "Linux"
reserved = true
depends_on = [ azurerm_resource_group.example ]

sku {
tier = "Dynamic"
size = "Y1"
}

lifecycle {
ignore_changes = [
kind
]
}
}

resource "azurerm_function_app" "example" {
name = "eesiliconfunc65"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
app_service_plan_id = azurerm_app_service_plan.example.id
storage_account_name = azurerm_storage_account.example.name
storage_account_access_key = azurerm_storage_account.example.primary_access_key
os_type = "linux"
version = "~4"
depends_on = [ azurerm_storage_account.example ]
app_settings = {
"FUNCTIONS_WORKER_RUNTIME" = "python",
"AzureWebJobsDisableHomepage" = "true",
"SCM_DO_BUILD_DURING_DEPLOYMENT" = "true"
}
site_config {
linux_fx_version = "python|3.10"
}
}

resource "null_resource" "run_az_cli" {
provisioner "local-exec" {
command = "az functionapp deployment github-actions add --repo sid24desai/funchttp --branch main -g resourcegroupname -n function-name --token github_pat_xxxxxxxxA5UEkAZqq"
}
}

此命令将在您的存储库中创建一个新的工作流程文件,只需将函数应用程序名称替换为您的函数并运行工作流程:-

enter image description here

enter image description here

关于Azure Function App - 使用 Terraform 配置 "Deployment Center",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76549059/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com