共享资源组中容器注册表的Bicep ParentResourceNotFound



通过Bicep,我正在尝试设置我的Azure基础设施。两个资源组:一个用于共享资源、应用服务计划和一个容器注册表。第二个用于项目特定的资源,用于应用程序的应用程序服务。

容器注册表通过linuxFxVersion链接到appservice。如果我使用containerRegistryName,它来自shared。二头肌,我收到错误ParentResourceNotFound消息不能在嵌套资源上执行请求的操作。未找到父资源"crdevopstest"。

当我使用acrResource.name时,如下面的代码所示,容器注册表与应用服务在同一个资源组中,它按预期工作。

main.bicep

resource rg 'Microsoft.Resources/resourceGroups@2021-04-01' = {
name: 'rg-${projectName}-${env}'
location: resourceLocation
}
resource rgShared 'Microsoft.Resources/resourceGroups@2021-04-01' = if (env != 'dev') {
name: 'rg-${subscription}-${env}'
location: resourceLocation
}
module appServiceShared 'shared.bicep' = if (env != 'dev') {
name:'appShared'
scope: rgShared
params: {
subscription: subscription
env: env
appServicePlanSku: appServicePlanSku
crSku: crSku
}
}
module appService 'app.bicep' = {
name: 'app${projectName}'
scope: rg
params: {
applicationName: projectName
env: env
appServicePlanSharedId: appServiceShared.outputs.appServicePlanSharedLinuxId
//appServicePlanSharedName: appServiceShared.outputs.appServicePlanSharedLinuxName
containerRegistryName: appServiceShared.outputs.containerRegistryName
}
}

shared.bicep

resource appServicePlanSharedWindows 'Microsoft.Web/serverfarms@2021-01-15' = {
name: 'plan-${subscription}-${env}-windows'
location: location
sku: {
name: appServicePlanSku
}
}
resource appServicePlanSharedLinux 'Microsoft.Web/serverfarms@2021-01-15' = {
name: 'plan-${subscription}-${env}-${appService}'
location: location
sku: {
name: appServicePlanSku
}
kind: appService
properties: {
reserved: true
}
}
resource acrResource 'Microsoft.ContainerRegistry/registries@2021-06-01-preview' = {
name: 'cr${subscription}'
location: location
sku: {
name: crSku
}
properties: {
adminUserEnabled: true        // TO DO - replace by identity
}
}
output appServicePlanSharedWindowsId string = appServicePlanSharedWindows.id
output appServicePlanSharedLinuxId string = appServicePlanSharedLinux.id
//output appServicePlanSharedLinuxName string = appServicePlanSharedLinux.name
output containerRegistryName string = acrResource.name

app.bicep

resource acrResource 'Microsoft.ContainerRegistry/registries@2021-06-01-preview' = {
name: 'crdevopsnick'
location: location
sku: {
name: 'Basic'
}
properties: {
adminUserEnabled: true        // TO DO - replace by identity
}
}
resource appServiceApi 'Microsoft.Web/sites@2021-03-01' = {
name: 'ase-${applicationName}-api-dotnet-${env}'
location: location
properties: {
serverFarmId: appServicePlanSharedId
httpsOnly: true
siteConfig: {
linuxFxVersion: 'DOCKER|${acrResource.name}.azurecr.io/${applicationName}service:latest'
appSettings: [
{
name: 'DOCKER_REGISTRY_SERVER_URL'
value: 'https://mcr.microsoft.com'
} 
{
name: 'DOCKER_REGISTRY_SERVER_USERNAME'
value: acrResource.name
} 
{
name: 'DOCKER_REGISTRY_SERVER_PASSWORD'
value: listCredentials(resourceId('Microsoft.ContainerRegistry/registries', acrResource.name), '2021-06-01-preview').passwords[0].value //acrResource.listCredentials().passwords[0].value
}
{
name: 'WEBSITES_PORT'
value: '7122'
}
]
}
}
}

如果它在另一个资源组中,则可能是一个问题。

有没有人知道是否可以从单独的资源组中使用共享容器注册表?

使用dependsOn现有和,我能够部署肱二头肌。

module appService 'app.bicep' = {
name: 'app${projectName}'
scope: rg
params: {
applicationName: projectName
env: env
sharedRgName: rgShared.name
containerRegistryName: appServiceShared.outputs.containerRegistryName
}
dependsOn: [ appServiceShared ]
}
resource acrResource 'Microsoft.ContainerRegistry/registries@2021-09-01' existing = {
name: 'crtdevops'
scope: resourceGroup(sharedRgName)
}
resource appServiceApi 'Microsoft.Web/sites@2022-03-01' = {
name: 'ase-${applicationName}-api-dotnet-${env}'
location: location
properties: {
serverFarmId: sharedPlan.id
httpsOnly: true
siteConfig: {
linuxFxVersion: 'DOCKER|${containerRegistryName}.azurecr.io/${applicationName}service:latest'
appSettings: [
{
name: 'DOCKER_REGISTRY_SERVER_URL'
value: 'https://mcr.microsoft.com'
} 
{
name: 'DOCKER_REGISTRY_SERVER_USERNAME'
value: containerRegistryName
} 
{
name: 'DOCKER_REGISTRY_SERVER_PASSWORD'
value: acrResource.listCredentials().passwords[0].value
}
{
name: 'WEBSITES_PORT'
value: '7122'
}
]
}
}
dependsOn: [ acrResource ]
}

最新更新