如何将文件共享挂载到 Bicep 中的 Azure 容器应用程序环境?

问题描述 投票:0回答:1

目前,我在将文件共享安装到 Azure 容器应用程序环境时遇到问题。

问题是卷安装不是幂等的,如果具有相同名称的卷安装已经存在,则在运行管道和 bicep 时会收到错误:

托管环境存储“storageMountName”的请求正文无效。只能更新“properties.azureFile.AccountKey”

我的二头肌模块:

param storageName string
param storageMountName string
param storageFileShareName string
param ACAEnvironmentResourceName string
@secure()
param storageAccountKey string

resource containerEnvironment 'Microsoft.App/managedEnvironments@2023-05-01' existing = {
  name: ACAEnvironmentResourceName
}

resource qdrantstorage 'Microsoft.App/managedEnvironments/storages@2023-05-01' = {
  parent: containerEnvironment
  name: storageMountName
  properties: {
    azureFile: {
      accountName: storageName
      shareName: storageFileShareName
      accountKey: storageAccountKey
      accessMode: 'ReadWrite'
    }
  }
}

我尝试安装具有唯一名称的卷,完全没有问题,一切运行顺利。 问题是当我尝试“重新安装”该卷时。 我明白为什么这可能是一个问题,但这种行为使得二头肌模板

'Microsoft.App/managedEnvironments/storages@2023-05-01'
幂等。

我当前正在尝试的是找到一种解决方法,在其中我可以检查具有给定名称的已安装卷是否已存在,如果存在,我将使安装步骤成为有条件的。

请注意,我是二头肌新手,如果我的方法错误,请告诉我。

azure azure-devops azure-storage azure-bicep azure-container-apps
1个回答
0
投票

从我在您的 Bicep 代码中看到的情况来看,您正在尝试将文件共享安装到 Bicep 中的 Azure 容器应用程序环境。我看不到您的存储创建或信息。换句话说,“Microsoft.App/managedEnvironments/storages@2023-05-01”既不会创建存储帐户,也不会创建文件共享。

话虽如此,您需要添加缺少的元素,所以类似以下的内容是一个有效的示例:

var storageName = 'uniquenamemax24chr'
var shareName = 'share'
var mountName = 'storagemountname'

resource containerEnvironment 'Microsoft.App/managedEnvironments@2023-05-01' existing = {
  name: ACAEnvironmentResourceName
}

resource storageAccount 'Microsoft.Storage/storageAccounts@2023-01-01' = {
  name: storageName 
  location: location
  kind: 'Storage'
  sku: {
    name: 'Standard_LRS'
  }
}

resource fileService 'Microsoft.Storage/storageAccounts/fileServices/shares@2023-01-01' = {
  name: '${storageAccount.name}/default/${shareName}'
  properties: {}
}

resource qdrantstorage 'Microsoft.App/managedEnvironments/storages@2023-05-01' = {
  parent: containerEnvironment
  name: mountName
  properties: {
    azureFile: {
      accountName: storageName 
      shareName: shareName 
      accountKey: storageAccount.listKeys().keys[0].value
      accessMode: 'ReadWrite'
    }
  }
}

如果您已经创建了存储帐户和文件存储,则可以使用相同的概念,您可以将其作为参数传递,也可以使用现有的来获取存储对象并传递所需的变量。

有两件事要提一下

  1. 存储命名约定应始终为小写字母:

    accountname
    sharename
    mountname

  2. 当我部署解决方案时,我使用增量模式。

它有效,这是最终结果:

© www.soinside.com 2019 - 2024. All rights reserved.