I see many templates online using primaryEndpoints ouput parameter in ARM templates, but I am not sure how they actually found it as it's not mentioned in the docs. What is the best way to find out the available outputs for a resource?
one of the way is to output the whole object with all properties and values.
"outputs": {
"myObject": {
"type": "Object",
"value": "[reference(parameters('myResources'))]"
}
you can also use resource explorer to browse resources that are provissioned
Related
When writing the outputs part of ARM template how do the do what properties are available for a resource. in the below example for public ip resource how do I find out dnsSettings.fqdn or .ipAddress is available
"outputs": {
"fqdn": {
"value": "[reference(parameters('publicIPAddresses_name')).dnsSettings.fqdn]",
"type": "string"
},
"ipaddress": {
"value": "[reference(parameters('publicIPAddresses_name')).ipAddress]",
"type": "string"
}
}
Your ask is related to Retrieve FQDN of Azure SQL from a linkted template question.
The easiest way to accomplish your requirement is illustrated in below screenshot.
Hope this helps!! Cheers!!
Note: If you think your question has been answered then please 'accept' it, if just helped then click "This answer is useful" and provide an up vote. This can be beneficial to other community members reading this thread.
One way I've found, using only ARM, is to output the whole object:
"outputs": {
"ipaddress": {
"type": "Object",
"value": "[reference(parameters('publicIPAddresses_name'))]"
}
When you apply the policy, the output will show all the possible properties and their values.
You can view the whole data structure in json at https://resources.azure.com.
you dont really know, because some properties are amended by default (and the other answer doesnt mention that at all, which could mislead you badly). One thing you can do is look at the rest api definition of the resource and use Full reference to the resource, that way you will always get what you see in the api definition.
reference(parameters('publicIPAddresses_name'), 'api-version', 'Full')
but, object structure will be different, as far as I remember you'd need to access properties of the object for the most of the output. What I tend to do is - create a template that does nothing but output the existing object I'm interested in and run it and examine the output.
Outputs are almost never needed so it's not that big of an issue in my mind.
Rest Api definitions: https://learn.microsoft.com/en-us/rest/api/azure/
I am creating an ARM template to provision keyvault and it's secrets. I want to generate unix timestamp inside template and supply to nbf and exp attributes which only take integers. Can't find much pointers on this.
i am referring to microsoft documentation https://learn.microsoft.com/en-us/azure/templates/microsoft.keyvault/vaults/secrets
If no solution in ARM template then i need to use powershell to generate and pass it to template which i may not prefer unless there is no other option.
There is no way to generate those with ARM templates. arm templates do not have a way to work with date\time
There is now a function available to generate Unix-style timestamps from an ISO-8601 format.
dateTimeToEpoch('2022-11-17T09:54:13Z')
Use utcNow() function to get Date/Time during deployment time. Note you can use it only in parameter's default value:
"parameters" : {
"todayUtc": {
"type": "string",
"defaultValue": "[utcNow('yyyy-MM-dd')]"
}
}
See: docs
I have several ARM templates, all receive list of tags as an object type parameter:
"tagValues": {
"type": "object"
}
In "resources" section I refer to tagValues as follows:
"tags": "[parameters('tagValues')]"
This approach works fine for all ARM templates except the one for creating Azure Functions App, because ARM template definition already contains a 'hidden-link:' tag:
"tags": {
"[concat('hidden-link:', resourceGroup().id, '/providers/Microsoft.Web/sites/', variables('appServices')[copyIndex()].name)]": "Resource"
}
Is there a way to union/combine tags passed into tagValues parameter with this 'hidden-link:' tag? I cannot move 'hidden-link:' tag into a variable, because it is in a copy loop.
ARM templates have a union function, which is documented here.
There is a similar question which looks like it can help you out too
This is to find out if something I'm attempting is even possible...
I've seen several examples of developing an entry ARM template (azuredeploy.json) that refs/imports an external child resource template (eg: azuredeploy.sql.server.json) within which is defined a new SQL Server as well as -- within the sql server's resources section -- nested resources, such as a firewallrule.
I've seen one example (https://blogs.msdn.microsoft.com/azuresqldbsupport/2017/01/11/arm-template-to-deploy-server-with-auditing-and-threat-detection-turned-on/) where the entry/parent ARM template (eg: azuredeploy.json) defines the SQL Server, and instead of defining the firewall rules as a nested resources, defines the firewall rules in parallel, using dependsOn to define execution order.
That appears to be a bit more maintainable/less nested than the first approach.
But I'd like to push it further, where the above resources are all defined in external templates: azuredeploy.json invoking azuredeploy.sql.server.json and azuredeploy.sql.server.firewallRules.json
Unfortunately, I've not found a single example of the above approach.
I've tried for most of the afternoon -- but having changed slashes of ids and names to every configuration imaginable, have run over and over again into:
Code=InvalidTemplate
Message=Deployment template validation failed: 'The template resource {resource-name}'
for type {resource-type} has incorrect segment lengths.
So the questions are:
a) any reason it should not be done this way? (I felt it allowed for a more modular set of arm templates, that could be referenced from a flat entry arm file, only requiring a correct set of 'dependsOn' attributes being defined)
b) can the above actually be done?!
c) is there an online example to study of the above approach and understand my approach error?
d) Just in case: when it's giving the error messages regarding the segment lengths...any chance it's getting itself confused, and it's taking into account "Microsoft.Resources/deployments", when it should be taking into account only "Microsoft.Sql/servers" and "Microsoft.Sql/servers/firewallRules"?
Much appreciated if anybody can advance me on this sticking point.
Yes, you should be able to do this, see: https://learn.microsoft.com/en-us/azure/templates/microsoft.sql/servers/firewallrules
The error you posted suggests that you're missing a name segment or type segment - those must match as in the example below.
"type": "Microsoft.Sql/servers/firewallrules",
"apiVersion": "2015-05-01-preview",
"name": "[concat(parameters('serverName'), '/', 'AllowAllWindowsAzureIps')]",
"location": "[resourceGroup().location]",
"properties": {
"endIpAddress": "0.0.0.0",
"startIpAddress": "0.0.0.0"
}
So your name property will be something like
sqlServerResourceName/whateverYouWantToNameTheFirewallRules - and type exactly as in the example above.
AFAIK, all the parameters have to be defined in the parent template right from the start. Is it possible to generate parameters dynamically at all, such as looping n times to generate n name fields?
This shows how parameters are defined in templates. Note that none of the parameters are created dynamically.
You can use parameters that depend on parameters to emulate something like that:
"parameters": {
"first": {
"type": "string",
"defaultValue": "lol"
},
"second": {
"type": "string",
"defaultValue": "[concat('not_so_', parameters('first'))]"
}
}
would give you value of not_so_lol for the first parameter.
You another option is to create variables that take values depending on the parameter:
"parameterOne": "defaultValue": x, - I'm lazy to type out proper definition in json.
...
"option-x": "something"
"option-y": "something-else"
"result": "[variables(concat('option-', parameters('parameterOne')))]"
so this is basically an If statement in ARM template. the value of the result variable equals to "[variables('option-x')]" or "[variables('option-y')]", depending on your input.
Another (a bit more complex option) is to use deployments outputs. So an example would be, you create a deployment filled with different outputs needed by you (basically you create a pool of constants), and after that, you can reference that deployment outputs in all of your templates (given they reside in the same subscription, but you can create that deployment in all of the subscriptions). that would basically create a pool of constants you can get needed value based on the current value.
"something": "[reference(concat('resourceGroupName', 'Microsoft.Resources/deployments/', parameters('deploymentName')),'2015-01-01').outputs]",
The last (most complex) option is to construct needed stuff on the fly, using nested templates. That's a bit too much to get through in an answer, but I'll just say that in this case you need to use nested templates as aggregator\transformator, where you feed values in and get desired output. This is pretty advanced stuff, but worth knowing. This would be a good example (for starters).
According to your description, we can use uniqueString() to achieve generate parameters dynamically. This function is helpful when you need to create a unique name for a resource.
More information about uniqueString, please refer to this link.