gpt4 book ai didi

在 Terraform 中使用 azurerm_runction_app_function 时,Azure 函数 Url 不包含身份验证代码

转载 作者:行者123 更新时间:2023-12-03 03:40:02 27 4
gpt4 key购买 nike

当您在 Azure 中设置函数时,它可以让您使用功能键获取默认函数 Url。它看起来有点像:

https://my-function-app.azurewebsites.net/api/my-function-name?code=[authentication-code]

这让我可以从 API 端点调用该函数,而无需使用任何其他身份验证。我正在尝试通过 azurerm 提供商以某种方式访问​​该 key 。更新:我正在使用 Terraform 1.1.7 版本和 azurerm 提供程序 v3.0.2。

我可以使用 azurerm_function_app_function.my-function.url 获取主 Url(不包括身份验证代码)。我可以使用 data.azurerm_function_app_host_keys.default_function_key 获取主机 key 。

data "azurerm_function_app_host_keys" "function-host-keys" {
name = azurerm_windows_function_app.function-app.name
resource_group_name = azurerm_resource_group.resource-group.name
}

resource "azurerm_function_app_function" "my-function" {
name = my-function
function_app_id = azurerm_windows_function_app.function-app.id
language = "CSharp"

file {
name = "MyFunc.cs"
content = file("../../MyFunc.cs")
}

config_json = jsonencode({
"bindings" = [
{
"authLevel" = "function"
"direction" = "in"
"methods" = [
"get",
"post",
]
"name" = "req"
"type" = "httpTrigger"
},
{
"direction" = "out"
"name" = "$return"
"type" = "http"
}
]
})
}

locals {
# This gets the host key but I need the function key
host-key = data.azurerm_function_app_host_keys.function-host-keys.default_function_key

# This gets the url, but without the "?code=######"
url = azurerm_function_app_function.my-function.url

# How do I get the function key for the ?code=#### part of the Url?
code = data.azurerm_some_function_resource.function_key
}

但我似乎找不到任何可以为我的特定功能提供默认功能键的内容,如 Azure 门户中提供的那样。请帮忙。

最佳答案

您可以为新创建的 FunctionApp 使用带有 dependent_on 的数据源吗?

data "azurerm_function_app_host_keys" "item" {
name = azurerm_function_app.item.name
resource_group_name = azurerm_function_app.item.resource_group_name

depends_on = [
azurerm_function_app.item
]
}

https://github.com/hashicorp/terraform-provider-azurerm/issues/8515#issuecomment-694515657

关于在 Terraform 中使用 azurerm_runction_app_function 时,Azure 函数 Url 不包含身份验证代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71666375/

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