forked from dmauser/opnazure
-
Notifications
You must be signed in to change notification settings - Fork 0
162 lines (142 loc) · 6.26 KB
/
deploymentCheker-sing-nic.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
160
161
162
name: Deployment Checker - Single Nic
# Prerequisites
# 1. Set up your AZURE CREDENTIALS SECRET as per : https://github.com/marketplace/actions/azure-login#configure-a-service-principal-with-a-secret
# 2. Make sure the Service Principal has IAM Owner on the Resource Group you're deploying into.
on:
#Run on Manual execution
workflow_dispatch:
#Run when bicep code changes
# push:
# branches:
# - 'master'
# - 'dev'
# paths:
# - "bicep/main-sing-nic.bicep"
# - "bicep/main-sing-nic.parameters.json"
# - ".github/workflows/deploymentCheker-sing-nic.yml"
#Run when PR's are made to main, where the changes are in the bicep directory or this workflow file itself
pull_request:
branches:
- 'master'
paths:
#- "bicep/main-active-active.parameters.json"
- "bicep/*"
- ".github/workflows/deploymentCheker-sing-nic.yml"
#Run on a weekly schedule
#schedule:
# At 11:00pm, every Tuesday week
# - cron: "0 23 * * 2"
env:
RG: "Automation-Actions-OPNAZURE-sing-nic-${{ github.run_number }}" #The resource group we're deploying to.
Location: "eastus"
ParamFilePath: "bicep/main.parameters.json" #Path to parameter file
TemplateFilePath: "bicep/main.bicep"
OPNsense-PIP: "OPNsense-PublicIP"
VNET: "OPN-VNET"
VNETAddress: "10.0.0.0/16"
UntrustedSubnet: "Untrusted-Subnet"
UntrustedSubnetAddress: "10.0.0.0/24"
TrustedSubnet: "Trusted-Subnet"
TrustedSubnetAddress: "10.0.1.0/24"
scenarioOption: "SingleNic"
existingvirtualNetwork: "existing"
DeployWindows: false
OpnScriptURI: "https://raw.githubusercontent.com/itsgudenuf/opnazure/master/scripts/"
DEPNAME: "Dep-OPNsense-sing-nic-${{ github.run_number }}" #Deployment Name
AZCLIVERSION: 2.36.0 #Pinning to a specific AZ CLI version
jobs:
Validation:
runs-on: ubuntu-latest
steps:
#Get the code files from the repo
- uses: actions/checkout@v3
- name: Job parameter check
run: |
RG='${{ env.RG }}'
echo "RG is: $RG"
echo "Param file path is: ${{ env.ParamFilePath }}"
echo "Template file path is: ${{ env.TemplateFilePath }}"
echo "Deployment name is ${{ env.DEPNAME }}"
echo "AZ cli version is ${{ env.AZCLIVERSION }}"
- name: Arm Parameter file check exists
shell: pwsh
run: |
Write-Output "Checking parameter file existance/contents"
$paramFilePath="${{ env.ParamFilePath }}"
Test-Path $paramFilePath
if (Test-Path $paramFilePath) {
$paramFileContent=Get-Content $paramFilePath
Write-Output $paramFileContent
}
- name: Azure Login
uses: Azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
enable-AzPSSession: false
environment: azurecloud
allow-no-subscriptions: false
- name: Validate Infrastructure deployment
uses: Azure/cli@v1
with:
azcliversion: ${{ env.AZCLIVERSION }}
inlineScript: |
az group create -l '${{ env.Location }}' -g '${{ env.RG }}'
az network vnet create -g '${{ env.RG }}' -n '${{ env.VNET }}' --address-prefixes '${{ env.VNETAddress }}'
az network vnet subnet create -g '${{ env.RG }}' --vnet-name '${{ env.VNET }}' -n '${{ env.UntrustedSubnet }}' --address-prefixes '${{ env.UntrustedSubnetAddress }}'
OpnScriptURI=$(echo ${{ env.OpnScriptURI }} | sed -e "s_master_${GITHUB_HEAD_REF}_")
az deployment group validate -g '${{ env.RG }}' -n '${{ env.DEPNAME }}' -f ${{ env.TemplateFilePath }} -p ${{ env.ParamFilePath }} -p scenarioOption=${{ env.scenarioOption }} -p existingvirtualNetwork=${{ env.existingvirtualNetwork }} -p existingUntrustedSubnetName=${{ env.UntrustedSubnet }} -p DeployWindows=${{ env.DeployWindows }} -p OpnScriptURI=$OpnScriptURI
Deploy:
runs-on: ubuntu-latest
needs: [Validation]
steps:
- uses: actions/checkout@v3
- name: Azure Login
uses: Azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
enable-AzPSSession: false
environment: azurecloud
allow-no-subscriptions: false
- name: Deploy Infrastructure
id: deployAks
uses: Azure/cli@v1
with:
azcliversion: ${{ env.AZCLIVERSION }}
inlineScript: |
OpnScriptURI=$(echo ${{ env.OpnScriptURI }} | sed -e "s_master_${GITHUB_HEAD_REF}_")
echo Executing: az deployment group create -g ${{ env.RG }} -n ${{ env.DEPNAME }} -f ${{ env.TemplateFilePath }} -p ${{ env.ParamFilePath }} -p scenarioOption=${{ env.scenarioOption }} -p existingvirtualNetwork=${{ env.existingvirtualNetwork }} -p existingUntrustedSubnetName=${{ env.UntrustedSubnet }} -p DeployWindows=${{ env.DeployWindows }} -p OpnScriptURI=$OpnScriptURI --verbose
az deployment group create -g ${{ env.RG }} -n ${{ env.DEPNAME }} -f ${{ env.TemplateFilePath }} -p ${{ env.ParamFilePath }} -p scenarioOption=${{ env.scenarioOption }} -p existingvirtualNetwork=${{ env.existingvirtualNetwork }} -p existingUntrustedSubnetName=${{ env.UntrustedSubnet }} -p DeployWindows=${{ env.DeployWindows }} -p OpnScriptURI=$OpnScriptURI --verbose
CheckOPNsenseAvailability:
runs-on: ubuntu-latest
needs: [Deploy]
steps:
- uses: actions/checkout@v3
- name: Azure Login
uses: Azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
enable-AzPSSession: true
environment: azurecloud
allow-no-subscriptions: false
- name: Test OPNsense Access
run: |
PIP=$(az network public-ip show -g '${{ env.RG }}' -n '${{ env.OPNsense-PIP }}' --query "ipAddress" -o tsv)
#curl -k https://$PIP --verbose
Cleanup:
runs-on: ubuntu-latest
needs: [Validation, Deploy, CheckOPNsenseAvailability]
if: always()
steps:
- name: Azure Login
uses: Azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
enable-AzPSSession: true
environment: azurecloud
allow-no-subscriptions: false
- name: Cleanup
uses: Azure/cli@v1
with:
azcliversion: ${{ env.AZCLIVERSION }}
inlineScript: |
az group delete -n '${{ env.RG }}' -y --verbose