Terraform:在Azure中指定后端类型

发布于 2025-01-24 15:47:38 字数 1062 浏览 3 评论 0原文

上下文:在手动在Azure中部署后端服务时, 提示我选择类型:自定义,Azure或服务面料。

如何通过Terraform声明类型(我想选择Azure资源)并说我要使用哪个应用程序? 根据文档,它说使用该应用程序的资源ID(我在部署开始时生成),然后我尝试了:

    resource "azurerm_api_management_backend" "polo-backend" {
  name                = "polo-backend"
  resource_group_name = azurerm_resource_group.polo-rg.name
  api_management_name = azurerm_api_management.polo-api-mgmt.name
  protocol            = "http"
  url                 = "https://myurl"
  resource_id = azurerm_windows_web_app.app-service.id
}

但是它给了我这个错误:

错误:创建 /更新后端:(名称“ polo-backend” / service名称“ polo-api-mgmt” / resource group“ polo1-default-rg”):apimanagement.backendclient#createorupdate:失败响应对 请求:statuscode = 400-原始错误:Autorest/Azure:服务返回错误。 status = 400代码=“ validationError” messages =“一个或多个字段包含不正确的值:” ResourceD“}]

此外。如果应用程序是用Terraform生成的,我该如何在URL部分中动态分配URL?

Context: While manually deploying a backend service in AZURE,
I am prompted to select the type: custom, azure or service fabric.

enter image description here

How can I declare via terraform the type (I would like to select Azure resource) and say which app I want to use?
As per documentation it says to use a resource id of the app (that i generate at the start of the deployment) and I tried this:

    resource "azurerm_api_management_backend" "polo-backend" {
  name                = "polo-backend"
  resource_group_name = azurerm_resource_group.polo-rg.name
  api_management_name = azurerm_api_management.polo-api-mgmt.name
  protocol            = "http"
  url                 = "https://myurl"
  resource_id = azurerm_windows_web_app.app-service.id
}

But it gives me this error:

Error: creating/updating Backend: (Name "polo-backend" / Service Name "polo-api-mgmt" / Resource Group "polo1-default-rg"): apimanagement.BackendClient#CreateOrUpdate: Failure responding to
request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="ValidationError" Message="One or more fields contain incorrect values:" Details=[{"code":"ValidationError","message":"Value should represent absolute http URL","target":"resourceId"}]

Furthermore.. if the app is generated with terraform how can I assign the URL dynamically in the URL section?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猫弦 2025-01-31 15:47:38

因此,我找到了我问题的答案:

基本上,您必须将资源ID(文字网址)传递给所需的资源。通过参数传递它,到目前为止不支持它,或者我试图分配的那个论点是错误的。

因此,我设法做的是使用数据模块尽可能多地“模板化”代码:

    resource "azurerm_api_management_backend" "polo-backend" {
name                = "polo-backend"
resource_group_name = azurerm_resource_group.polo-rg.name
api_management_name = azurerm_api_management.polo-api-mgmt.name
protocol            = "http"
url                 = "https://${azurerm_windows_web_app.app-service.name}.azurewebsites.net"
resource_id = "https://management.azure.com/subscriptions/${data.azurerm_client_config.mysubid.subscription_id}/resourceGroups/${azurerm_resource_group.polo-rg.name}/providers/Microsoft.Web/sites/${azurerm_windows_web_app.app-service.name}"
}

如果有人有更好的解决方案,请随时建议!

编辑:
感谢您的答案 - 我能够使用以下方式解决错误:

resource_id = "https://${azurerm_windows_function_app.functionapp.name}.azurewebsites.net${azurerm_windows_function_app.functionapp.id}"

So I found the answer to my question:

Basically you have to pass to the resource id, the literal URL to the desired resource. passing it via arguments it's not supported as of now OR that argument I was trying to assign is wrong.

So what I managed to do was using the data module to "template-ify" the code as much as I can:

    resource "azurerm_api_management_backend" "polo-backend" {
name                = "polo-backend"
resource_group_name = azurerm_resource_group.polo-rg.name
api_management_name = azurerm_api_management.polo-api-mgmt.name
protocol            = "http"
url                 = "https://${azurerm_windows_web_app.app-service.name}.azurewebsites.net"
resource_id = "https://management.azure.com/subscriptions/${data.azurerm_client_config.mysubid.subscription_id}/resourceGroups/${azurerm_resource_group.polo-rg.name}/providers/Microsoft.Web/sites/${azurerm_windows_web_app.app-service.name}"
}

IF anyone has a better solution than this please feel free to suggest!

EDIT:
Thanks for this answer - I was able to resolve the error using:

resource_id = "https://${azurerm_windows_function_app.functionapp.name}.azurewebsites.net${azurerm_windows_function_app.functionapp.id}"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文