Commit f8eadde8 authored by Carlos Andrés Carrero Saldarriaga's avatar Carlos Andrés Carrero Saldarriaga
Browse files

Add resources scripts

parent e6038684
$resourceGroupName = "rg-face-detection"
$region = "eastus2"
$scopeTagKey = "Scope"
$scopeTagValue = "Face Detection"
$resourceTypeTagKey = "Resource Type"
$resourceTypeTagValue = "Resource Group"
az group create `
--name $resourceGroupName `
--location $region `
--tags "$scopeTagKey=$scopeTagValue" "$resourceTypeTagKey=$resourceTypeTagValue"
$query = "[?name=='$resourceGroupName'].{name: name tags: tags}[0]" ; $query
az group list `
--query $query
\ No newline at end of file
$keyVaultSecretName = "FaceApiPrimaryKey"
$keyVaultName = "kv-face-detection"
$keyVaultSecretIdQuery = "id"
$functionName = "func-face-detection"
$resourceGroupName = "rg-face-detection"
$settingName = "FaceApiPrimaryKey"
# Gets the keyvault secret
$secretId=(az keyvault secret show `
--name $keyVaultSecretName `
--vault-name $keyVaultName `
--query $keyVaultSecretIdQuery `
--output tsv)
# Formats the value to use in configuration settings
$finalConfiguration="@Microsoft.KeyVault(SecretUri=$secretId)"
# Configuration value
$finalConfiguration
# Sets App Setting
az functionapp config appsettings set `
--name $functionName `
--resource-group $resourceGroupName `
--settings "$settingName=$finalConfiguration"
\ No newline at end of file
$keyVaultSecretName = "FaceApiEndpoint"
$keyVaultName = "kv-face-detection"
$keyVaultSecretIdQuery = "id"
$functionName = "func-face-detection"
$resourceGroupName = "rg-face-detection"
$settingName = "FaceApiEndpoint"
# Gets the keyvault secret
$secretId=(az keyvault secret show `
--name $keyVaultSecretName `
--vault-name $keyVaultName `
--query $keyVaultSecretIdQuery `
--output tsv)
# Formats the value to use in configuration settings
$finalConfiguration="@Microsoft.KeyVault(SecretUri=$secretId)"
# Configuration value
$finalConfiguration
# Sets App Setting
az functionapp config appsettings set `
--name $functionName `
--resource-group $resourceGroupName `
--settings "$settingName=$finalConfiguration"
\ No newline at end of file
$storageAccountName = "stfuncfacedetection"
$resourceGroupName = "rg-face-detection"
$region = "eastus2"
# Hot - Optimized for storing data that is accessed frequently.
# Cool - Optimized for storing data that is infrequently accessed and stored for at least 30 days.
# Archive - Optimized for storing data that is rarely accessed and stored for at least 180 days with flexible latency requirements, on the order of hours.
$storageAccountAccessTier = "Hot"
$storageAccountBlobPublicAccess = "false"
# General-purpose v2 accounts: Basic storage account type for blobs, files, queues, and tables. Recommended for most scenarios using Azure Storage.
$storageAccountKind = "StorageV2"
# Standard Locally Redundant Storage
$storageAccountSku = "Standard_LRS"
$scopeTagKey = "Scope"
$scopeTagValue = "Face Detection"
$resourceTypeTagKey = "Resource Type"
$resourceTypeTagValue = "Storage Account"
az storage account create `
--name $storageAccountName `
--resource-group $resourceGroupName `
--location $region `
--access-tier $storageAccountAccessTier `
--allow-blob-public-access $storageAccountBlobPublicAccess `
--kind $storageAccountKind `
--sku $storageAccountSku `
--tags "$scopeTagKey=$scopeTagValue" "$resourceTypeTagKey=$resourceTypeTagValue"
$query = "[?name=='$storageAccountName'].{name: name tags: tags}[0]" ; $query
az storage account list `
--query $query
$appInsightsName = "appi-face-detection"
$resourceGroupName = "rg-face-detection"
$appInsightsResourceType = "Microsoft.Insights/components"
$appInsightsResourceProperties = '{\"Application_Type\":\"web\"}'
$scopeTagKey = "Scope"
$scopeTagValue = "Face Detection"
$resourceTypeTagKey = "Resource Type"
$resourceTypeTagValue = "Application Insights"
az resource create `
--name $appInsightsName `
--resource-group $resourceGroupName `
--resource-type $appInsightsResourceType `
--properties $appInsightsResourceProperties
az resource tag `
--name $appInsightsName `
--resource-group $resourceGroupName `
--resource-type $appInsightsResourceType `
--tags "$scopeTagKey=$scopeTagValue" "$resourceTypeTagKey=$resourceTypeTagValue"
$query = "{name: name tags: tags}" ; $query
az monitor app-insights component show `
--app $appInsightsName `
--resource-group $resourceGroupName `
--query $query
\ No newline at end of file
$functionName = "func-face-detection"
$resourceGroupName = "rg-face-detection"
$region = "eastus2"
$storageAccountName = "stfuncfacedetection"
$runtime = "dotnet-isolated"
$functionVersion = "3"
$functionOSType = "Windows"
$appInsightsName = "appi-face-detection"
$scopeTagKey = "Scope"
$scopeTagValue = "Face Detection"
$resourceTypeTagKey = "Resource Type"
$resourceTypeTagValue = "Function App"
az functionapp create `
--name $functionName `
--resource-group $resourceGroupName `
--consumption-plan-location $region `
--storage-account $storageAccountName `
--runtime $runtime `
--functions-version $functionVersion `
--os-type $functionOSType `
--app-insights $appInsightsName `
--tags "$scopeTagKey=$scopeTagValue" "$resourceTypeTagKey=$resourceTypeTagValue"
az functionapp identity assign `
--name $functionName `
--resource-group $resourceGroupName
$query = "[?name=='$functionName'].{name: name identity: identity tags: tags}[0]" ; $query
az functionapp list `
--resource-group $resourceGroupName `
--query $query
$resourceGroupName = "rg-face-detection"
$region = "eastus2"
$accountName = "cog-face-detection"
$kind = "Face"
$sku = "S0"
$scopeTagKey = "Scope"
$scopeTagValue = "Face Detection"
$resourceTypeTagKey = "Resource Type"
$resourceTypeTagValue = "Cognitive Services Face API"
az cognitiveservices account purge `
--location $region `
--name $accountName `
--resource-group $resourceGroupName
az cognitiveservices account create `
--resource-group $resourceGroupName `
--location $region `
--name $accountName `
--kind $kind `
--sku $sku `
--tags "$scopeTagKey=$scopeTagValue" "$resourceTypeTagKey=$resourceTypeTagValue"
az cognitiveservices account identity assign `
--name $accountName `
--resource-group $resourceGroupName
$query = "[?name=='$accountName'].{name: name kind: kind sku: sku.name resourceGroup: resourceGroup identity: identity tags: tags}[0]" ; $query
az cognitiveservices account list `
--query $query
\ No newline at end of file
$keyVaultName = "kv-face-detection"
$region = "eastus2"
$resourceGroupName = "rg-face-detection"
$keyVaultSku = "standard"
$scopeTagKey = "Scope"
$scopeTagValue = "Face Detection"
$resourceTypeTagKey = "Resource Type"
$resourceTypeTagValue = "Key Vault"
# Permanently deletes the specified vault in case it exists as soft deleted
az keyvault purge `
--name $keyVaultName `
--location $region
# Creates the key vault
az keyvault create `
--name $keyVaultName `
--resource-group $resourceGroupName `
--location $region `
--sku $keyVaultSku `
--tags "$scopeTagKey=$scopeTagValue" "$resourceTypeTagKey=$resourceTypeTagValue"
$query = "[?name=='$keyVaultName'].{name: name identity: identity tags: tags}[0]" ; $query
az keyvault list `
--resource-group $resourceGroupName `
--query $query
\ No newline at end of file
$resourceGroupName = "rg-face-detection"
$functionName = "func-face-detection"
$principalIdQuery = "[?name=='$functionName'].{appId: identity.principalId}"
$keyVaultName = "kv-face-detection"
$keyVaultPolicyPermissions = "get"
# Gets the function application principal id
$functionPrincipalId=(az functionapp list `
--resource-group $resourceGroupName `
--query $principalIdQuery `
--output tsv)
# Sets the key vault policy for the function
az keyvault set-policy `
--name $keyVaultName `
--resource-group $resourceGroupName `
--secret-permissions $keyVaultPolicyPermissions `
--object-id $functionPrincipalId
# Lists the key vault with the assigned permissions to the function
$query = "[].{name: name tags: tags accessPolicies: properties.accessPolicies[?objectId=='$productsApiPrincipalId']}" ; $query
az keyvault list `
--resource-group $resourceGroupName `
--query $query
\ No newline at end of file
$accountName = "cog-face-detection"
$resourceGroupName = "rg-face-detection"
$key1Query = "key1"
$keyVaultSecretName = "FaceApiPrimaryKey"
$keyVaultName = "kv-face-detection"
$keyVaultSecretDescription = "Cognitive services face API primary key"
$scopeTagKey = "Scope"
$scopeTagValue = "Face Detection"
$resourceTypeTagKey = "Resource Type"
$resourceTypeTagValue = "Key Vault Secret"
# Gets the cognitive services face api key1
$faceApiPrimaryKey=(az cognitiveservices account keys list `
--name $accountName `
--resource-group $resourceGroupName `
--query $key1Query `
--output tsv)
# Sets the keyvault secret
az keyvault secret set `
--name $keyVaultSecretName `
--vault-name $keyVaultName `
--description $keyVaultSecretDescription `
--value $faceApiPrimaryKey `
--tags "$scopeTagKey=$scopeTagValue" "$resourceTypeTagKey=$resourceTypeTagValue"
\ No newline at end of file
$accountName = "cog-face-detection"
$resourceGroupName = "rg-face-detection"
$keyVaultSecretName = "FaceApiEndpoint"
$keyVaultName = "kv-face-detection"
$keyVaultSecretDescription = "Cognitive services face API endpoint"
$scopeTagKey = "Scope"
$scopeTagValue = "Face Detection"
$resourceTypeTagKey = "Resource Type"
$resourceTypeTagValue = "Key Vault Secret"
$query = "[?name=='$accountName'].{endpoint: properties.endpoints.Face}[0]" ; $query
# Gets the cognitive services face api endpoint
$faceApiEndpoint=(az cognitiveservices account list `
--query $query `
--output tsv)
# Sets the keyvault secret
az keyvault secret set `
--name $keyVaultSecretName `
--vault-name $keyVaultName `
--description $keyVaultSecretDescription `
--value $faceApiEndpoint `
--tags "$scopeTagKey=$scopeTagValue" "$resourceTypeTagKey=$resourceTypeTagValue"
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment