0

I am trying to deploy a storage account using azure bicep.

In my code:

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

I get an error in the SKU. The error is the following.

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

I don't fully understand why is this error showing up, I am still new to azure bicep and trying to move slowly from terraform deployments to azure bicep. Please can anyone explain me why is this error is coming up and how to solve it? Thank you so much

UPDATE CODE:

this is the error I am getting when I removed the 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
  }
}
]

the error is at the last 2 lines. It says that is expecting } and ] at that point. Checking line by line, I couldn't see any error on syntax

Nayden Van
  • 1,133
  • 1
  • 23
  • 70

1 Answers1

1

The sku field is read-only for services that are under a storage account like blobServices and fileServices.

You can (only) set the SKU on Storage Account level (Microsoft.Storage/storageAccounts@2021-04-01).

To be complete; the tier field is also read-only on the storage account, since it's based on the SKU name. Remove these fields and you should be good to go.

rickvdbosch
  • 14,105
  • 2
  • 40
  • 53
  • Thank you so so much for your reply. Is clear now why is not working. Just another question, which I believe is related to this error. I implemented a loop, to create multiple storage accounts with one script, as soon as I removed the sku, I got the error about syntax. Which it wasn't there before. I will update my post. Thank you so much once again for your super clear explanation – Nayden Van Sep 27 '21 at 11:31