-
Notifications
You must be signed in to change notification settings - Fork 0
/
Run-Factory.ps1
92 lines (74 loc) · 2.88 KB
/
Run-Factory.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<#
.SYNOPSIS
ImageFactory Control Script
.DESCRIPTION
.EXAMPLE
.\Run-ImageFactory.ps1
Version History
v1.0 - Initial Release
#>
#Requires -Version 5.1
#Requires -Module @{ModuleName='AzureRM'; ModuleVersion='6.7.0'}
Param (
[Parameter(HelpMessage="The Azure Subscription Id")]
[string]$Subscription = $Env:AZURE_SUBSCRIPTION,
[Parameter(HelpMessage="The Azure Region Location")]
[string]$Location = $Env:AZURE_LOCATION,
[Parameter(HelpMessage="The Local VM Administrator Name")]
[string]$AdminUserName = $Env:AZURE_ADMINUSER,
[Parameter(HelpMessage="The Local VM Administrator Password")]
[securestring]$AdminPassword = (ConvertTo-SecureString -String "$Env:AZURE_ADMINPASSWORD" -AsPlainText -Force),
[Parameter(HelpMessage="DevTest Lab Name")]
[string]$DevTestLabName = "ImageFactory",
[Parameter(HelpMessage="Show Environment Variables")]
[string]$ShowEnv = $false
)
if($ShowEnv -eq $true) {Get-ChildItem Env:AZURE*}
# Test for Required Environment Settings
if (!$Subscription) {
if (!$Env:AZURE_SUBSCRIPTION) {throw "SubscriptionId Required" }
else {$Subscription = $Env:AZURE_SUBSCRIPTION}
}
if ( !$Location) {
if (!$Env:AZURE_LOCATION) {throw "Location Required" }
else {$Location = $Env:AZURE_LOCATION}
}
if ( !$AdminUserName) {
if (!$Env:AZURE_ADMINUSER) {throw "AdminUserName Required" }
else {$AdminUserName = $Env:AZURE_ADMINUSER}
}
if ( !$AdminPassword) {
if (!$Env:AZURE_ADMINPASSWORD) {throw "AdminPassword Required" }
else {$AdminPassword = $Env:AZURE_ADMINPASSWORD}
}
###############################
## Azure Intialize ##
###############################
$ConfigFiles = "./Configuration"
$functionPath = Join-Path (Split-Path ($Script:MyInvocation.MyCommand.Path)) "Scripts/functions.ps1"
if (Test-Path $functionPath) { . $functionPath }
LoginAzure $Subscription
##############################
## Execute SubScripts ##
##############################
# Scrape source code control for json files + create all VMs discovered
# .\Scripts\Make-GoldImageVMs.ps1 -ConfigurationLocation $ConfigFiles `
# -DevTestLabName $DevTestLabName `
# -AdminUserName $AdminUserName `
# -AdminPassword $AdminPassword `
# -StandardTimeoutMinutes 60
# For all created VMs, save as images
# .\Scripts\Snap-Image.ps1 -DevTestLabName $DevTestLabName
# For all images, distribute to all labs that have 'signed up' for the image
# .\Scripts\Distribute-Image.ps1 -ConfigurationLocation $ConfigFiles `
# -SubscriptionId $Subscription `
# -DevTestLabName $DevTestLabName `
# -MaxJobs 20
# Clean up any leftover stopped VMs in the factory
#.\Scripts\CleanUp-Factory.ps1 -DevTestLabName $DevTestLabName
## TODO STILL
# Retire all 'old' images from the factory lab and all other connected labs (cascade deletes)
.\Scripts\Retire-Images.ps1 -ConfigurationLocation $ConfigFiles `
-SubscriptionId $Subscription `
-DevTestLabName $DevTestLabName `
-ImagesToSave 2