Kir*_*ran 2 terraform terraform-provider-azure
使用 Terraform,我创建了一个 Azure 静态 Web 应用程序,如下所示。但文档 没有演示如何设置资源的应用程序设置。对于普通的Azure功能应用程序,我们可以看到app_settings参数。但是如何为使用 Terraform 创建的 Azure 静态 Web 应用程序设置应用程序设置?
resource "azurerm_static_site" "example" {
name = "example"
resource_group_name = "example"
location = "West Europe"
}
Run Code Online (Sandbox Code Playgroud)
我喜欢为 Azure 静态 Web 应用程序设置参数AAD_CLIENT_ID并配置身份提供程序,如 Microsoft文档中所示。AAD_CLIENT_SECRET
原始答案:截至目前(2021 年 11 月 24 日),Azure 静态 Web 应用程序上的应用程序设置是一项开放功能请求。当该功能添加到 Terraform 时,我将更新此答案。
更新:使用 AzAPI Terraform 提供程序 [ 2 ],我们可以管理AzureRM 提供程序目前不支持的资源。下面的代码示例用于应用程序设置和 Azure 函数与静态 Web 应用程序的链接。
# For AzAPI provider
terraform {
required_providers {
azapi = {
source = "azure/azapi"
version = "~> 1.0"
}
}
}
# For static web app
resource azurerm_static_site swa {
name = "myswa"
resource_group_name = "myrg"
location = "westeurope"
# ignore below if you do not need to link functions
sku_tier = "Standard"
sku_size = "Standard"
}
# For application settings. You may change to azapi_resource once Github issue
# https://github.com/Azure/terraform-provider-azapi/issues/256 is closed.
resource azapi_resource_action appsetting {
type = "Microsoft.Web/staticSites/config@2022-03-01"
resource_id = "${azurerm_static_site.swa.id}/config/appsettings"
method = "PUT"
body = jsonencode({
properties = {
"mykey"="myvalue"
}
})
}
# For linking Azure function. Ignore if not needed
resource azapi_resource linktofunction {
type = "Microsoft.Web/staticSites/userProvidedFunctionApps@2022-03-01"
name = "swalinktofunction"
parent_id = azurerm_static_site.swa.id
body = jsonencode({
properties = {
functionAppRegion = "westeurope"
# below swafunction created else where
functionAppResourceId = azurerm_windows_function_app.swafunction.id
}
})
}
Run Code Online (Sandbox Code Playgroud)
对于应用程序设置,我被迫使用,azapi_resource_action因为azapi_resource无法解决问题 [ 3 ]。这有一个重要的后果:如果通过 Azure 门户或 az cli 等外部方式删除或更新应用程序设置,Terraform 将不会知道。这并不理想,但这是我们目前可以通过 Terraform 得到的最好结果。
| 归档时间: |
|
| 查看次数: |
4502 次 |
| 最近记录: |