Can I pull data from an existingAzure Storage Account table using ARM Templates? - azure

I have an existing Azure Storage Account which has a table. This table has a few details that I would be needing to use in my mainTemplate.json ARM file. Can I pull these values directly in the ARM Template.
[concat(reference(resourceId('Microsoft.Storage/storageAccounts',parameters('storageAccountName'))).primaryEndpoints.table, parameters('tableName'))]
I have been using the above statement in the outputs section and it returns me the table uri. Can I get the values inside that table by any way?

As suggested by Silent By referring this link
Try with using DeploymentScriptOutputs
The script takes one parameter, and output the parameter value. DeploymentScriptOutputs is used for storing outputs.
example
"outputs": {
"result": {
"value": "[reference('runPowerShellInlineWithOutput').outputs.text]",
"type": "string"
}
}
In the outputs section, the value line shows how to access the stored values. Write-Output is used for debugging purpose. To learn how to access the output file, see Monitor and troubleshoot deployment scripts
Thank you #silent for your suggestion

Related

Returning identity value using Azure Functions SQL extension

I am working on a simple REST API using the SQL extension for Azure Functions as described here.
Now i have a table in my Azure SQL database with a primary-key identity column. I am using an Output binding in a HTTP-triggered Azure function for inserting a row in the table:
...
{
"name": "aRow",
"type": "sql",
"direction": "out",
"commandText": "[dbo].[MYTABLE]",
"commandType": "Text",
"connectionStringSetting": "..."
},
...
This is working perfectly and the identity column is being incremented as expected. Now, naturally, i want to return the identity ID of the inserted row to the client. I don't think this feature is built in at the moment, therefor i was hoping that someone out there has solved this in a neat way or at least can point me in a direction.
I have tried adding an Input binding to the above function that querys the row where ID = ##IDENTITY, but it seems like the bindings aren't executed in the same scope or in the correct order. Either way, there is no match for this query. That would've been a neat solution though.

Azure core tools - how to specify a different key name when fetching connection string

Is there a way to tell the tool what field name in my local.settings.json file I want to update when fetching a connection string? so specifically, when I run this command:
func azure storage fetch-connection-string $STORAGE_ACCOUNT_NAME
by default, it grabs the name of my storage account (mystorage123) and appends "_STORAGE" to it. So you end up with something like this:
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"mystorage123_STORAGE": "DefaultEndpointsProtocol=https;AccountName=mystorage123;AccountKey=<key>"
},
"ConnectionStrings": {}
}
I would like it just to create a json field / key that just matches the actual account name - in this case "mystorage123".
Is there a way to do this?
I know I can write powershell code to update my json file manually. But it'd be better if I can just tell the command what to call the field.
Thanks.
I would like it just to create a json field / key that just matches
the actual account name - in this case "mystorage123". Is there a way
to do this? I know I can write powershell code to update my json file
manually. But it'd be better if I can just tell the command what to
call the field.
I don’t think there is such a way. This connection string is originally been spliced.

Azure availability zone ARM A parameter syntax

I am attempting to add availability zone into my VM arm template.
Majority of times I don't want the VM to be in a zone as it is a single VM.
So in my ARM template, I have defined the zone section as:
"zones":[
"[if(greaterOrEquals(parameters('availabilityZone'), 1),parameters('availabilityZone'),json('null'))]"
],
this works fine if I set a value of 1 or higher but fails if I leave as blank.
failed validation with message: 'The zone(s) '' for resource
'Microsoft.Compute/virtualMachines/XXX' is not supported.
if I remove the if condition then hard code in the blank it works:
"zones": "",
I appreciate your help in advance.
Stu
we found the following solution that worked:
"zones":
"if(empty(parameters('availabilityZone')),parameters('availabilityZone'),array(parameters('availabilityZone')))]"
Please try something like this, if your parameter doesn't contain then it will pass the empty value,
"zones": "[if(empty(parameters('availabilityZone')),'', parameters('availabilityZone'))]",
https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/template-functions-string?tabs=json#empty

Is it possible to create a CompositeIndex of CosmosDB with ARM template

I find instructions for using ARM templates to create or make changes to CosmosDB, but none of them contain instructions on how to add a CompositeIndex to the template. I have also heard it is not supported in the template and has to be done with PowerShell or Azure CLI script, but have not been able to find a supporting content on the net. Can someone please shed light on this?
I've not tested this but according to the Microsoft.DocumentDB resource provider docs / template reference there is a Microsoft.DocumentDB/databaseAccounts/apis/databases/containers resource which may give you what you need.
Every container has an IndexingPolicy in the template schema, which has an array of IncludedPath objects which themselves have an array of Index objects as follows:
"includedPaths": [
{
"path": "string",
"indexes": [
{
"dataType": "string",
"precision": "integer",
"kind": "string"
}
]
}
]
It's treated as a separate resource from the database / account altogether. You may want to add this resource to your template with an appropriate dependsOn value to ensure it's deployed after your database.
You can add multiple paths therefore making a composite index.
Full schema is here:
https://learn.microsoft.com/en-us/azure/templates/microsoft.documentdb/2015-04-08/databaseaccounts/apis/databases/containers
If this doesn't do it, you may want to look at this too as the schema docs may be out of date and compositeIndexes may be supported:
https://learn.microsoft.com/en-us/azure/cosmos-db/how-to-manage-indexing-policy#composite-indexing-policy-examples

Azure Resource Manager - Convert value to 'lower'

I was recently using ARM templates to deploy multiple resources into Azure. While deploying Storage accounts, I ran into an issue which was due to some constraints put up by Azure like
Name of Storage Account should not contain upper case letters
Its max length should be 24.
I want this name from the user and can handle the 2nd issue using the "maxLength" property on 'parameters'. But for lower case, there is no such property in 'parameters' also I'm unable to find any function which will convert the user entered value to lower case.
What I expect:
Method to convert the user entered value in lower case.
Any other method to suit my use case.
Thanks in advance.
You should look at the string function reference of the ARM templates.
you need to create a variable (or just add those functions to the name input, like so:
"name": "[toLower(parameters('Name'))]"
or add a substring method, something like this:
"variables": {
"storageAccountName": "[tolower(concat('sawithsse', substring(parameters('storageAccountType'), 0, 2), uniqueString(subscription().id, resourceGroup().id)))]"
},

Resources