Skip to content

Instantly share code, notes, and snippets.

@mattruma
Last active August 31, 2020 12:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattruma/b5a94db43cdf3641597e7d92c8f28275 to your computer and use it in GitHub Desktop.
Save mattruma/b5a94db43cdf3641597e7d92c8f28275 to your computer and use it in GitHub Desktop.
Adventures with Azure ARM Templates: Create Logic App API Connection for Cosmos
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"connectionName": {
"type": "String"
},
"cosmosAccountName": {
"type": "String"
}
},
"resources": [
{
"type": "Microsoft.Web/connections",
"apiVersion": "2016-06-01",
"location": "[resourceGroup().location]",
"name": "[parameters('connectionName')]",
"properties": {
"api": {
"id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/documentdb')]"
},
"displayName": "[parameters('cosmosAccountName')]",
"parameterValues": {
"databaseAccount": "[parameters('cosmosAccountName')]",
"accessKey": "[listKeys(resourceId('Microsoft.DocumentDB/databaseAccounts', parameters('cosmosAccountName')), '2015-04-08').primaryMasterKey]"
}
}
}
]
}
Param(
[String] [Parameter(Mandatory = $true)] $ResourceGroupName,
[String] $ConnectionName = '',
[String] [Parameter(Mandatory = $true)] $CosmosAccountName,
[String] $TemplateFile = "LogicAppCosmosConnection.json"
)
$ErrorActionPreference = "Stop"
$TemplateFile = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($PSScriptRoot, $TemplateFile))
if ($null -eq $ConnectionName -or $ConnectionName.Trim() -eq '') {
$ConnectionName = $CosmosAccountName + "-cn"
}
New-AzResourceGroupDeployment `
-Name ((Get-ChildItem $TemplateFile).BaseName + "-" + ((Get-Date).ToUniversalTime()).ToString("MMdd-HHmm")) `
-ResourceGroupName $ResourceGroupName `
-TemplateFile $TemplateFile `
-Force `
-Verbose `
-connectionName $ConnectionName `
-cosmosAccountName $CosmosAccountName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment