简体   繁体   中英

Copy a file from storage using Azure Resource Manager Template?

I am looking to copy a file from my storage account to a VM that is being created using an ARM template?

I have already created the storage account and added the files to the storage account. I am busy creating the template but don't see any option to copy the files from the storage account to the OSDisk that gets created when creating the VirtualMachine.

Update I feel I should give some background of what I want to achieve:

  1. I want to create ARM deploy.json and parameters.json
  2. Using the above JSON I would like to use the Azure Java SDK to create the VM in Azure
  3. In the JSON I will be using the docker extension to build out docker containers
  4. The docker containers will use base images from DockerHub and then will be customised using the compose which is supported in the DockerExtension
  5. I need to copy certain files over from the storage account so that the Docker Extension can use these files as part of the docker compose when building the custom docker containers
  6. The Java SDK will make certain decisions based on user input which will then generate the parameters.json for the Azure Java SDK

So based on this I need to somehow copy the files from storage to the VM before the azure docker extension executes.

One way of achieving this would be to use a Custom script extension, which is added to your VM. It allows you to run a powershell script at the time of deployment that runs on the VM. In the JSON outline window in Visual Studio, click add resource

添加资源

Then add a custom script extension and link it to the VM

添加自定义脚本扩展

This will add a blank powershell script to the newly created custom script folder in your project. Here you can put the script to download the file from blob. Like this .

If you want to do it with DSC, here's a sample: https://github.com/bmoore-msft/AzureRM-Samples/tree/master/VMDSCInstallFile . Ed's answer might be a simpler approach though. The key here is getting the credentials to the VM to be able to pull from storage. That means whether you're using DSC or a custom script, you need to get the location/uri and a sasToken to the script (unless the files are unsecured). The DSC sample above will give you a way to pass the uri/token that will work in either workflow. Look at the PS script in the root to see how the uri & token are created and passed to the template deployment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM