Bicep部署静态Web应用遇段长度错误,如何修复域名配置?
问题
我有一个用于部署静态Web应用的Bicep文件:
@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: {} }
部署该文件时,出现以下错误:
[error]Deployment template validation failed: 'The template resource
my-ui/https://xyz.contoso.comfor 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.
请问我遗漏了什么?该如何修复?
原因与修复方案
错误原因:自定义域名参数包含了
https://前缀,而Azure静态Web应用的自定义域名资源名称仅需纯域名(不含协议前缀)。带前缀的字符串作为子资源名称时,会导致资源ID格式错误(出现斜杠分割的多余段),触发模板验证失败。修复步骤:
- 修改参数
rootCustomDomainName的默认值,移除https://前缀,仅保留纯域名:@description('rootCustomDomainName') param rootCustomDomainName string = 'xyz.contoso.com' - 确保传递该参数时,仅传入纯域名(不含任何协议前缀)。
- 修改参数
修改后,自定义域名资源的名称会变为my-ui/xyz.contoso.com,符合Azure资源ID的格式要求,可通过模板验证并完成部署。
内容的提问来源于stack exchange,提问作者user989988
相关产品推荐
相关产品推荐

