Search code examples
azureterraformazure-web-app-serviceazure-appservice

provision API AppServices using Terraform


is it possible to provision APi app service using https://azure.microsoft.com/en-ca/products/app-service/api through terraform Seems only possible to provision web apps https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/windows_web_app how to provision API web apps using terraform.


Solution

  • provision API App Services using Terraform:

    It is not possible to provision API app services with terraform. You can create API Management under web app API block with the help of azurerm_api_management resource provider.

    enter image description here

    There is a parameter called kindin azurerm_windows_web_app resource provider terraform but kind = "Api" is not supported in any versions. The only supported are app, windows, linux etc but not an Api.

    To create an API app, use Az CLI command az resource create in the below format.

    az resource create -g examplejahresources -n jahserviceapi --resource-type Microsoft.web/sites --is-full-object --properties "{ 
    \"kind\": \"api\", \"location\": \"West US\", \"properties\": { \"serverFarmId\": \"/subscriptions/xxxx/resource
    Groups/examplejahresources/providers/Microsoft.Web/serverFarms/jahplan\" } }"
    

    With kind = "App" you can be able to create and deploy it using terraform as shown below.

      provider "azurerm" {
          features {}
        }
        
        data "azurerm_resource_group" "example" {
          name     = "xxxx"
        }
        
        resource "azurerm_app_service_plan" "example" {
          name                = "webapp-appserviceplan"
          location            = data.azurerm_resource_group.example.location
          resource_group_name = data.azurerm_resource_group.example.name
          kind                = "Api"
          reserved            = true
          sku {
            tier = "Standard"
            size = "S1"
          }
        }
        
        resource "azurerm_windows_web_app" "example" {
          name                = "testingja"
          resource_group_name = data.azurerm_resource_group.example.name
          location            = data.azurerm_resource_group.example.location
          service_plan_id     = azurerm_app_service_plan.example.id
         
         site_config {}
        }
    

    Output:

    enter image description here

    enter image description here

    Reference: Github issue