-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLzDeployPipeline.ps1
117 lines (100 loc) · 3.9 KB
/
LzDeployPipeline.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
Write-Host "LzDeployPipeline.ps1 V1.0.0"
Write-Host "Use this script to deploy a pipeline"
$scriptPath = Split-Path $script:MyInvocation.MyCommand.Path
Import-Module (Join-Path -Path $scriptPath -ChildPath LazyStackLib) -Force
Import-Module (Join-Path -Path $scriptPath -ChildPath LazyStackUI) -Force
Test-LzDependencies
$indent = 1
$settingsFile = "smf.yaml"
if(!(Test-Path $settingsFile)) {
Write-LzHost $indent "Error: Can't find ${settingsFile}"
exit
}
$smf = Get-SMF $settingsFile # this routine may prompt user for OrgCode and MgmtProfile
$orgCode = @($smf.Keys)[0]
Write-LzHost $indent "OrgCode:" $orgCode
$LzMgmtProfile = $smf.$orgCode.AWS.MgmtProfile
Write-LzHost $indent "AWS Managment Account:" $LzMgmtProfile
$pipelinesMenu = @()
foreach($sysCode in $smf.$orgCode.Systems.Keys) {
$system = $smf.$orgCode.Systems[$sysCode]
foreach($acctName in $system.Accounts.Keys) {
$awsAcct = $system.Accounts[$acctName]
$accountFullName = $orgCode + $sysCode + $acctName
$pipelines = $awsAcct.Pipelines
foreach($pipelineName in $pipelines.Keys) {
$pipeline = $pipelines[$pipelineName]
$pipelineMenuEntry = @{SysCode=$sysCode; AccountName=$acctName; AccountFullName = $accountFullName; PipelineName=$pipelineName}
$pipelinesMenu += $pipelineMenuEntry
}
}
}
if($pipelinesMenu.Count -eq 0) {
Write-LzHost $indent "No Pipelines found"
exit
}
Write-LzHost $indent "Pipelines"
for($i=0; $i -lt $pipelinesMenu.Count; $i++) {
$item = $pipelinesMenu[$i]
Write-LzHost $indent ($i + 1) $item.AccountName $item.PipelineName
}
$selection = Read-MenuSelection `
-prompt "Select Pipeline to deploy" `
-min 1 `
-max $pipelinesMenu.Count `
-indent $indent `
-options "q"
switch($selection) {
-1 {
exit
}
default {
$pipelineMenuEntry = $pipelinesMenu[$selection - 1]
$sysCode = $pipelineMenuEntry.SysCode
$awsAcctName = $pipelineMenuEntry.AccountName
$pipelineName = $pipelineMenuEntry.PipelineName
Write-Host "orgCode" $orgCode
Write-Host "sysCode" $sysCode
Write-Host "awsAcctName" $awsAcctName
Write-Host "pipeLineName" $pipelineName
$awsAcct = $smf.$orgCode.Systems.$sysCode.Accounts.$awsAcctName
$pipeline = $awsAcct.Pipelines[$pipelineName]
#$pipeline | ConvertTo-Yaml
$LzRegion = $awsAcct.DefaultRegion
if($null -eq $LzRegion -Or $LzRegion -eq "") {
$LzRegion = $smf.AWS.DefaultRegion
if($null -eq $LzRegion -Or $LzRegion -eq "") {
$LzRegion = "us-east-1"
}
}
$region = $pipeline.Region
if($null -eq $region -Or $region -eq "") {
$region = $LzRegion #default from account
}
$templateParams = ""
if($null -ne $pipeline.TemplateParams) {
foreach($propertyName in $pipeline.TemplateParams.Keys) {
$templateParams += (" " + $propertyName + "=" + '"' + $pipeline.TemplateParams.$propertyName + '" ')
}
}
$LzAccessRoleProfile = $orgCode + $sysCode + $awsAcctName + "AccessRole"
$stackName = Get-ValidAwsStackName($pipelineName + "-" + $pipeline.Region) # replace non-alphanumeric characters with "-"
$stackName = $stackName.ToLower()
if($templateParams -eq "") {
sam deploy `
--stack-name $stackName `
-t $pipeline.TemplatePath `
--capabilities CAPABILITY_NAMED_IAM `
--profile $LzAccessRoleProfile `
--region $region
} else {
sam deploy `
--stack-name $stackName `
-t $pipeline.TemplatePath `
--capabilities CAPABILITY_NAMED_IAM `
--parameter-overrides $templateParams `
--profile $LzAccessRoleProfile `
--region $region
}
}
}