Hello,
I want to copy and .exe. as well as a .ps1 new a new provisioned Windows virtual machine as part of the code. I want to then execute the ps1 script to install the .exe on the vm after provisioning. The files are on a azure storage account. Is there any sample code I code use to perform this? I already have the storage account with the files in a container. I just need to access, copy, and execute. Could I use the vm extensions ( azurerm_virtual_machine_extension) for this? Thank you.
You can use terraform Azure virtual machine extension for this purpose. Use below code snippet to achieve this task. Please respond if this solution helps.
/*This is with an assumption that your storage account is publicly accessible.
However, if the storage account is privately accessible with a private endpoint,
make sure that the VM deployed can privately access the storage account.
If not the blob download 'Invoke-WebRequest' will fail.
*/
$baseUri = 'https://<storage acount name>.blob.core.windows.net/<container name>'
$sasurl = '<Blob SAS token>'
$downloadpath = 'C:\Users\text\Documents\tempFolder'
#The two files I'm download are helm-v3.15.4-linux-amd64.exe and TemplateAnalyzer-win-x64.exe
$files = @("helm-v3.15.4-linux-amd64.exe", "TemplateAnalyzer-win-x64.exe")
foreach ($file in $files) {
Invoke-WebRequest -Uri "$($baseUri)/$($file)?$($sasurl)" -OutFile "$($downloadpath)\$file"
}
Start-Process -FilePath "$downloadpath\TemplateAnalyzer-win-x64.exe"
Start-Process -FilePath "$downloadpath\helm-v3.15.4-linux-amd64.exe"