wasim
wasim

Reputation: 13

Trying to create a fileshare storage account using Bicep but getting errors

Im trying to deploy a basic fileshare storage account. Please ignore the commented out lines. when I do what-if via pipeline, i get this error image. Im not sure what is the error is, i have created the parameter in param file annd declared that param at the top of bicep file with its correct data type.

The below is bicep file

//--Parameters--//
@description('Specifies the location for resources.')
param saLoc string

@description('Optional. Type of Storage Account to create.')
param saKind string

// The below is optional - if you want to create a fileshare stoarge account with private endpoint, you might need to give the private ip of the private endpoint here
// @description('Specifies the private IP Address of the Storage Account blob private endpoint.')
// param saBlobPrivIp string = ''

@description('Optional. Storage Account Sku Name.')
@allowed([
  'Standard_LRS'
  'Standard_GRS'
  'Standard_RAGRS'
  'Standard_ZRS'
  'Premium_LRS'
  'Premium_ZRS'
  'Standard_GZRS'
  'Standard_RAGZRS'
])
param saSkuName string

param saShareQuota int

@description('Specifies the storage account to create')
param saName string

@description('Tags for the storage account')
param saTags object

@description('Array of File Shares to create')
param saFileShares array

// The below parameter is optional -  if you want to link subnet with privateendpoint
// @description('Subnet to connect Storage Account Private Endpoints')
// param saSubnet string

// The below parameter is optional - if using identity-based authentication settings for Azure Files, then uncomment the below

// @description('Optional. Provides the identity-based authentication settings for Azure Files.')
// param saazureFilesIdentityBasedAuthentication object = {}

//--Variables--//
// Loading values from the JSON file directly, some below are optional - if using private dns zone and domain, add them in envconstants file and uncomment the below
var targetEnv = loadJsonContent('../../envconstants.json', 'targetEnvironment')
// var privDNSZoneId = loadJsonContent('../../envconstants.json', 'privDNSZoneId')
// var domain = loadJsonContent('../../envconstants.json', 'domain')

// Extracting specific values from the JSON, some below are optional - if using managed domain add that in stoarge account, add that in envconstants file and uncomment this
// var privDnsZoneFileCore = privDNSZoneId.fileCore
// var mgDomainGuid = domain.managedDomainGuid
// var mgDomainName = domain.managedDomainName

// Enable Private Endpoints, the below is optional - if using private endpoint in stoarge account, keep this to true
// var deployStorageAccPrivateEndpoints = false

//--Modules--//
module storageAccount 'br/public:avm/res/storage/storage-account:0.12.0' = {
  name: saName
  scope: resourceGroup(targetEnv.subId, targetEnv.resourceGrp)
  params: {
    location: saLoc
    kind: saKind
    skuName: saSkuName

    // Required parameters
    name: toLower(saName)

    // Non-required parameters
    allowBlobPublicAccess: false
    publicNetworkAccess: 'Disabled'
    requireInfrastructureEncryption: true
    sasExpirationPeriod: '30.00:00:00'

    networkAcls: {
      bypass: 'AzureServices'
      defaultAction: 'Deny'
    }

    tags: saTags 


    // azureFilesIdentityBasedAuthentication: !empty(saazureFilesIdentityBasedAuthentication) ? {
    //   activeDirectoryProperties: {
    //     domainGuid: mgDomainGuid
    //     domainName: mgDomainName
    //   }
    //   defaultSharePermission: saazureFilesIdentityBasedAuthentication.defaultSharePermission
    //   directoryServiceOptions: 'AADDS'
    // } : {}

    fileServices: !empty(saFileShares) ? {
      shareDeleteRetentionPolicy: {
        days: 7
        enabled: true
      }
      shares: saFileShares
      shareQuota: saShareQuota
      tags: saTags
    } : {}

  

    // privateEndpoints: deployStorageAccPrivateEndpoints ? [
    //   !empty(saFilePrivIp) ? {
    //     privateDnsZoneResourceIds: [ privDnsZoneFileCore ]
    //     name: '${saName}-${saLoc}-file-pep'
    //     service: 'file'
    //     location: saLoc
    //     subnetResourceId: saSubnet
    //     customNetworkInterfaceName: '${saName}-${saLoc}-file-nic'
    //     ipConfigurations: [
    //       {
    //         name: '${saName}-file-ipconf'
    //         properties: {
    //           groupid: 'file'
    //           membername: 'file'
    //           privateIPAddress: saFilePrivIp
    //         }
    //       }
    //     ]
    //     tags: {
    //       'hidden-title': saName
    //     }
    //   } : {
    //     privateDnsZoneResourceIds: [ privDnsZoneFileCore ]
    //     name: '${saName}-${saLoc}-file-pep'
    //     service: 'file'
    //     location: saLoc
    //     subnetResourceId: saSubnet
    //     customNetworkInterfaceName: '${saName}-${saLoc}-file-nic'
    //     tags: {
    //       'hidden-title': saName 
    //     }
    //   }
    // ] : []
  }
}

The below is the bicepparam file

param saName = 'testfileshare'

param saLoc = 'South Central US'

param saKind = 'StorageV2'

param saShareQuota = 200

param saSkuName = 'Standard_LRS'

param saFileShares = [{ name: 'default' }]

param saTags = {
  environment: 'TEST-PERSONAL-REPO'
  created_by: 'bicep'
}

The below is the error image image description

Upvotes: 1

Views: 150

Answers (1)

Vinay B
Vinay B

Reputation: 2401

Create a fileshare storage account using Bicep.

During these cases the might be with the parameter with the spelling or parameter type you declared in module and top level in the file.

from the error description the error seems to be with the way you pass the parameter. Here from the error description I can clearly identify the extra space with the parameter.

templete parameter 'param saName '

Remove this extra space after saName which leads to this isssue youre facing.

the actual parameter input looks something like this 'param saName' this is what bicep is expecting as an input parameter.

I Tried a demo configuration with relevent inputs and I was able to provision the requriement.

Configuration:

param saLoc string
param saKind string = 'StorageV2'
param saShareQuota int = 100
param saSkuName string = 'Standard_LRS'
param saName string
param saTags object
param saFileShares array = []

module storageAccount 'br/public:avm/res/storage/storage-account:0.12.0' = {
  name: saName
  scope: resourceGroup('98bccad1-ca91-4b24-83d6-78dfd797ff89', 'vinay-rg')
  params: {
    location: saLoc
    kind: saKind
    skuName: saSkuName
    name: toLower(saName)
    allowBlobPublicAccess: false
    publicNetworkAccess: 'Disabled'
    requireInfrastructureEncryption: true
    sasExpirationPeriod: '30.00:00:00'
    networkAcls: {
      bypass: 'AzureServices'
      defaultAction: 'Deny'
    }
    tags: saTags
    fileServices: length(saFileShares) > 0 ? {
      shareDeleteRetentionPolicy: {
        days: 7
        enabled: true
      }
      shares: saFileShares
      shareQuota: saShareQuota
      tags: saTags
    } : {}
  }
}

Deployment:

enter image description here

enter image description here

refer:

Bicep deployment what-if - Azure Resource Manager | Microsoft Learn

Parameters in Bicep files - Azure Resource Manager | Microsoft Learn

Upvotes: 0

Related Questions