feat: added pwsh to deploy the lab vm

Former-commit-id: 0d24a349056ec0a67c39da21232a765a8da71477
This commit is contained in:
Renan Vilas Novas 2021-09-21 16:39:13 -03:00
Родитель d9b37e63a7
Коммит 038923065c
1 изменённых файлов: 87 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,87 @@
param (
[parameter(mandatory=$true)]
[string]$sourceSas,
# Size of the VHD snapshot in bytes
[long]$vhdSizeBytes = 136367309312,
# Region to deploy the VM
[string]$location = 'eastus',
# VM resource group
[string]$resourceGroupName = 'rg-labvm',
# disk VM name
[string]$diskName = 'disklabvmeastus'
)
Write-Host "[DevSquad In a Day] Initializing the lab VM disk"
$diskconfig = New-AzDiskConfig -SkuName 'Premium_LRS' -OsType 'Windows' -UploadSizeInBytes $vhdSizeBytes -Location $location -CreateOption 'Upload'
New-AzResourceGroup $resourceGroupName -Location $location
New-AzDisk -ResourceGroupName $resourceGroupName -DiskName $diskName -Disk $diskconfig
$diskSas = Grant-AzDiskAccess -ResourceGroupName $resourceGroupName -DiskName $diskName -DurationInSecond 86400 -Access 'Write'
$disk = Get-AzDisk -ResourceGroupName $resourceGroupName -DiskName $diskName
Write-Host "[DevSquad In a Day] Copying the lab VM snapshot to your subscription"
azcopy copy $sourceSas $diskSas.AccessSAS --blob-type PageBlob
Revoke-AzDiskAccess -ResourceGroupName $resourceGroupName -DiskName $diskName
Write-Host "[DevSquad In a Day] Creating the lab VM associated resources"
$subnetName = 'labDsiadSubNet'
$singleSubnet = New-AzVirtualNetworkSubnetConfig `
-Name $subnetName `
-AddressPrefix 10.0.0.0/24
$vnetName = "labDsiadVnet"
$vnet = New-AzVirtualNetwork `
-Name $vnetName -ResourceGroupName $resourceGroupName `
-Location $location `
-AddressPrefix 10.0.0.0/16 `
-Subnet $singleSubnet
$nsgName = "labDsiadNsg"
$rdpRule = New-AzNetworkSecurityRuleConfig -Name myRdpRule -Description "Allow RDP" `
-Access Allow -Protocol Tcp -Direction Inbound -Priority 110 `
-SourceAddressPrefix Internet -SourcePortRange * `
-DestinationAddressPrefix * -DestinationPortRange 3389
$nsg = New-AzNetworkSecurityGroup `
-ResourceGroupName $resourceGroupName `
-Location $location `
-Name $nsgName -SecurityRules $rdpRule
$ipName = "labDsiadIP"
$pip = New-AzPublicIpAddress `
-Name $ipName -ResourceGroupName $resourceGroupName `
-Location $location `
-AllocationMethod Dynamic
$nicName = "labDsiadNicName"
$nic = New-AzNetworkInterface -Name $nicName `
-ResourceGroupName $resourceGroupName `
-Location $location -SubnetId $vnet.Subnets[0].Id `
-PublicIpAddressId $pip.Id `
-NetworkSecurityGroupId $nsg.Id
$vmName = "vm-lab"
$vmConfig = New-AzVMConfig -VMName $vmName -VMSize "Standard_E2s_v3"
$vm = Add-AzVMNetworkInterface -VM $vmConfig -Id $nic.Id
$vm = Set-AzVMOSDisk -VM $vm -ManagedDiskId $disk.Id `
-CreateOption Attach -Windows
Write-Host "[DevSquad In a Day] Creating the lab VM"
New-AzVM -ResourceGroupName $resourceGroupName -Location $location -VM $vm
Write-Host "[DevSquad In a Day] Done!"