mirror of
https://github.com/actions/runner-images-sangeeth.git
synced 2025-12-10 11:41:32 +00:00
Make CreateAzureVMFromPackerTemplate friendlier (#3209)
* Don't assume JSON output Specify JSON output, since it's required. The default can be changed. * Make actions easier to track To make cleanup easier, use the same GUID for all components and report at the end on what was created.
This commit is contained in:
@@ -48,21 +48,22 @@ Function CreateAzureVMFromPackerTemplate {
|
||||
)
|
||||
|
||||
$vmSize = "Standard_DS2_v2"
|
||||
$vnetName = $env:UserName + [System.GUID]::NewGuid().ToString().ToUpper()
|
||||
$subnetName = $env:UserName + [System.GUID]::NewGuid().ToString().ToUpper()
|
||||
$nicName = $env:UserName + [System.GUID]::NewGuid().ToString().ToUpper()
|
||||
$publicIpName = $env:UserName + [System.GUID]::NewGuid().ToString().ToUpper()
|
||||
$guid = [System.GUID]::NewGuid().ToString().ToUpper()
|
||||
$vnetName = $env:UserName + "vnet-" + $guid
|
||||
$subnetName = $env:UserName + "subnet-" + $guid
|
||||
$nicName = $env:UserName + "nic-" + $guid
|
||||
$publicIpName = $env:UserName + "pip-" + $guid
|
||||
|
||||
Write-Host "Creating a virtual network and subnet"
|
||||
($vnet = az network vnet create -g $ResourceGroupName -l $AzureLocation -n $vnetName --address-prefixes 10.0.0.0/16 --subnet-name $subnetName --subnet-prefixes 10.0.1.0/24 --subscription $subscriptionId)
|
||||
($vnet = az network vnet create -g $ResourceGroupName -l $AzureLocation -n $vnetName --address-prefixes 10.0.0.0/16 --subnet-name $subnetName --subnet-prefixes 10.0.1.0/24 --subscription $subscriptionId -o json)
|
||||
$subnetId = ($vnet | ConvertFrom-Json).newVNet.subnets[0].id
|
||||
|
||||
Write-Host "`nCreating a network interface controller (NIC)"
|
||||
($nic = az network nic create -g $ResourceGroupName -l $AzureLocation -n $nicName --subnet $subnetId --subscription $subscriptionId)
|
||||
($nic = az network nic create -g $ResourceGroupName -l $AzureLocation -n $nicName --subnet $subnetId --subscription $subscriptionId -o json)
|
||||
$networkId = ($nic | ConvertFrom-Json).NewNIC.id
|
||||
|
||||
Write-Host "`nCreating a public IP address"
|
||||
($publicIp = az network public-ip create -g $ResourceGroupName -l $AzureLocation -n $publicIpName --allocation-method Static --sku Standard --version IPv4 --subscription $subscriptionId)
|
||||
($publicIp = az network public-ip create -g $ResourceGroupName -l $AzureLocation -n $publicIpName --allocation-method Static --sku Standard --version IPv4 --subscription $subscriptionId -o json)
|
||||
$publicIpId = ($publicIp | ConvertFrom-Json).publicIp.id
|
||||
|
||||
Write-Host "`nAdding the public IP to the NIC"
|
||||
@@ -70,4 +71,6 @@ Function CreateAzureVMFromPackerTemplate {
|
||||
|
||||
Write-Host "`nCreating the VM"
|
||||
az group deployment create -g $ResourceGroupName -n $VirtualMachineName --subscription $subscriptionId --template-file $templateFilePath --parameters vmSize=$vmSize vmName=$VirtualMachineName adminUserName=$AdminUsername adminPassword=$AdminPassword networkInterfaceId=$networkId
|
||||
|
||||
Write-Host "`nCreated in $(ResourceGroupName):`n vnet $(vnetName)`n subnet $(subnetName)`n nic $(nicName)`n publicip $(publicIpName)`n vm $(VirtualMachineName)"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user