0

我正在尝试使用 azure bicep 部署存储帐户。

在我的代码中:

resource storageAccounts_storageacntin_name_default 'Microsoft.Storage/storageAccounts/blobServices@2021-04-01' = {
  parent: storageAccounts_storageacntin_name_resource
  name: 'default'
  sku: {
    name: 'Standard_RAGRS'
    tier: 'Standard'
  }
  properties: {
    changeFeed: {
      enabled: false
    }
    restorePolicy: {
      enabled: false
    }
    containerDeleteRetentionPolicy: {
      enabled: true
      days: 7
    }
    cors: {
      corsRules: []
    }
    deleteRetentionPolicy: {
      enabled: true
      days: 30
    }
    isVersioningEnabled: true
  }
}

我在 SKU 中收到错误消息。错误如下。

The property "sku" is read-only. Expressions cannot be assigned to read-only properties.bicep(BCP073)

我不完全理解为什么会出现这个错误,我对 azure bicep 仍然很陌生,并试图从 terraform 部署缓慢移动到 azure bicep。请谁能解释我为什么会出现这个错误以及如何解决它?非常感谢

更新代码:

这是我删除 sku 时遇到的错误

param storageAccounts array = [
  'storage1'
]

resource storage_Accounts 'Microsoft.Storage/storageAccounts@2021-04-01' = [ for storageName in storageAccounts :{
  name: [storageName]
  location: 'westeurope'
  sku: {
    name: 'Standard_RAGRS'
    tier: 'Standard'
  }
  kind: 'StorageV2'
  properties: {
    allowCrossTenantReplication: true
    minimumTlsVersion: 'TLS1_2'
    allowBlobPublicAccess: false
    allowSharedKeyAccess: true
    networkAcls: {
      bypass: 'AzureServices'
      virtualNetworkRules: []
      ipRules: []
      defaultAction: 'Allow'
    }
    supportsHttpsTrafficOnly: true
    encryption: {
      services: {
        file: {
          keyType: 'Account'
          enabled: true
        }
        blob: {
          keyType: 'Account'
          enabled: true
        }
      }
      keySource: 'Microsoft.Storage'
    }
    accessTier: 'Hot'
  }
}]

resource storageAccounts_hamzaelaouane1_name_default 'Microsoft.Storage/storageAccounts/blobServices@2021-04-01' = [ for storageName in storageAccounts: {
  parent: [storage_Accounts]
  name: storageName
  properties: {
    changeFeed: {
      enabled: false
    }
    restorePolicy: {
      enabled: false
    }
    containerDeleteRetentionPolicy: {
      enabled: true
      days: 7
    }
    cors: {
      corsRules: []
    }
    deleteRetentionPolicy: {
      enabled: true
      days: 30
    }
    isVersioningEnabled: true
  }
}
]

错误在最后两行。它说那是期待}]在那一点上。逐行检查,我看不到任何语法错误

4

1 回答 1

1

对于存储帐户(如和)下的服务,该sku字段是只读的。blobServicesfileServices

您可以(仅)在存储帐户级别 ( Microsoft.Storage/storageAccounts@2021-04-01) 上设置 SKU。

要完整;该tier字段在存储帐户上也是只读的,因为它基于 SKU 名称。删除这些字段,您应该一切顺利。

于 2021-09-27T11:11:36.717 回答