Paul Farry
Paul Farry

Reputation: 4768

How to Create App Service with a subType of api

In powershell and using the new-azwebapp to create a website in our app service plan. But it only ever seems to create a type of app

I'm trying to create it with the type of api like you can when you select from the Azure Portal UI, but I can't see a setting in the configuration to do this.

After creating I set the AppSettings and then try to update the Type, but it doesn't seem to matter.

Hoping that I'm missing something simple.

$siteName = "namegoeshere"
$sitePlan = "myplanname"
$siteLocation  = "Australia East"
$siteResourceGroup = "resourcegroupname"

$createdSite = new-azWebApp -Name $siteName -ResourceGroupName $siteResourceGroup -AppServicePlan $sitePlan -Location $siteLocation

$newAppSettings = @{ "name"="value"}
Set-AzWebApp -Name $siteName -ResourceGroupName $siteResourceGroup -AppSettings $newAppSettings -AppServicePlan Grower  #-PhpVersion 0

$p = @{ 'type' = "api" }
$r = Set-AzResource -Name $siteName -ResourceGroupName $siteResourceGroup -ResourceType Microsoft.Web/sites  -PropertyObject $p -ApiVersion 2016-03-01 -Kind "app"
echo $r.Properties

Upvotes: 0

Views: 106

Answers (1)

George Chen
George Chen

Reputation: 14334

The type api is not set with type, in the New-AzureRmResource parameters there is a parameter to set it, it's [-Kind <String>]. You could check it here.

Here is an example.

# CREATE "just-an-api" API App

$ResourceLocation = "West US"
$ResourceName = "just-an-api"
$ResourceGroupName = "demo"
$PropertiesObject = @{
    # serverFarmId points to the App Service Plan resource id
    serverFarmId = "/subscriptions/SUBSCRIPTION-GUID/resourceGroups/demo/providers/Microsoft.Web/serverfarms/plan1"
}

    New-AzureRmResource -Location $ResourceLocation `
        -PropertyObject $PropertiesObject `
        -ResourceGroupName $ResourceGroupName `
        -ResourceType Microsoft.Web/sites `
        -ResourceName "just-an-api/$ResourceName" `
        -Kind 'api' `
        -ApiVersion 2016-08-01 -Force

Upvotes: 1

Related Questions