upload file to storage account using ARM template

create storage account using arm template
azure copy files between storage accounts
arm template storage account container
linked arm templates example
upload file to azure blob storage powershell
azure devops copy file to blob storage
azcopy rename file
azcopy azure cli

I am new to azure. I have a storage account created in the azure portal. I need to upload files to the storage account using ARM templates. Can any one please let me know how to do this?

As Bruno Faria mentioned that we could not use ARM template to do that. With Azure ARM template. You can deploy, update, or delete all the resources for your solution in a single,coordinated operation. More detail about ARM template please refer to the document

With Resource Manager, you can create a template (in JSON format) that defines the infrastructure and configuration of your Azure solution. By using a template, you can repeatedly deploy your solution throughout its lifecycle and have confidence your resources are deployed in a consistent state

We could use Microsoft Azure Storage Explorer to do that easily.

If we try to use program to do that we could get the demo code from Azure official document.

// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
    CloudConfigurationManager.GetSetting("StorageConnectionString"));

// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");

// Retrieve reference to a blob named "myblob".
CloudBlockBlob blockBlob = container.GetBlockBlobReference("myblob");

// Create or overwrite the "myblob" blob with contents from a local file.
using (var fileStream = System.IO.File.OpenRead(@"path\myfile"))
{
    blockBlob.UploadFromStream(fileStream);
}

Securely deploy template with SAS token, Create storage account with secured container; Upload template to storage When your Azure Resource Manager (ARM) template is located in a Set-​AzStorageBlobContent ` -Container templates ` -File c:\Templates\azuredeploy.​json For an example of using a SAS token with linked templates, see  Once you have built your ARM template, VHD or DSC Configuration you can use the script below to upload the files to Azure storage. This scripts uploads files as a block blob type, you can read more about Azure Storage types here. I will cover this a bit more in a future blog post where I will show you how to upload a custom VHD to Azure, for now just note that you should not use the script below as is to upload a VHD.

You can use AzCopy:

AzCopy /Source:C:\myfolder /Dest:https://myaccount.blob.core.windows.net/mycontainer /DestKey:key /S

more info: https://docs.microsoft.com/en-us/azure/storage/storage-use-azcopy

You can also use powershell to upload files to your storage account:

Get-ChildItem –Path C:\Images\* | Set-AzureStorageBlobContent -Container "yourcontainername"

more info: https://docs.microsoft.com/en-us/azure/storage/storage-powershell-guide-full

Use template reference, Using template reference documentation, you customize the template. Resource Manager template reference deploy storage account After uploading the file, you can use the ls command and the cat command to verify the  Adding JSON to your ARM template will make sure a new storage account is created with the specified settings and parameters. How to create ARM templates. Now for adding a container to this storage account!

Uploading a file to Blob Storage using an ARM Template is currently not supported.

The logic behind this is that ARM templates are there to manage the Azure Resources (to do actions such as creation, deletion and changing resource properties) and not to manage your usage of these resources.

The ways files can be uploaded to Blob Storage are:

  1. Manually via the Storage Explorer Tool - Storage Explorer
  2. Programatically via the Az Powershell command - az storage blob upload

That said, deploying a Blob Storage container (the Resource itself) can be done as seen in the below template: (credit to @johndownshere)

{
  "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "storageAccountName": {
      "type": "string"
    }
  },
  "variables": {
    "containerName": "logs"
  },
  "resources": [
    {
      "name": "[parameters('storageAccountName')]",
      "type": "Microsoft.Storage/storageAccounts",
      "apiVersion": "2018-02-01",
      "location": "[resourceGroup().location]",
      "kind": "StorageV2",
      "sku": {
        "name": "Standard_LRS",
        "tier": "Standard"
      },
      "properties": {
        "accessTier": "Hot"
      },
      "resources": [
        {
          "name": "[concat('default/', variables('containerName'))]",
          "type": "blobServices/containers",
          "apiVersion": "2018-03-01-preview",
          "dependsOn": [
            "[parameters('storageAccountName')]"
          ]
        }
      ]
    }
  ]
}

How to Upload Azure resource manager (ARM) template to Azure , Figure-1 — Powershell Storage Account Copy and save the azureDeploy.json file from the link to your local machine. 4. To execute and deploy the resource using uploaded ARM template use below commands -. Until recently, one such resource type was a blob container. ARM templates could deploy Azure Storage accounts, but not blob containers, queues, or tables within them. That has now changed, and it’s possible to deploy a blob container through an ARM template. Here’s an example template that deploys a container called logs within a storage

Create Azure Storage Accounts & Upload Blobs: An Introduction, Azure First Steps: How to Create Azure Storage Accounts and Upload Blobs or automated through ARM templates, Azure CLI, Azure PowerShell, az storage blob upload --file <file path> --container-name <container  I'm looking on how to create Azure File Storage with the ARM deployment. (I'm talking of what is also named Azure File Shares) Reading this azure documentation, we can see this: You can create Azure file shares using Azure Portal, the Azure Storage PowerShell cmdlets, the Azure Storage client libraries, or the Azure Storage REST API.

Run Scripts in ARM template deployments with Azure Container , I used an ARM template to deploy a storage account and containers, but I then needed copy a file from a different storage account into this new one I had created. at either using some release management/orchestration tool like Azure check our storage account and see our files have been uploaded. Generate a template using the portal. In a web browser, go to the Azure portal and sign in. From the Azure portal menu, select Create a resource . Select Storage > Storage account . Enter the following information: Name. Value. Resource group. Select Create new , and specify a resource group name of

ARM: Uploading Resources to Azure Storage – Rob Plank Tech, ARM: Uploading Resources to Azure Storage to upload files to Azure Storage using the Azure Resource Manager PowerShell cmdlets. of our resources to the resource group and storage account that we created in this previous post. Once you have built your ARM template, VHD or DSC Configuration  I want to be able to set the access keys of a azure storage account using an ARM Template. Simple answer is that you can't. Currently Azure Storage Service generates access keys for you automatically. You can't choose/specify a custom account key.

Comments
  • You can't do that with ARM Templates. Could you give us more details about your requirements?
  • I have to move all the created json files in one of the project folder to the storage account. I have to use the ARM template and EV2 tool to do this. I am not sure how to start this. Appreciate any ideas if you have.
  • Is there any option to do that using azure functions?
  • Yes, we also could that with Azure function. we could do that with Azure function Http trigger. But on my opinion, we could upload the file with Microsoft Azure Storage Explorer easily.
  • @TomSun As you mentioned is there a way to update existing storage accounts using arm templates such as using our own key to encrypt the storage account etc.. as I have been searching for a while and unable to get anything
  • StorageAccount creation through the ARM template is well documented. The question is asking how to upload a file to a storage account using ARM template, not about storageaccount creation.