Create Maps for Integration Account in Bicep

31 Views Asked by At

When I try and reference an array generated by a Deployment Script I can't seem to access the elements in the array.

I have a Main.Bicep file which has a module to create an Integration Account by calling the IntegrationAccount.bicep file.

param integrationAccountName string

module IntegrationAccount 'IntegrationAccount.bicep' = {
  scope: resourceGroup(subscriptionID, resourceGroupName)
  name: 'integrationAccountModule'
  params: {
    integrationAccountName: integrationAccountName
    location: location
  }
  dependsOn: [
    ResourceGroup
  ]
}

location is also defined as a parameter earlier in the Main.Bicep file.

I now want to add a number of Maps but to do this I need the name of the Map and its content. There are a variable number of Maps and I want to pick up the names of the Maps and their content directly from the folder they are saved to by the developers.

I have created a Powershell script (GetMapFiles.ps1) to return the list of Map names and their content.

$mapFolder = "C:\SomeFolder\Maps"

$fileNames = Get-ChildItem -Path $mapFolder -Recurse -Include *.xslt

foreach ($file in $fileNames)
{
    $fileName = $file.Name
    $fileContent = Get-Content $mapFolder\$fileName
    
    Write-Output $fileName 
    Write-Output $fileContent
}

I run a DeploymentScript (DeploymentScript.bicep) which runs the Powershell script.

resource deploymentScript 'Microsoft.Resources/deploymentScripts@2023-08-01' = {
  name: 'MapFiles'
  location: location
  kind: 'AzurePowerShell'
  identity: {
    type: 'UserAssigned'
    userAssignedIdentities: {
      '${userAssignedIdentity.id}': {}
    }
  }
  properties: {
    azPowerShellVersion: '10.0'
    scriptContent: loadTextContent('./DeploymentScripts/GetMapFiles.ps1')
    retentionInterval: 'P1D'
    cleanupPreference: 'Always'
  }
  dependsOn: [
    roleAssignment
    blobContainer
  ]
}

In my Main.bicep file I execute the DeploymentScript.bicep file above and save the output to an array.

param containerNameDeploymentScript string
param storageAccountDeploymentScript string

module DeploymentScript 'DeploymentScript.bicep' = {
  scope: resourceGroup(subscriptionID, resourceGroupName)
  name: 'DeploymentScriptModule'
  params: {
    containerNameDeploymentScript: containerNameDeploymentScript
    location: location
    storageAccountDeploymentScript: storageAccountDeploymentScript
    subscriptionID: subscriptionID
  }
}

output mapFiles array  = DeploymentScript.outputs.mapFiles

Then in my Main.bicep file I execute my Map bicep file.

param mapFiles array

module Map 'Map.bicep' = [for file in mapFiles: {
  scope: resourceGroup(subscriptionID, resourceGroupName)
  name: file.
  params: {
    integrationAccountName: integrationAccountName
    mapName: file.
    mapContent: file.
  }
  dependsOn: [
    IntegrationAccount
  ]
} ]

What is not happening is the array doesn't seem to be working here i.e. file. on name, mapName and mapContent.

0

There are 0 best solutions below