'Terraform: specify backend type in azure
Context: While manually deploying a backend service in AZURE, I am prompted to select the type: custom, azure or service fabric.
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?
Solution 1:[1]
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!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | simone.benati |

