Terraform: specify backend type in azure
Asked Answered
E

1

6

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?

Ella answered 27/4, 2022 at 15:5 Comment(0)
E
7

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}"
Ella answered 28/4, 2022 at 7:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.