简体   繁体   English

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

[英]Bicep ParentResourceNotFound for container registry in shared resource group

Via Bicep, I'm trying to setup my Azure infrastructure.通过 Bicep,我正在尝试设置我的 Azure 基础设施。 Two resource groups: one for shared resources, app service plans and a container registry.两个资源组:一个用于共享资源、应用程序服务计划和一个容器注册表。 The second one for a project specific resources, app services for the applications.第二个用于项目特定资源,应用程序的应用程序服务。

The container registry is linked to the appservice via linuxFxVersion.容器注册表通过 linuxFxVersion 链接到应用服务。 If I use the containerRegistryName, which comes from shared.bicep, I receive the error ParentResourceNotFound with the message Can not perform requested operation on nested resource.如果我使用来自 shared.bicep 的 containerRegistryName,我会收到错误 ParentResourceNotFound 和消息Can not perform requested operation on nested resource。 Parent resource 'crdevopstest' not found.未找到父资源“crdevopstest”。

When I use acrResource.name as shown in the code below, the container registry is in the same resource group as the app service, it works as expected.当我如下面的代码所示使用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'
        }
      ]
    }
  }
}

This StackOverflow POST it could be an issue if it is in another resource group.这个StackOverflow POST如果它在另一个资源组中,它可能是一个问题。

Does anyone knows if it is possible to use a shared container registry from a separate resource group?有谁知道是否可以使用来自单独资源组的共享容器注册表?

With the use of dependsOn and existing , I was able to deploy the Bicep.通过使用dependsOnexisting ,我能够部署 Bicep。

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 ]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM