0

I have a bicep to deploy a static web app:

@description('rootCustomDomainName')
param rootCustomDomainName string = 'https://xyz.contoso.com'

resource staticWebApp 'Microsoft.Web/staticSites@2022-03-01' = {
  name: 'my-ui'
  location: location
  sku: {
    name: 'Free'
    tier: 'Free'
  }
  properties: {
    allowConfigFileUpdates: true
    branch: branch
    buildProperties: {
      appLocation: 'UI/web-app'
      skipGithubActionWorkflowGeneration: true
    }
    enterpriseGradeCdnStatus: 'Disabled'
    provider: 'DevOps'
    repositoryUrl: repositoryUrl
    stagingEnvironmentPolicy: 'Disabled'
  }
}

resource rootCustomDomain 'Microsoft.Web/staticSites/customDomains@2022-03-01' = {
  parent: staticWebApp
  name: rootCustomDomainName
  properties: {}
}

On deploying this, I see the following error:

[error]Deployment template validation failed: 'The template resource my-ui/https://xyz.contoso.com for type 'Microsoft.Web/staticSites/customDomains' at line '1' and column '2294' has incorrect segment lengths. A nested resource type must have identical number of segments as its resource name. A root resource type must have segment length one greater than its resource name.

What am I missing? How do I fix this?

user989988
  • 3,006
  • 7
  • 44
  • 91

1 Answers1

0
  • I have tried to reproduce in my environment and got below results.

  • I have followed the template which you have provided.

  • We need to pass only a custom domain name. Ex:xyz.contoso.com in the template but after that I got the below error.

enter image description here

Modified bicep Template:

param staticWebApp string = '<staticWebAppName>'
param repositoryUrl string ='<Url>'
param DomainName string = 'CustomDomainName'

resource static_name_resource 'Microsoft.Web/staticSites@2022-03-01' = {
  name: staticWebApp
  location: 'WestUS2'
  sku:
{
name: 'Free'
    tier: 'Free'
  }
properties:
{
repositoryUrl: repositoryUrl
branch: 'main'
    stagingEnvironmentPolicy: 'Disabled'
    allowConfigFileUpdates: true
    provider: 'DevOps'
    enterpriseGradeCdnStatus: 'Disabled'
  }
}

resource static_DomainName 'Microsoft.Web/staticSites/customDomains@2022-03-01' = {
  parent: static_name_resource
  name: DomainName
  location: 'globel'
  properties:
{
}
}


  • The static web app is deployed successfully but custom domain is not deployed.

  • For that you need to attach the auto generated URL of static web app to custom domain in DNS Zone to verify auto generated URL of static web app and attach the custom domain as below.

  • Search for DNS Zone and use the auto generated URL in Alias as below and click on save.

enter image description here

  • After the above steps redeploy the static app once again as below.

enter image description here

  • Now The Custom domain is added successfully to static web app.

enter image description here

  • After that navigate to static web app -> custom domain.

enter image description here

Tarun Krishna
  • 366
  • 2
  • 6