I'm trying to set CORS rule for my storage account as suggested here under Configure CORS by using Azure Resource Manager tools: https://docs.microsoft.com/en-us/azure/app-service-api/app-service-api-cors-consume-javascript
by adding property cors:
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"sku": {
"name": "Standard_RAGRS",
"tier": "Standard"
},
"kind": "Storage",
"name": "[parameters('storageAccounts_teststoragejkjk_name')]",
"apiVersion": "2016-01-01",
"location": "westus",
"tags": {},
"properties": {
"cors": {"allowedOrigins": ["*"]}
},
"resources": [],
"dependsOn": []
}
]
Deployment returns succes and I can see Write StorageAccount operation under Activity Log in Azure Portal but Cors Rules aren't added anywhere and when i download template from Azure it doesn't have this "cors property".
I also tried manually adding Corse Rule (i need it only on my Blob) and automation scripts (including deployment.ps) still looks the same...
Any suggestion on how to configure Cors rule on blob storage using ARM templates?
Because they are native to the Azure platform, Resource Manager templates let you track your deployments in the portal, use deep integration with other Azure services and provision any Azure resource as soon as it is available.
By default, CORS is disabled for each service. To enable CORS, you need to set the appropriate service properties using version 2013-08-15 or later for the Blob, Queue, and Table services, or version 2015-02-21 or for the File service. You enable CORS by adding CORS rules to the service properties.
As @JBA pointed out this now works via ARM templates.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"name": "storageAccountName",
"apiVersion": "2018-02-01",
"location": "northeurope",
"kind": "StorageV2",
"sku": {
"name": "Standard_LRS",
"tier": "Standard"
},
"tags": {},
"dependsOn": [],
"properties": {
"accessTier": "Hot"
},
"resources": [
{
"name": "default",
"type": "blobServices",
"apiVersion": "2018-11-01",
"dependsOn": [
"storageAccountName"
],
"properties": {
"cors": {
"corsRules": [
{
"allowedOrigins": [
"https://mywebsite.com"
],
"allowedMethods": [
"GET"
],
"maxAgeInSeconds": 0,
"exposedHeaders": [
"*"
],
"allowedHeaders": [
"*"
]
}
]
}
},
"resources": []
},
{
"type": "blobServices/containers",
"apiVersion": "2018-03-01-preview",
"name": "[concat('default/', 'myFilesToShare')]",
"dependsOn": [
"storageAccountName"
],
"properties": {
"publicAccess": "Blob"
}
}
]
}
]
}
What is your deployment client? If you are using Powershell to deploy ARM (w you probably are) why not use Set-AzureStorageCORSRule?
PS C:\>$CorsRules = (@{
AllowedHeaders=@("x-ms-blob-content-type","x-ms-blob-content-disposition");
AllowedOrigins=@("*");
MaxAgeInSeconds=30;
AllowedMethods=@("Get","Connect")},
@{
AllowedOrigins=@("http://www.fabrikam.com","http://www.contoso.com");
ExposedHeaders=@("x-ms-meta-data*","x-ms-meta-customheader");
AllowedHeaders=@("x-ms-meta-target*","x-ms-meta-customheader");
MaxAgeInSeconds=30;
AllowedMethods=@("Put")})
PS C:\> Set-AzureStorageCORSRule -ServiceType Blob -CorsRules $CorsRules
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With