Created
August 13, 2018 17:45
-
-
Save renzors/4843c42e48a4ed6757bafb1308a840ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$serviceAppUrl = $OctopusParameters["Stemp.LoginAppUrl"] | |
$servicePassword = $OctopusParameters["Stemp.LoginPassword"] | |
$serviceTenantId = $OctopusParameters["Stemp.LoginTenantID"] | |
$serviceSubscriptionId = $OctopusParameters["Stemp.LoginSubscriptionID"] | |
$cosmosResourceGroupName = $OctopusParameters["Stemp.CosmosResourceGroup"] | |
$cosmosName = $OctopusParameters["Stemp.CosmosName"] | |
$cosmosDatabaseName = $OctopusParameters["Stemp.CosmosDataBaseName"] | |
$cosmosCollectionName = $OctopusParameters["Stemp.CosmosCollectionName"] | |
# Login with Service Principal | |
az login ` | |
--service-principal -u $serviceAppUrl -p $servicePassword ` | |
--tenant $serviceTenantId | |
# Set subscription | |
az account set --subscription $serviceSubscriptionId | |
#Check for existing Database | |
$exist = az cosmosdb database exists ` | |
--db-name $cosmosDatabaseName ` | |
--name $cosmosName ` | |
--resource-group-name $cosmosResourceGroupName | |
if ($exist -eq "false") | |
{ | |
Write-Host "Creating $cosmosDatabaseName database." | |
# Creating database | |
az cosmosdb database create ` | |
--db-name $cosmosDatabaseName ` | |
--name $cosmosName ` | |
--resource-group-name $cosmosResourceGroupName | |
} | |
else | |
{ | |
Write-Host "$cosmosDatabaseName database already exists." | |
} | |
#Check for existing Collection | |
$existc = az cosmosdb collection exists ` | |
--collection-name $cosmosCollectionName ` | |
--db-name $cosmosDatabaseName ` | |
--name $cosmosName ` | |
--resource-group-name $cosmosResourceGroupName | |
if ($existc -eq "false") | |
{ | |
Write-Host "Creating $cosmosCollectionName collection." | |
# Creating collection | |
az cosmosdb collection create ` | |
--collection-name $cosmosCollectionName ` | |
--db-name $cosmosDatabaseName ` | |
--name $cosmosName ` | |
--resource-group-name $cosmosResourceGroupName | |
} | |
else | |
{ | |
Write-Host "$cosmosCollectionName collection already exists." | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment