I am trying to get an array of Notification hub connection strings however I always got an error message from listKeys expression
BCP182: : This expression is being used in the for-body of the
variable "notificationHubConfig", which requires values that can be
calculated at the start of the deployment
Here is my code. First I have an array call notificationHubs in my environment yaml file
notificationhubs:
'["tenantId1:nameSpaceNotificationHub1:Hubname1","tenantId2:nameSpaceNotificationHub2:Hubname2"]'
In module bicep file. First I get the namespaces of Notification Hubs. They are all existing resource. Then I create an array of notifition hub connection string through listKeys function. And the error happen due to the listKeys expression.
resource namespace 'Microsoft.NotificationHubs/namespaces#2017-04-01' existing = [for i in range(0, length(notificationhubs)): {
name: '${split(notificationhubs[i], ':')[1]}'
scope: resourceGroup('${notificationHubResourceGroupName}')
}]
var notificationHubConfig = [for i in range(0, length(notificationhubs)): {
name: notificationhubs[i]
value: '${listKeys('${namespace[i].id}/AuthorizationRules/RootManageSharedAccessKey', namespace[i].apiVersion).primaryConnectionString}'
}]
I have tested all the inputs of the expression and it seem correct (for example namespace[i].id, namespace[i].apiVersion ...etc). Could anyone can help please. Thank you in advance
The bicep logic that replaces variables in your case does not work for loops.
There is an open issue it on GitHub: Variable substitution logic does not work for variables with loop expressions
I am trying to remove / from the URL using azure function before assigning to output variable value
"webappStorageUri":{
"type": "string",
"value": "[take(reference(resourceId('Microsoft.Storage/storageAccounts', variables('webappStorageName'))).primaryEndpoints.web, length(reference(resourceId('Microsoft.Storage/storageAccounts', variables('webappStorageName'))).primaryEndpoints.web)-1]"
}
Returned value from length function should be the value for take function. This is not working. I get following error on deployment. I don't get anything out of this error message. Does Azure support chained function execution? Is this is right approach to remove / from the URL?
Error message
[error]Deployment template language expression evaluation failed: 'Unable to parse language expression 'take(reference(resourceId('Microsoft.Storage/storageAccounts', variables('webappStorageName'))).primaryEndpoints.web, length(reference(resourceId('Microsoft.Storage/storageAccounts', variables('webappStorageName'))).primaryEndpoints.web)-1': expected token 'RightParenthesis' and actual 'Integer'.'. Please see https://aka.ms/arm-template-expressions for usage details.
I'm not sure what you are trying to achieve, but your function has issues with brackets, and you cannot really substract by appending -1 in a random place.
"[take(reference(variables('webappStorageName')).primaryEndpoints.web,
sub(length(reference(variables('webappStorageName')).primaryEndpoints.web), 1))]"
line breaks for readability only
I am trying to retrieve a csv file from the Azure blob storage using the logic apps.
I set the azure storage explorer path in the parameters and in the get blob content action I am using that parameter.
In the Parameters I have set the value as:
concat('Directory1/','Year=',string(int(substring(utcNow(),0,4))),'/Month=',string(int(substring(utcnow(),5,2))),'/Day=',string(int(substring(utcnow(),8,2))),'/myfile.csv')
So during the run time this path should form as:
Directory1/Year=2019/Month=12/Day=30/myfile.csv
but during the execution action is getting failed with the following error message
{
"status": 400,
"message": "The specifed resource name contains invalid characters.\r\nclientRequestId: 1e2791be-8efd-413d-831e-7e2cd89278ba",
"error": {
"message": "The specifed resource name contains invalid characters."
},
"source": "azureblob-we.azconn-we-01.p.azurewebsites.net"
}
So my question is: How to write path to get data from the time series partitioned path.
The response of the Joy Wang was partially correct.
The Parameters in logic apps will treat values as a String only and will not be able to identify any functions such as concat().
The correct way to use the concat function is to use the expressions.
And my solution to the problem is:
concat('container1/','Directory1/','Year=',string(int(substring(utcNow(),0,4))),'/Month=',string(int(substring(utcnow(),5,2))),'/Day=',string(int(substring(utcnow(),8,2))),'/myfile.csv')
You should not use that in the parameters, when you use this line concat('Directory1/','Year=',string(int(substring(utcNow(),0,4))),'/Month=',string(int(substring(utcnow(),5,2))),'/Day=',string(int(substring(utcnow(),8,2))),'/myfile.csv') in the parameters, its type is String, it will be recognized as String by logic app, then the function will not take effect.
And you need to include the container name in the concat(), also, no need to use string(int()), because utcNow() and substring() both return the String.
To fix the issue, use the line below directly in the Blob option, my container name is container1.
concat('container1/','Directory1/','Year=',substring(utcNow(),0,4),'/Month=',substring(utcnow(),5,2),'/Day=',substring(utcnow(),8,2),'/myfile.csv')
Update:
As mentioned in #Stark's answer, if you want to drop the leading 0 from the left.
You can convert it from string to int, then convert it back to string.
concat('container1/','Directory1/','Year=',string(int(substring(utcNow(),0,4))),'/Month=',string(int(substring(utcnow(),5,2))),'/Day=',string(int(substring(utcnow(),8,2))),'/myfile.csv')
I'm trying to add an extension to an azure arm template, so when it loops around it adds the extension to each vm, but I'm getting an error where it doesn't recognise the credentials parameter.
The full JSON is at the link below:
https://pastebin.com/embed_iframe/7uvwdZ6e
The error I'm getting is:
VM has reported a failure when processing extension 'CreateADPDC'. Error message: "The DSC Extension received an incorrect input: A parameter cannot be found that
matches parameter name 'AdminCreds'.
Another common error is to specify parameters of type PSCredential without an explicit type. Please be sure to use a typed parameter in DSC Configuration, for example:
configuration Example {
param([PSCredential] $UserAccount)
Any idea where I've gone wrong on this?
Thanks in advance :)
this error comes from your configuration\arm template interaction, if you have the AdminCreds credentials parameter there, i think you need to use protectedsettings to pass it:
"protectedSettings": {
"configurationArguments": {
"adminCreds": {
"userName": "xxx",
"password": "yyy"
}
}
}
configuration should look like this (so should contain adminCreds input parameter with that particular type):
Param (
[System.Management.Automation.PSCredential]$Admincreds,
other_params
)
I'm just learning how use mongoDb and I get confused by the documentation about the Collection.remove() method.
In first place, I tried to follow this doc:
http://docs.mongodb.org/manual/reference/method/db.collection.remove/
But I got the message Error: Cannot use a writeConcern without a provided callback, so I searchd why and I found this documentation then: http://mongodb.github.io/node-mongodb-native/api-generated/collection.html
In the first one there are two args, in the second there are three.
Then I did a console.log((mongodb.Collection(db, 'user').remove).toString());
And I got function remove(selector, options, callback)...
So now I just don't understand what's going on here, Is there different kind of Collection class? I whish to understand which documentation I should follow.
It seems like you just have to provide a callback-function:
Collection.remove(function(err, removedCount) {
//your next actions
});
From documentation:
[callback] (function) – must be provided if you performing a remove with a writeconcern