簡體   English   中英

Bicep ParentResourceNotFound 用於共享資源組中的容器注冊表

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

通過 Bicep,我正在嘗試設置我的 Azure 基礎設施。 兩個資源組:一個用於共享資源、應用程序服務計划和一個容器注冊表。 第二個用於項目特定資源,應用程序的應用程序服務。

容器注冊表通過 linuxFxVersion 鏈接到應用服務。 如果我使用來自 shared.bicep 的 containerRegistryName,我會收到錯誤 ParentResourceNotFound 和消息Can not perform requested operation on nested resource。 未找到父資源“crdevopstest”。

當我如下面的代碼所示使用acrResource.name時,容器注冊表與應用程序服務位於同一資源組中,它按預期工作。

主二頭肌

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

共享二頭肌

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

應用程序二頭肌

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

這個StackOverflow POST如果它在另一個資源組中,它可能是一個問題。

有誰知道是否可以使用來自單獨資源組的共享容器注冊表?

通過使用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