0
votes

I am trying to automate adding custom domain to Azure App.

Here's what I thought of doing:

  • Trigger a HTTP call to Function App with a customDomain query param.
  • Take this query param and run a Azure Powershell script to add custom domain to Azure App.

Here's what I setup in function App:

run.ps1

param($req, $TriggerMetadata)

$customDomain = $req.Query.customDomain

Set-AzWebApp `
    -Name some-app `
    -ResourceGroupName SouthEastAsia ` 
    -HostNames @($customDomain,"some-app.azurewebsites.net")

Push-OutputBinding -Name res -Value ([HttpResponseContext]@{
    StatusCode = [System.Net.HttpStatusCode]::OK
    Body = "Added Custom Domain: $customDomain"
})

function.json

{
    "bindings": [
      {
        "authLevel": "anonymous",
        "type": "httpTrigger",
        "direction": "in",
        "name": "req",
        "methods": [
          "get",
          "post"
        ]
      },
      {
        "type": "http",
        "direction": "out",
        "name": "res"
      }
    ],
    "scriptFile": "./run.ps1"
}

But this is giving me 404 NotFound error when I trigger a HTTP Get request:

https://function.domain/api/AddCustomDomain?customDomain=test
1

1 Answers

0
votes

Is there a specific reason to pass an array into the -Hostnames param? It looks like you're trying to specify the default Azure hostname but it won't be required.

Try Set-AzWebApp -Name some-app -ResourceGroupName SouthEastAsia -HostNames "$customDomain"

If you do need multiple custom domains try wrapping your var in quotes Set-AzWebApp -Name some-app -ResourceGroupName SouthEastAsia -HostNames @("$customDomain1","$customDomain2","$customDomain3")