-
Notifications
You must be signed in to change notification settings - Fork 57
159 lines (145 loc) · 9.83 KB
/
fgt-azure-marketplace-version-update.yml
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
name: '[FGT] Azure Marketplace version update'
on:
workflow_dispatch:
schedule:
- cron: '00 22 * * 0'
env:
PRODUCT: FortiGate
PRODUCTSHORT: FGT
PRODUCTOFFER: fortinet_fortigate-vm_v5
PRODUCTSKU_X64: fortinet_fg-vm
PRODUCTSKU_ARM64: fortinet_fg-vm_arm64
jobs:
ARM-FGT-Version-Update:
name: Update FGT version list
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Azure Login via Az module
uses: azure/login@v2
with:
creds: ${{secrets.AZURE_CREDENTIALS}}
enable-AzPSSession: true
- name: Verify FGT published version, update templates when new version found
uses: azure/powershell@v2
with:
inlineScript: |
function Sort-Versions {
param (
[string[]]$Versions
)
$parsedVersions = $Versions | ForEach-Object {
$versionParts = $_ -split '\.'
[pscustomobject]@{
Major = [int]$versionParts[0]
Minor = [int]$versionParts[1]
Patch = [int]$versionParts[2]
FullVersion = $_
}
}
$sortedVersions = $parsedVersions | Sort-Object -Property Major, Minor, Patch -Descending
$sortedVersions.FullVersion
}
$buildingBlocks = @("A-Single-VM", "Active-Active-ELB-ILB","Active-Passive-ELB-ILB","Active-Passive-SDN")
$marketplaceVersions_x64 = @()
$marketplaceVersionsUI_x64 = @()
$marketplaceVersions_arm64 = @()
$marketplaceVersionsUI_arm64 = @()
$marketplaceVersions_x64 = @("latest") + $(Sort-Versions($(Get-AzVMImage -PublisherName "fortinet" -Location eastus -Offer "${env:PRODUCTOFFER}" -sku "${env:PRODUCTSKU_X64}").Version))
$marketplaceVersions_x64 | ConvertTo-Json | Out-File -Filepath "./fgtversion_x64.json"
$marketplaceVersions_x64 | ForEach-Object { $marketplaceVersionsUI_x64 += [pscustomobject]@{label=$_;value=$_} }
$marketplaceVersionsUI_x64 | ConvertTo-Json | Out-File -Filepath "./fgtversionui_x64.json"
$marketplaceVersions_arm64 = @("latest") + $(Sort-Versions($(Get-AzVMImage -PublisherName "fortinet" -Location eastus -Offer "${env:PRODUCTOFFER}" -sku "${env:PRODUCTSKU_ARM64}").Version))
$marketplaceVersions_arm64 | ConvertTo-Json | Out-File -Filepath "./fgtversion_arm64.json"
$marketplaceVersions_arm64 | ForEach-Object { $marketplaceVersionsUI_arm64 += [pscustomobject]@{label=$_;value=$_} }
$marketplaceVersionsUI_arm64 | ConvertTo-Json | Out-File -Filepath "./fgtversion_arm64_ui.json"
foreach ($buildingBlock in $buildingBlocks) {
if (Test-Path -Path "./${env:PRODUCT}/${buildingBlock}/mainTemplate.json" -PathType Leaf) {
Get-Content -Raw -Path "./${env:PRODUCT}/${buildingBlock}/mainTemplate.json" | jq --slurpfile content "./fgtversion_x64.json" '.parameters.fortiGateImageVersion_x64.allowedValues = $content[]' | Set-Content -Path "./${env:PRODUCT}/${buildingBlock}/mainTemplate.json"
$content = Get-Content "./${env:PRODUCT}/${buildingBlock}/mainTemplate.json" -Raw
if (-Not $content -match '(?<=\r\n)\z') {
"" | Out-File -Append "./${env:PRODUCT}/${buildingBlock}/mainTemplate.json"
}
Get-Content -Raw -Path "./${env:PRODUCT}/${buildingBlock}/mainTemplate.json" | jq --slurpfile content "./fgtversion_arm64.json" '.parameters.fortiGateImageVersion_arm64.allowedValues = $content[]' | Set-Content -Path "./${env:PRODUCT}/${buildingBlock}/mainTemplate.json"
$content = Get-Content "./${env:PRODUCT}/${buildingBlock}/mainTemplate.json" -Raw
if (-Not $content -match '(?<=\r\n)\z') {
"" | Out-File -Append "./${env:PRODUCT}/${buildingBlock}/mainTemplate.json"
}
}
if (Test-Path -Path "./${env:PRODUCT}/${buildingBlock}/azuredeploy.json" -PathType Leaf) {
Get-Content -Raw -Path "./${env:PRODUCT}/${buildingBlock}/azuredeploy.json" | jq --slurpfile content "./fgtversion_x64.json" '.parameters.fortiGateImageVersion_x64.allowedValues = $content[]' | Set-Content -Path "./${env:PRODUCT}/${buildingBlock}/azuredeploy.json"
$content = Get-Content "./${env:PRODUCT}/${buildingBlock}/azuredeploy.json" -Raw
if (-Not $content -match '(?<=\r\n)\z') {
"" | Out-File -Append "./${env:PRODUCT}/${buildingBlock}/azuredeploy.json"
}
Get-Content -Raw -Path "./${env:PRODUCT}/${buildingBlock}/azuredeploy.json" | jq --slurpfile content "./fgtversion_arm64.json" '.parameters.fortiGateImageVersion_arm64.allowedValues = $content[]' | Set-Content -Path "./${env:PRODUCT}/${buildingBlock}/azuredeploy.json"
$content = Get-Content "./${env:PRODUCT}/${buildingBlock}/azuredeploy.json" -Raw
if (-Not $content -match '(?<=\r\n)\z') {
"" | Out-File -Append "./${env:PRODUCT}/${buildingBlock}/azuredeploy.json"
}
}
if (Test-Path -Path "./${env:PRODUCT}/${buildingBlock}/createUiDefinition.json" -PathType Leaf) {
Get-Content -Raw -Path "./${env:PRODUCT}/${buildingBlock}/createUiDefinition.json" | jq --slurpfile content "./fgtversionui_x64.json" '(.parameters.steps[].elements[] | select( .name == "instancetype_x64") | .elements[] | select( .name == "fortiGateImageVersion_x64") | .constraints.allowedValues) |= $content[]' | Set-Content -Path "./${env:PRODUCT}/${buildingBlock}/createUiDefinition.json"
$content = Get-Content "./${env:PRODUCT}/${buildingBlock}/createUiDefinition.json" -Raw
if (-Not $content -match '(?<=\r\n)\z') {
"" | Out-File -Append "./${env:PRODUCT}/${buildingBlock}/createUiDefinition.json"
}
Get-Content -Raw -Path "./${env:PRODUCT}/${buildingBlock}/createUiDefinition.json" | jq --slurpfile content "./fgtversion_arm64_ui.json" '(.parameters.steps[].elements[] | select( .name == "instancetype_arm64") | .elements[] | select( .name == "fortiGateImageVersion_arm64") | .constraints.allowedValues) |= $content[]' | Set-Content -Path "./${env:PRODUCT}/${buildingBlock}/createUiDefinition.json"
$content = Get-Content "./${env:PRODUCT}/${buildingBlock}/createUiDefinition.json" -Raw
if (-Not $content -match '(?<=\r\n)\z') {
"" | Out-File -Append "./${env:PRODUCT}/${buildingBlock}/createUiDefinition.json"
}
}
}
$buildingBlocks = @("AzureApplicationGateway/scenario1","AzureApplicationGateway/scenario2","AzureApplicationGateway/scenario3","AzureGatewayLoadBalancer","AzureRouteServer/Active-Passive","ZTNAApplicationGateway")
foreach ($buildingBlock in $buildingBlocks) {
if (Test-Path -Path "./${env:PRODUCT}/${buildingBlock}/mainTemplate.json" -PathType Leaf) {
Get-Content -Raw -Path "./${env:PRODUCT}/${buildingBlock}/mainTemplate.json" | jq --slurpfile content "./fgtversion_x64.json" '.parameters.fortiGateImageVersion.allowedValues = $content[]' | Set-Content -Path "./${env:PRODUCT}/${buildingBlock}/mainTemplate.json"
$content = Get-Content "./${env:PRODUCT}/${buildingBlock}/mainTemplate.json" -Raw
if (-Not $content -match '(?<=\r\n)\z') {
"" | Out-File -Append "./${env:PRODUCT}/${buildingBlock}/mainTemplate.json"
}
}
if (Test-Path -Path "./${env:PRODUCT}/${buildingBlock}/azuredeploy.json" -PathType Leaf) {
Get-Content -Raw -Path "./${env:PRODUCT}/${buildingBlock}/azuredeploy.json" | jq --slurpfile content "./fgtversion_x64.json" '.parameters.fortiGateImageVersion.allowedValues = $content[]' | Set-Content -Path "./${env:PRODUCT}/${buildingBlock}/azuredeploy.json"
$content = Get-Content "./${env:PRODUCT}/${buildingBlock}/azuredeploy.json" -Raw
if (-Not $content -match '(?<=\r\n)\z') {
"" | Out-File -Append "./${env:PRODUCT}/${buildingBlock}/azuredeploy.json"
}
}
if (Test-Path -Path "./${env:PRODUCT}/${buildingBlock}/createUiDefinition.json" -PathType Leaf) {
Get-Content -Raw -Path "./${env:PRODUCT}/${buildingBlock}/createUiDefinition.json" | jq --slurpfile content "./fgtversionui_x64.json" '(.parameters.basics[] | select( .name == "fortiGateImageVersion") | .constraints.allowedValues) |= $content[]' | Set-Content -Path "./${env:PRODUCT}/${buildingBlock}/createUiDefinition.json"
$content = Get-Content "./${env:PRODUCT}/${buildingBlock}/createUiDefinition.json" -Raw
if (-Not $content -match '(?<=\r\n)\z') {
"" | Out-File -Append "./${env:PRODUCT}/${buildingBlock}/createUiDefinition.json"
}
}
}
Remove-Item "./fgtversion_x64.json"
Remove-Item "./fgtversionui_x64.json"
Remove-Item "./fgtversion_arm64.json"
Remove-Item "./fgtversion_arm64_ui.json"
azPSVersion: "latest"
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: Update report
committer: GitHub <[email protected]>
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
signoff: false
branch: fgt-vm-update-version
delete-branch: true
title: '[FGT] Azure Marketplace FGT Version update'
body: |
Update report
- Updated FGT version in building blocks: "A-Single-VM", "Active-Active-ELB-ILB","Active-Passive-ELB-ILB","Active-Passive-SDN"
- Auto-generated by [create-pull-request][1]
[1]: https://github.com/peter-evans/create-pull-request
labels: |
report
automated pr
assignees: jvhoof
reviewers: jvhoof
draft: false