Handle bash output and passing to bicep
Hello Frederic Gauthier, seems like you already found a solution to your problem, I am just posting it here for ease of other folks who are facing similar issue on SO. Please feel free to add any points/your inputs to this if required.
Thanks Charles Duffy for sharing the right input. You just need to install jq by making changes in inlineScript section. This will process the JSON output in the format you need by transforming the array in JSON into required format.
jq
Transformation:
jq -r 'map("\"" + . + "\"") | join(", ")'
this will converts the JSON array into a comma-separated list of quoted strings.sed 's/^/(/;s/$/)/'
this will wraps the list in parentheses.Sample Inlinescript:
inlineScript: |
$(var-bashPreInjectScript)
templateFile=hub/hubconnectivite.bicep
echo "Deploying $templateFile using ${{ parameters.deployOperation }} operation"
preDeploymentRgList=$(az group list --subscription "$(var-hub-subscriptionId)" --query "[].name" -o json)
preDeploymentRgListFormatted=$(echo "$preDeploymentRgList" | jq -r 'map("\"" + . + "\"") | join(", ")' | sed 's/^/(/;s/$/)/')
echo "Formatted Resource Groups: $preDeploymentRgListFormatted"
az deployment sub ${{ parameters.deployOperation }} \
--name hubconnectivite${{ parameters.deploymentRegion }} \
--location ${{ parameters.deploymentRegion }} \
--subscription $(var-hub-subscriptionId) \
--template-file $templateFile \
--parameters \
preDeploymentRgListName="$preDeploymentRgListFormatted" \
subscriptionId='$(var-hub-subscriptionId)' \
location='${{ parameters.deploymentRegion )}}' \
otherParameter='$(var-other-parameter)'
# Post-injection script (if any)
$(var-bashPostInjectScript)
Refer:
Convert a JSON array to a bash array of strings - Stack Overflow for related query information