From 9f38fe084500f95ac48183b50f52bbc7b60fed0b Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Fri, 18 Aug 2023 21:36:27 -0700 Subject: [PATCH 01/55] Initial test of GitHub Actions for end-to-end testing of Azure IPAM --- deploy/deploy.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/deploy/deploy.ps1 b/deploy/deploy.ps1 index 5c3d1dd..472ff79 100644 --- a/deploy/deploy.ps1 +++ b/deploy/deploy.ps1 @@ -859,6 +859,8 @@ process { -AsFunction $AsFunction ` -Tags $Tags ` -ResourceNames $ResourceNames + + Write-Output "ipamSuffix=$($deployment.Outputs["suffix"].Value)" >> $Env:GITHUB_OUTPUT } if ($PSCmdlet.ParameterSetName -eq 'Full') { From 7be8518e304ae7659057f36c59cb0230eebf6259 Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Fri, 18 Aug 2023 21:53:42 -0700 Subject: [PATCH 02/55] Removed workflows folder from gitignore --- .github/workflows/azure-ipam-testing.yml | 58 ++++++++++++++++++++++++ .gitignore | 1 - 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/azure-ipam-testing.yml diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml new file mode 100644 index 0000000..b4936ff --- /dev/null +++ b/.github/workflows/azure-ipam-testing.yml @@ -0,0 +1,58 @@ +name: Azure IPAM Testing + +permissions: + id-token: write + contents: read + +run-name: Azure IPAM Deployment & Testing + +on: + push: + branches: [ github-actions ] + pull_request: + branches: [ main ] + +env: + IPAM_UI_ID: ipam-ui-${{ github.run_id }}-${{ github.run_attempt }} + IPAM_ENGINE_ID: ipam-engine-${{ github.run_id }}-${{ github.run_attempt }} + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - run: echo "Job triggered by a ${{ github.event_name }} event from ${{ github.head_ref }} to main." + + - name: "Azure Login" + uses: azure/login@v1 + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + + - name: Checkout Azure IPAM Code + uses: actions/checkout@v3 + + - name: List files in the repository + run: | + ls ${{ github.workspace }} + + - run: echo "UI-ID -> $IPAM_UI_ID" + - run: echo "ENGINE-ID -> $IPAM_ENGINE_ID" + + - name: Deploy Azure IPAM + working-directory: "deploy" + id: "pwshScript" + shell: pwsh + run: .\deploy.ps1 -Location "westus3" -UIAppName $Env:IPAM_UI_ID -EngineAppName $Env:IPAM_ENGINE_ID + + - name: "Output PowerShell Value 'ipamSuffix'" + run: echo "${{ steps.pwshScript.outputs.ipamSuffix }}" + + - name: "Test Sleepy Time" + run: | + echo "Time: $(date +'%T')" + echo "Sleeping for 30 seconds" + sleep 30 + echo "Time: $(date +'%T')" + + - run: echo "${{ github.job }} status is ${{ job.status }}." diff --git a/.gitignore b/.gitignore index 423e19e..a2ace75 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ .env .VSCodeCounter -.github/workflows NOTES.md TODO.md /logs From e75b916810f54f40c0e328f7d38b9ec9be520f9e Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Fri, 18 Aug 2023 22:08:10 -0700 Subject: [PATCH 03/55] Added prerequisites to testing workflow --- .github/workflows/azure-ipam-testing.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index b4936ff..1520d09 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -32,12 +32,11 @@ jobs: - name: Checkout Azure IPAM Code uses: actions/checkout@v3 - - name: List files in the repository + - name: Install Deployment Prerequisites + shell: pwsh run: | - ls ${{ github.workspace }} - - - run: echo "UI-ID -> $IPAM_UI_ID" - - run: echo "ENGINE-ID -> $IPAM_ENGINE_ID" + Set-PSRepository PSGallery -InstallationPolicy Trusted + Install-Module Az, Microsoft.Graph - name: Deploy Azure IPAM working-directory: "deploy" From b4115b04763d295897a90c6ecf1f3e1162ba01ae Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Fri, 18 Aug 2023 22:23:19 -0700 Subject: [PATCH 04/55] Enabled PowerShell session for workflow --- .github/workflows/azure-ipam-testing.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index 1520d09..3758996 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -28,6 +28,7 @@ jobs: client-id: ${{ secrets.AZURE_CLIENT_ID }} subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} tenant-id: ${{ secrets.AZURE_TENANT_ID }} + enable-AzPSSession: true - name: Checkout Azure IPAM Code uses: actions/checkout@v3 From 28a681744a13a3327fcf7a623a47c3347c2f5c4f Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Fri, 18 Aug 2023 22:47:16 -0700 Subject: [PATCH 05/55] Trying forward slash to execute script --- .github/workflows/azure-ipam-testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index 3758996..c893473 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -43,7 +43,7 @@ jobs: working-directory: "deploy" id: "pwshScript" shell: pwsh - run: .\deploy.ps1 -Location "westus3" -UIAppName $Env:IPAM_UI_ID -EngineAppName $Env:IPAM_ENGINE_ID + run: ./deploy.ps1 -Location "westus3" -UIAppName $Env:IPAM_UI_ID -EngineAppName $Env:IPAM_ENGINE_ID - name: "Output PowerShell Value 'ipamSuffix'" run: echo "${{ steps.pwshScript.outputs.ipamSuffix }}" From 80a77ea9677ed1c5704b8568ba215febec81f5c4 Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Fri, 18 Aug 2023 22:51:39 -0700 Subject: [PATCH 06/55] Moved prerequisites to earlier in workflow --- .github/workflows/azure-ipam-testing.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index c893473..dbd2e8c 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -22,6 +22,12 @@ jobs: steps: - run: echo "Job triggered by a ${{ github.event_name }} event from ${{ github.head_ref }} to main." + - name: Install Deployment Prerequisites + shell: pwsh + run: | + Set-PSRepository PSGallery -InstallationPolicy Trusted + Install-Module Az, Microsoft.Graph -Force + - name: "Azure Login" uses: azure/login@v1 with: @@ -33,12 +39,6 @@ jobs: - name: Checkout Azure IPAM Code uses: actions/checkout@v3 - - name: Install Deployment Prerequisites - shell: pwsh - run: | - Set-PSRepository PSGallery -InstallationPolicy Trusted - Install-Module Az, Microsoft.Graph - - name: Deploy Azure IPAM working-directory: "deploy" id: "pwshScript" From 26dd42afda4189b4d6e4e4db075bdbc71f1cfa7b Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Fri, 18 Aug 2023 22:53:27 -0700 Subject: [PATCH 07/55] Fixed indentation --- .github/workflows/azure-ipam-testing.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index dbd2e8c..75f4e3a 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -23,10 +23,10 @@ jobs: - run: echo "Job triggered by a ${{ github.event_name }} event from ${{ github.head_ref }} to main." - name: Install Deployment Prerequisites - shell: pwsh - run: | - Set-PSRepository PSGallery -InstallationPolicy Trusted - Install-Module Az, Microsoft.Graph -Force + shell: pwsh + run: | + Set-PSRepository PSGallery -InstallationPolicy Trusted + Install-Module Az, Microsoft.Graph -Force - name: "Azure Login" uses: azure/login@v1 From f4f8ba663d103797863969c09c6c6c313532ba10 Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Sat, 19 Aug 2023 22:01:24 -0700 Subject: [PATCH 08/55] Added log upload to workflow --- .github/workflows/azure-ipam-testing.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index 75f4e3a..ff71d75 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -55,4 +55,20 @@ jobs: sleep 30 echo "Time: $(date +'%T')" + - name: "Upload Logs" + working-directory: "logs" + run: | + $archiveName = "ipam-" + (Get-Date -UFormat "%Y-%m-%d_%I-%M-%S_%p").tostring() + ".zip" + Compress-Archive -Pat ./* -DestinationPath /tmp/$archiveName + $storage = Get-AzStorageAccount -Name "ipamghactionlogs" -ResourceGroupName "Logging-RG" + $context = $storage.Context + @uploadDetails = @{ + File = "/tmp/$archiveName" + Container = "deploy-logs" + Blob = $archiveName + Context = $context + StandardBlobTier = "Hot" + } + Set-AzStorageBlobContent @uploadDetails + - run: echo "${{ github.job }} status is ${{ job.status }}." From fd3beb9b27ab9412d209f468ad6ae9b72c521983 Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Sat, 19 Aug 2023 22:19:10 -0700 Subject: [PATCH 09/55] Fixed log file creation string --- .github/workflows/azure-ipam-testing.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index ff71d75..701924c 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -58,7 +58,8 @@ jobs: - name: "Upload Logs" working-directory: "logs" run: | - $archiveName = "ipam-" + (Get-Date -UFormat "%Y-%m-%d_%I-%M-%S_%p").tostring() + ".zip" + $dateStamp = (Get-Date -UFormat "%Y-%m-%d_%I-%M-%S_%p").tostring() + $archiveName = "ipam-${dateStamp}.zip" Compress-Archive -Pat ./* -DestinationPath /tmp/$archiveName $storage = Get-AzStorageAccount -Name "ipamghactionlogs" -ResourceGroupName "Logging-RG" $context = $storage.Context From a352adad58fa8f012c3da1e15d0cbe1f496c4ca7 Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Sat, 19 Aug 2023 22:35:33 -0700 Subject: [PATCH 10/55] Set shell to pwsh --- .github/workflows/azure-ipam-testing.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index 701924c..7baf6cb 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -57,6 +57,7 @@ jobs: - name: "Upload Logs" working-directory: "logs" + shell: pwsh run: | $dateStamp = (Get-Date -UFormat "%Y-%m-%d_%I-%M-%S_%p").tostring() $archiveName = "ipam-${dateStamp}.zip" From 8a80d2fc8a761f95d53cfc05f9403d899aef5222 Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Sat, 19 Aug 2023 22:49:50 -0700 Subject: [PATCH 11/55] Fixed dollar sign for variable assignment --- .github/workflows/azure-ipam-testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index 7baf6cb..49d0921 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -64,7 +64,7 @@ jobs: Compress-Archive -Pat ./* -DestinationPath /tmp/$archiveName $storage = Get-AzStorageAccount -Name "ipamghactionlogs" -ResourceGroupName "Logging-RG" $context = $storage.Context - @uploadDetails = @{ + $uploadDetails = @{ File = "/tmp/$archiveName" Container = "deploy-logs" Blob = $archiveName From 0f20370b153d7236d293ae3d021e1d36259f62ce Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Sat, 19 Aug 2023 23:51:48 -0700 Subject: [PATCH 12/55] Trying powershell action --- .github/workflows/azure-ipam-testing.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index 49d0921..15a1f6e 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -40,10 +40,12 @@ jobs: uses: actions/checkout@v3 - name: Deploy Azure IPAM + uses: azure/powershell@v1 working-directory: "deploy" id: "pwshScript" - shell: pwsh - run: ./deploy.ps1 -Location "westus3" -UIAppName $Env:IPAM_UI_ID -EngineAppName $Env:IPAM_ENGINE_ID + with: + inlineScript: ./deploy.ps1 -Location "westus3" -UIAppName $Env:IPAM_UI_ID -EngineAppName $Env:IPAM_ENGINE_ID + azPSVersion: "latest" - name: "Output PowerShell Value 'ipamSuffix'" run: echo "${{ steps.pwshScript.outputs.ipamSuffix }}" From 3c7e91c8324bbf63bb433c842390de637365c5b8 Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Sat, 19 Aug 2023 23:53:47 -0700 Subject: [PATCH 13/55] Fixed deploy script path --- .github/workflows/azure-ipam-testing.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index 15a1f6e..bebd847 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -41,10 +41,9 @@ jobs: - name: Deploy Azure IPAM uses: azure/powershell@v1 - working-directory: "deploy" id: "pwshScript" with: - inlineScript: ./deploy.ps1 -Location "westus3" -UIAppName $Env:IPAM_UI_ID -EngineAppName $Env:IPAM_ENGINE_ID + inlineScript: ./deploy/deploy.ps1 -Location "westus3" -UIAppName $Env:IPAM_UI_ID -EngineAppName $Env:IPAM_ENGINE_ID azPSVersion: "latest" - name: "Output PowerShell Value 'ipamSuffix'" From 044407599f87407f3c9c2973ac7aa144bd00777b Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Sun, 20 Aug 2023 00:35:57 -0700 Subject: [PATCH 14/55] Updated remaining PowerShell workflows to azure/powershell action --- .github/workflows/azure-ipam-testing.yml | 43 +++++++++++++----------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index bebd847..e39802e 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -23,10 +23,12 @@ jobs: - run: echo "Job triggered by a ${{ github.event_name }} event from ${{ github.head_ref }} to main." - name: Install Deployment Prerequisites - shell: pwsh - run: | - Set-PSRepository PSGallery -InstallationPolicy Trusted - Install-Module Az, Microsoft.Graph -Force + uses: azure/powershell@v1 + with: + inlineScript: | + Set-PSRepository PSGallery -InstallationPolicy Trusted + Install-Module Az, Microsoft.Graph -Force + azPSVersion: "latest" - name: "Azure Login" uses: azure/login@v1 @@ -57,21 +59,22 @@ jobs: echo "Time: $(date +'%T')" - name: "Upload Logs" - working-directory: "logs" - shell: pwsh - run: | - $dateStamp = (Get-Date -UFormat "%Y-%m-%d_%I-%M-%S_%p").tostring() - $archiveName = "ipam-${dateStamp}.zip" - Compress-Archive -Pat ./* -DestinationPath /tmp/$archiveName - $storage = Get-AzStorageAccount -Name "ipamghactionlogs" -ResourceGroupName "Logging-RG" - $context = $storage.Context - $uploadDetails = @{ - File = "/tmp/$archiveName" - Container = "deploy-logs" - Blob = $archiveName - Context = $context - StandardBlobTier = "Hot" - } - Set-AzStorageBlobContent @uploadDetails + uses: azure/powershell@v1 + with: + inlineScript: | + $dateStamp = (Get-Date -UFormat "%Y-%m-%d_%I-%M-%S_%p").tostring() + $archiveName = "ipam-${dateStamp}.zip" + Compress-Archive -Path ./logs/* -DestinationPath /tmp/$archiveName + $storage = Get-AzStorageAccount -Name "ipamghactionlogs" -ResourceGroupName "Logging-RG" + $context = $storage.Context + $uploadDetails = @{ + File = "/tmp/$archiveName" + Container = "deploy-logs" + Blob = $archiveName + Context = $context + StandardBlobTier = "Hot" + } + Set-AzStorageBlobContent @uploadDetails + azPSVersion: "latest" - run: echo "${{ github.job }} status is ${{ job.status }}." From 472a60b568d72253e6167ce7d342b8413ae4a041 Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Sun, 20 Aug 2023 09:19:10 -0700 Subject: [PATCH 15/55] Switched to Service Principal credentials --- .github/workflows/azure-ipam-testing.yml | 68 ++++++++++++------------ 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index e39802e..6e9ac16 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -1,8 +1,8 @@ name: Azure IPAM Testing -permissions: - id-token: write - contents: read +# permissions: +# id-token: write +# contents: read run-name: Azure IPAM Deployment & Testing @@ -23,30 +23,33 @@ jobs: - run: echo "Job triggered by a ${{ github.event_name }} event from ${{ github.head_ref }} to main." - name: Install Deployment Prerequisites - uses: azure/powershell@v1 - with: - inlineScript: | - Set-PSRepository PSGallery -InstallationPolicy Trusted - Install-Module Az, Microsoft.Graph -Force - azPSVersion: "latest" + shell: pwsh + run: | + Set-PSRepository PSGallery -InstallationPolicy Trusted + Install-Module Az, Microsoft.Graph -Force + + # - name: "Azure Login" + # uses: azure/login@v1 + # with: + # client-id: ${{ secrets.AZURE_CLIENT_ID }} + # subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + # tenant-id: ${{ secrets.AZURE_TENANT_ID }} + # enable-AzPSSession: true - name: "Azure Login" uses: azure/login@v1 with: - client-id: ${{ secrets.AZURE_CLIENT_ID }} - subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - tenant-id: ${{ secrets.AZURE_TENANT_ID }} + creds: ${{ secrets.AZURE_CREDENTIALS }} enable-AzPSSession: true - name: Checkout Azure IPAM Code uses: actions/checkout@v3 - name: Deploy Azure IPAM - uses: azure/powershell@v1 + working-directory: "deploy" id: "pwshScript" - with: - inlineScript: ./deploy/deploy.ps1 -Location "westus3" -UIAppName $Env:IPAM_UI_ID -EngineAppName $Env:IPAM_ENGINE_ID - azPSVersion: "latest" + shell: pwsh + run: ./deploy.ps1 -Location "westus3" -UIAppName $Env:IPAM_UI_ID -EngineAppName $Env:IPAM_ENGINE_ID - name: "Output PowerShell Value 'ipamSuffix'" run: echo "${{ steps.pwshScript.outputs.ipamSuffix }}" @@ -59,22 +62,21 @@ jobs: echo "Time: $(date +'%T')" - name: "Upload Logs" - uses: azure/powershell@v1 - with: - inlineScript: | - $dateStamp = (Get-Date -UFormat "%Y-%m-%d_%I-%M-%S_%p").tostring() - $archiveName = "ipam-${dateStamp}.zip" - Compress-Archive -Path ./logs/* -DestinationPath /tmp/$archiveName - $storage = Get-AzStorageAccount -Name "ipamghactionlogs" -ResourceGroupName "Logging-RG" - $context = $storage.Context - $uploadDetails = @{ - File = "/tmp/$archiveName" - Container = "deploy-logs" - Blob = $archiveName - Context = $context - StandardBlobTier = "Hot" - } - Set-AzStorageBlobContent @uploadDetails - azPSVersion: "latest" + working-directory: "logs" + shell: pwsh + run: | + $dateStamp = (Get-Date -UFormat "%Y-%m-%d_%I-%M-%S_%p").tostring() + $archiveName = "ipam-${dateStamp}.zip" + Compress-Archive -Pat ./* -DestinationPath /tmp/$archiveName + $storage = Get-AzStorageAccount -Name "ipamghactionlogs" -ResourceGroupName "Logging-RG" + $context = $storage.Context + $uploadDetails = @{ + File = "/tmp/$archiveName" + Container = "deploy-logs" + Blob = $archiveName + Context = $context + StandardBlobTier = "Hot" + } + Set-AzStorageBlobContent @uploadDetails - run: echo "${{ github.job }} status is ${{ job.status }}." From bb32aca18f529fe11c829784b14758cbdffc72f7 Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Sun, 20 Aug 2023 22:27:01 -0700 Subject: [PATCH 16/55] Added some spacing --- .github/workflows/azure-ipam-testing.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index 6e9ac16..156966f 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -67,9 +67,12 @@ jobs: run: | $dateStamp = (Get-Date -UFormat "%Y-%m-%d_%I-%M-%S_%p").tostring() $archiveName = "ipam-${dateStamp}.zip" + Compress-Archive -Pat ./* -DestinationPath /tmp/$archiveName + $storage = Get-AzStorageAccount -Name "ipamghactionlogs" -ResourceGroupName "Logging-RG" $context = $storage.Context + $uploadDetails = @{ File = "/tmp/$archiveName" Container = "deploy-logs" @@ -77,6 +80,7 @@ jobs: Context = $context StandardBlobTier = "Hot" } + Set-AzStorageBlobContent @uploadDetails - run: echo "${{ github.job }} status is ${{ job.status }}." From bd6b4819c0f0c0dcde334ca9dc8280f993733f4a Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Sun, 20 Aug 2023 23:15:54 -0700 Subject: [PATCH 17/55] Separated workflow into multiple jobs and added cleanup --- .github/workflows/azure-ipam-testing.yml | 24 ++++++++++++++++++++++++ deploy/deploy.ps1 | 5 ++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index 156966f..ff591c5 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -19,6 +19,8 @@ env: jobs: deploy: runs-on: ubuntu-latest + outputs: + ipamSuffix: ${{ steps.pwshScript.outputs.ipamSuffix }} steps: - run: echo "Job triggered by a ${{ github.event_name }} event from ${{ github.head_ref }} to main." @@ -84,3 +86,25 @@ jobs: Set-AzStorageBlobContent @uploadDetails - run: echo "${{ github.job }} status is ${{ job.status }}." + + sleep: + runs-on: ubuntu-latest + needs: deploy + steps: + - name: "Test Sleepy Time" + run: | + echo "Time: $(date +'%T')" + echo "Sleeping for 30 seconds" + sleep 30 + echo "Time: $(date +'%T')" + + cleanup: + runs-on: ubuntu-latest + needs: [ deploy, sleep ] + steps: + - name : "Cleanup Azure IPAM Deployment" + shell: pwsh + run: | + Remove-AzResourceGroup -Name "ipam-${{ needs.deploy.outputs.ipamSuffix }}" + Remove-AzADApplication -DisplayName $Env:IPAM_UI_ID + Remove-AzADApplication -DisplayName $Env:IPAM_ENGINE_ID diff --git a/deploy/deploy.ps1 b/deploy/deploy.ps1 index 472ff79..48a0cd1 100644 --- a/deploy/deploy.ps1 +++ b/deploy/deploy.ps1 @@ -860,7 +860,7 @@ process { -Tags $Tags ` -ResourceNames $ResourceNames - Write-Output "ipamSuffix=$($deployment.Outputs["suffix"].Value)" >> $Env:GITHUB_OUTPUT + # Write-Output "ipamSuffix=$($deployment.Outputs["suffix"].Value)" >> $Env:GITHUB_OUTPUT } if ($PSCmdlet.ParameterSetName -eq 'Full') { @@ -1027,6 +1027,9 @@ process { finally { Write-Host Stop-Transcript | Out-Null + + Write-Output "ipamSuffix=$($deployment.Outputs["suffix"].Value)" >> $Env:GITHUB_OUTPUT + exit } } From 151a4aa0e527c0a704c17c13ac784d1f91279dc3 Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Sun, 20 Aug 2023 23:45:29 -0700 Subject: [PATCH 18/55] Added login step to cleanup job --- .github/workflows/azure-ipam-testing.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index ff591c5..c62836f 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -56,13 +56,6 @@ jobs: - name: "Output PowerShell Value 'ipamSuffix'" run: echo "${{ steps.pwshScript.outputs.ipamSuffix }}" - - name: "Test Sleepy Time" - run: | - echo "Time: $(date +'%T')" - echo "Sleeping for 30 seconds" - sleep 30 - echo "Time: $(date +'%T')" - - name: "Upload Logs" working-directory: "logs" shell: pwsh @@ -102,6 +95,12 @@ jobs: runs-on: ubuntu-latest needs: [ deploy, sleep ] steps: + - name: "Azure Login" + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + enable-AzPSSession: true + - name : "Cleanup Azure IPAM Deployment" shell: pwsh run: | From a14c6fbef2ae72644333d2201a88b90fb706b193 Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Sun, 20 Aug 2023 23:46:46 -0700 Subject: [PATCH 19/55] Fixed indentation --- .github/workflows/azure-ipam-testing.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index c62836f..51a399b 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -96,10 +96,10 @@ jobs: needs: [ deploy, sleep ] steps: - name: "Azure Login" - uses: azure/login@v1 - with: - creds: ${{ secrets.AZURE_CREDENTIALS }} - enable-AzPSSession: true + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + enable-AzPSSession: true - name : "Cleanup Azure IPAM Deployment" shell: pwsh From 902006fbe169272fefb8a09f90c3c79d8966b4ac Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Mon, 21 Aug 2023 07:07:44 -0700 Subject: [PATCH 20/55] Added dependencies into cleanup job --- .github/workflows/azure-ipam-testing.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index 51a399b..66bd2ae 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -95,6 +95,12 @@ jobs: runs-on: ubuntu-latest needs: [ deploy, sleep ] steps: + - name: Install Deployment Prerequisites + shell: pwsh + run: | + Set-PSRepository PSGallery -InstallationPolicy Trusted + Install-Module Az -Force + - name: "Azure Login" uses: azure/login@v1 with: From cd355a1f4b0367c82aaa87be84cca0bc9bd96784 Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Mon, 21 Aug 2023 07:44:47 -0700 Subject: [PATCH 21/55] Added -Force to App Registration removal in cleanup job --- .github/workflows/azure-ipam-testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index 66bd2ae..318322f 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -110,6 +110,6 @@ jobs: - name : "Cleanup Azure IPAM Deployment" shell: pwsh run: | - Remove-AzResourceGroup -Name "ipam-${{ needs.deploy.outputs.ipamSuffix }}" + Remove-AzResourceGroup -Name "ipam-${{ needs.deploy.outputs.ipamSuffix }}" -Force Remove-AzADApplication -DisplayName $Env:IPAM_UI_ID Remove-AzADApplication -DisplayName $Env:IPAM_ENGINE_ID From bf1d8b1f0138757799aacf57b45d671e9a063aed Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Mon, 21 Aug 2023 08:32:51 -0700 Subject: [PATCH 22/55] Added output for IPAM Resource Group name and referenced it in cleanup job --- .github/workflows/azure-ipam-testing.yml | 2 +- deploy/deploy.ps1 | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index 318322f..99d0686 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -110,6 +110,6 @@ jobs: - name : "Cleanup Azure IPAM Deployment" shell: pwsh run: | - Remove-AzResourceGroup -Name "ipam-${{ needs.deploy.outputs.ipamSuffix }}" -Force + Remove-AzResourceGroup -Name ${{ needs.deploy.outputs.ipamResourceGroup }} -Force Remove-AzADApplication -DisplayName $Env:IPAM_UI_ID Remove-AzADApplication -DisplayName $Env:IPAM_ENGINE_ID diff --git a/deploy/deploy.ps1 b/deploy/deploy.ps1 index 48a0cd1..6ddfd16 100644 --- a/deploy/deploy.ps1 +++ b/deploy/deploy.ps1 @@ -1029,6 +1029,7 @@ process { Stop-Transcript | Out-Null Write-Output "ipamSuffix=$($deployment.Outputs["suffix"].Value)" >> $Env:GITHUB_OUTPUT + Write-Output "ipamResourceGroup=$($deployment.Outputs["resourceGroupName"].Value)" >> $Env:GITHUB_OUTPUT exit } From 98d70d0d1563a2fae01409c53712a3c139d23d7b Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Mon, 21 Aug 2023 09:06:11 -0700 Subject: [PATCH 23/55] Added proper output for Resource Group name to job --- .github/workflows/azure-ipam-testing.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index 99d0686..6d14e64 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -21,6 +21,7 @@ jobs: runs-on: ubuntu-latest outputs: ipamSuffix: ${{ steps.pwshScript.outputs.ipamSuffix }} + ipamResourceGroupName: ${{ steps.pwshScript.outputs.ipamResourceGroup }} steps: - run: echo "Job triggered by a ${{ github.event_name }} event from ${{ github.head_ref }} to main." From 653bc5e71292c3cb002d3feeab3cd49aca7f419c Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Mon, 21 Aug 2023 09:55:07 -0700 Subject: [PATCH 24/55] Fixed output variable name --- .github/workflows/azure-ipam-testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index 6d14e64..d919ee6 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -21,7 +21,7 @@ jobs: runs-on: ubuntu-latest outputs: ipamSuffix: ${{ steps.pwshScript.outputs.ipamSuffix }} - ipamResourceGroupName: ${{ steps.pwshScript.outputs.ipamResourceGroup }} + ipamResourceGroup: ${{ steps.pwshScript.outputs.ipamResourceGroup }} steps: - run: echo "Job triggered by a ${{ github.event_name }} event from ${{ github.head_ref }} to main." From 0742353a8914f2be6c13d1a00256acd9727c6ef4 Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Mon, 21 Aug 2023 10:40:29 -0700 Subject: [PATCH 25/55] Added output and adjusted workflow steps to properly remove App Registrations by ID instead of Name --- .github/workflows/azure-ipam-testing.yml | 6 ++++-- deploy/deploy.ps1 | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index d919ee6..015b153 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -20,6 +20,8 @@ jobs: deploy: runs-on: ubuntu-latest outputs: + ipamUIAppId: ${{ steps.pwshScript.outputs.ipamUIAppId }} + ipamEngineAppId: ${{ steps.pwshScript.outputs.ipamEngineAppId }} ipamSuffix: ${{ steps.pwshScript.outputs.ipamSuffix }} ipamResourceGroup: ${{ steps.pwshScript.outputs.ipamResourceGroup }} steps: @@ -112,5 +114,5 @@ jobs: shell: pwsh run: | Remove-AzResourceGroup -Name ${{ needs.deploy.outputs.ipamResourceGroup }} -Force - Remove-AzADApplication -DisplayName $Env:IPAM_UI_ID - Remove-AzADApplication -DisplayName $Env:IPAM_ENGINE_ID + Get-AzADApplication -ApplicationId ${{ needs.deploy.outputs.ipamUIAppId }} | Remove-AzADApplication + Get-AzADApplication -ApplicationId ${{ needs.deploy.outputs.ipamEngineAppId }} | Remove-AzADApplication diff --git a/deploy/deploy.ps1 b/deploy/deploy.ps1 index 6ddfd16..f6c4a99 100644 --- a/deploy/deploy.ps1 +++ b/deploy/deploy.ps1 @@ -1028,6 +1028,8 @@ process { Write-Host Stop-Transcript | Out-Null + Write-Output "ipamUIAppId=$($appDetails.UIAppId)" >> $Env:GITHUB_OUTPUT + Write-Output "ipamEngineAppId=$($appDetails.EngineAppId)" >> $Env:GITHUB_OUTPUT Write-Output "ipamSuffix=$($deployment.Outputs["suffix"].Value)" >> $Env:GITHUB_OUTPUT Write-Output "ipamResourceGroup=$($deployment.Outputs["resourceGroupName"].Value)" >> $Env:GITHUB_OUTPUT From 30f1cc68adac86bf29df93ff2167a7fad9e2e363 Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Mon, 21 Aug 2023 20:25:46 -0700 Subject: [PATCH 26/55] Added initial Pester test and limited repo clone to specific directories --- .github/workflows/azure-ipam-testing.yml | 42 +++++++- deploy/deploy.ps1 | 1 + tests/azureipam.tests.ps1 | 127 +++++++++++++++++++++++ 3 files changed, 167 insertions(+), 3 deletions(-) create mode 100644 tests/azureipam.tests.ps1 diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index 015b153..cc6aa15 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -20,6 +20,7 @@ jobs: deploy: runs-on: ubuntu-latest outputs: + ipamURL: ${{ steps.pwshScript.outputs.ipamURL }} ipamUIAppId: ${{ steps.pwshScript.outputs.ipamUIAppId }} ipamEngineAppId: ${{ steps.pwshScript.outputs.ipamEngineAppId }} ipamSuffix: ${{ steps.pwshScript.outputs.ipamSuffix }} @@ -31,7 +32,7 @@ jobs: shell: pwsh run: | Set-PSRepository PSGallery -InstallationPolicy Trusted - Install-Module Az, Microsoft.Graph -Force + Install-Module Az, Microsoft.Graph -AllowClobber -Force # - name: "Azure Login" # uses: azure/login@v1 @@ -49,6 +50,9 @@ jobs: - name: Checkout Azure IPAM Code uses: actions/checkout@v3 + with: + sparse-checkout: | + deploy - name: Deploy Azure IPAM working-directory: "deploy" @@ -94,15 +98,47 @@ jobs: sleep 30 echo "Time: $(date +'%T')" - cleanup: + test: runs-on: ubuntu-latest needs: [ deploy, sleep ] + steps: + - name: Install Testing Prerequisites + shell: pwsh + run: | + Set-PSRepository PSGallery -InstallationPolicy Trusted + Install-Module Az, Pester -AllowClobber -Force + + - name: "Azure Login" + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + enable-AzPSSession: true + + - name: Checkout Azure IPAM Code + uses: actions/checkout@v3 + with: + sparse-checkout: | + tests + + - name: Test Azure IPAM via Pester + working-directory: "tests" + env: + IPAM_URL: ${{ needs.deploy.outputs.ipamURL }} + IPAM_ENGINE_APP_ID: ${{ needs.deploy.outputs.ipamEngineAppId }} + shell: pwsh + run: | + Import-Module Pester -PassThru + Invoke-Pester -Output Detailed ./azureipam.tests.ps1 -PassThru + + cleanup: + runs-on: ubuntu-latest + needs: [ deploy, sleep, test ] steps: - name: Install Deployment Prerequisites shell: pwsh run: | Set-PSRepository PSGallery -InstallationPolicy Trusted - Install-Module Az -Force + Install-Module Az -AllowClobber -Force - name: "Azure Login" uses: azure/login@v1 diff --git a/deploy/deploy.ps1 b/deploy/deploy.ps1 index f6c4a99..c7189f9 100644 --- a/deploy/deploy.ps1 +++ b/deploy/deploy.ps1 @@ -1028,6 +1028,7 @@ process { Write-Host Stop-Transcript | Out-Null + Write-Output "ipamURL=https://$($deployment.Outputs["appServiceHostName"].Value)" >> $Env:GITHUB_OUTPUT Write-Output "ipamUIAppId=$($appDetails.UIAppId)" >> $Env:GITHUB_OUTPUT Write-Output "ipamEngineAppId=$($appDetails.EngineAppId)" >> $Env:GITHUB_OUTPUT Write-Output "ipamSuffix=$($deployment.Outputs["suffix"].Value)" >> $Env:GITHUB_OUTPUT diff --git a/tests/azureipam.tests.ps1 b/tests/azureipam.tests.ps1 new file mode 100644 index 0000000..246a8b9 --- /dev/null +++ b/tests/azureipam.tests.ps1 @@ -0,0 +1,127 @@ +BeforeAll { + [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 + + Set-StrictMode -Version Latest + + [string]$baseUrl = "$env:IPAM_URL/api" + [System.Security.SecureString]$accessToken = ConvertTo-SecureString (Get-AzAccessToken -ResourceUrl api://$env:IPAM_ENGINE_APP_ID).Token -AsPlainText + [hashtable]$headers = @{ + "Content-Type" = "application/json" + } + + # GET API Request + Function Get-ApiResource { + [CmdletBinding()] + Param ( + [Parameter(Mandatory=$True, Position=0)] + [string]$resource + ) + + $response = Invoke-RestMethod ` + -Method Get ` + -Authentication Bearer ` + -Token $accessToken ` + -Uri "${baseUrl}${resource}" ` + -Headers $headers + + Write-Output $response + } + + # POST API Request + Function New-ApiResource { + [CmdletBinding()] + Param( + [Parameter(Mandatory=$True, Position=0)] + [string]$resource, + + [Parameter(Mandatory=$True, Position=1)] + [hashtable]$body + ) + + $jsonBody = $body | ConvertTo-Json + $response = Invoke-RestMethod ` + -Method Post ` + -Authentication Bearer ` + -Token $accessToken ` + -Uri "${baseUrl}${resource}" ` + -Headers $headers ` + -Body $jsonBody + + Write-Output $response + } + + # PUT API Request + Function Set-ApiResource { + [CmdletBinding()] + Param( + [Parameter(Mandatory=$True, Position=0)] + [string]$resource, + + [Parameter(Mandatory=$True, Position=1)] + [hashtable]$body + ) + + $jsonBody = $body | ConvertTo-Json + $response = Invoke-RestMethod ` + -Method Put ` + -Authentication Bearer ` + -Token $accessToken ` + -Uri "${baseUrl}${resource}" ` + -Headers $headers ` + -Body $jsonBody + + Write-Output $response + } + + # PATCH API Request + Function Update-ApiResource { + [CmdletBinding()] + Param( + [Parameter(Mandatory=$True, Position=0)] + [string]$resource, + + [Parameter(Mandatory=$True, Position=1)] + [hashtable]$body + ) + + $jsonBody = $body | ConvertTo-Json + $response = Invoke-RestMethod ` + -Method Patch ` + -Authentication Bearer ` + -Token $accessToken ` + -Uri "${baseUrl}${resource}" ` + -Headers $headers ` + -Body $jsonBody + + Write-Output $response + } + + # DELETE API Request + Function Remove-ApiResource { + [CmdletBinding()] + Param( + [Parameter(Mandatory=$True, Position=0)] + [string]$resource + ) + + $response = Invoke-RestMethod ` + -Method Delete ` + -Autjentication Bearer ` + -Token $accessToken ` + -Uri "${baseUrl}${resource}" ` + -Headers $headers + + Write-Output $response + } +} + +Describe 'Get-Posts' { + + It 'Spaces is empty' { + + $spaces = Get-ApiResource '/spaces' + + $spaces | Should -Be $null + } + +} From a966564be49869dda4fb3c77ac0b06a95ff65356 Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Mon, 21 Aug 2023 20:35:58 -0700 Subject: [PATCH 27/55] Cleanup workflow and add proper names to jobs --- .github/workflows/azure-ipam-testing.yml | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index cc6aa15..d689a7a 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -18,6 +18,7 @@ env: jobs: deploy: + name: Deploy Azure IPAM runs-on: ubuntu-latest outputs: ipamURL: ${{ steps.pwshScript.outputs.ipamURL }} @@ -42,7 +43,7 @@ jobs: # tenant-id: ${{ secrets.AZURE_TENANT_ID }} # enable-AzPSSession: true - - name: "Azure Login" + - name: Azure Login uses: azure/login@v1 with: creds: ${{ secrets.AZURE_CREDENTIALS }} @@ -64,7 +65,7 @@ jobs: run: echo "${{ steps.pwshScript.outputs.ipamSuffix }}" - name: "Upload Logs" - working-directory: "logs" + working-directory: logs shell: pwsh run: | $dateStamp = (Get-Date -UFormat "%Y-%m-%d_%I-%M-%S_%p").tostring() @@ -88,10 +89,11 @@ jobs: - run: echo "${{ github.job }} status is ${{ job.status }}." sleep: + name: Sleep for 5 Minutes runs-on: ubuntu-latest needs: deploy steps: - - name: "Test Sleepy Time" + - name: Test Sleepy Time run: | echo "Time: $(date +'%T')" echo "Sleeping for 30 seconds" @@ -99,6 +101,7 @@ jobs: echo "Time: $(date +'%T')" test: + name: Test Azure IPAM via Pester runs-on: ubuntu-latest needs: [ deploy, sleep ] steps: @@ -108,7 +111,7 @@ jobs: Set-PSRepository PSGallery -InstallationPolicy Trusted Install-Module Az, Pester -AllowClobber -Force - - name: "Azure Login" + - name: Azure Login uses: azure/login@v1 with: creds: ${{ secrets.AZURE_CREDENTIALS }} @@ -121,7 +124,7 @@ jobs: tests - name: Test Azure IPAM via Pester - working-directory: "tests" + working-directory: tests env: IPAM_URL: ${{ needs.deploy.outputs.ipamURL }} IPAM_ENGINE_APP_ID: ${{ needs.deploy.outputs.ipamEngineAppId }} @@ -129,8 +132,9 @@ jobs: run: | Import-Module Pester -PassThru Invoke-Pester -Output Detailed ./azureipam.tests.ps1 -PassThru - + cleanup: + name: Cleanup Azure IPAM Deployment runs-on: ubuntu-latest needs: [ deploy, sleep, test ] steps: @@ -140,13 +144,13 @@ jobs: Set-PSRepository PSGallery -InstallationPolicy Trusted Install-Module Az -AllowClobber -Force - - name: "Azure Login" + - name: Azure Login uses: azure/login@v1 with: creds: ${{ secrets.AZURE_CREDENTIALS }} enable-AzPSSession: true - - name : "Cleanup Azure IPAM Deployment" + - name : Cleanup Azure IPAM Deployment shell: pwsh run: | Remove-AzResourceGroup -Name ${{ needs.deploy.outputs.ipamResourceGroup }} -Force From 34d4e2db9b14c746ef9a4242c6085ddb6d08f5f1 Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Mon, 21 Aug 2023 20:41:36 -0700 Subject: [PATCH 28/55] Fixed indentation --- .github/workflows/azure-ipam-testing.yml | 42 ++++++++++++------------ 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index d689a7a..907274e 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -111,27 +111,27 @@ jobs: Set-PSRepository PSGallery -InstallationPolicy Trusted Install-Module Az, Pester -AllowClobber -Force - - name: Azure Login - uses: azure/login@v1 - with: - creds: ${{ secrets.AZURE_CREDENTIALS }} - enable-AzPSSession: true - - - name: Checkout Azure IPAM Code - uses: actions/checkout@v3 - with: - sparse-checkout: | - tests - - - name: Test Azure IPAM via Pester - working-directory: tests - env: - IPAM_URL: ${{ needs.deploy.outputs.ipamURL }} - IPAM_ENGINE_APP_ID: ${{ needs.deploy.outputs.ipamEngineAppId }} - shell: pwsh - run: | - Import-Module Pester -PassThru - Invoke-Pester -Output Detailed ./azureipam.tests.ps1 -PassThru + - name: Azure Login + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + enable-AzPSSession: true + + - name: Checkout Azure IPAM Code + uses: actions/checkout@v3 + with: + sparse-checkout: | + tests + + - name: Invoke Pester Tests + working-directory: tests + env: + IPAM_URL: ${{ needs.deploy.outputs.ipamURL }} + IPAM_ENGINE_APP_ID: ${{ needs.deploy.outputs.ipamEngineAppId }} + shell: pwsh + run: | + Import-Module Pester -PassThru + Invoke-Pester -Output Detailed ./azureipam.tests.ps1 -PassThru cleanup: name: Cleanup Azure IPAM Deployment From e6f93cb906e4ea5fe0f4068b208155955a8b1d7b Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Wed, 23 Aug 2023 15:15:53 -0700 Subject: [PATCH 29/55] Added additional tests and fixed small bug --- .github/workflows/azure-ipam-testing.yml | 1 + engine/app/routers/space.py | 2 +- tests/azureipam.tests.ps1 | 321 ++++++++++++++++++++++- 3 files changed, 315 insertions(+), 9 deletions(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index 907274e..11997ca 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -126,6 +126,7 @@ jobs: - name: Invoke Pester Tests working-directory: tests env: + IPAM_RESOURCE_GROUP: ${{ needs.deploy.outputs.ipamResourceGroup }} IPAM_URL: ${{ needs.deploy.outputs.ipamURL }} IPAM_ENGINE_APP_ID: ${{ needs.deploy.outputs.ipamEngineAppId }} shell: pwsh diff --git a/engine/app/routers/space.py b/engine/app/routers/space.py index fa311d1..5132382 100644 --- a/engine/app/routers/space.py +++ b/engine/app/routers/space.py @@ -1134,7 +1134,7 @@ async def create_block_net( resv_cidrs = list(x['cidr'] for x in target_block['resv'] if not x['settledOn']) block_net_cidrs += resv_cidrs - ext_cidrs = list(x['cidr'] for x in target_block['externala']) + ext_cidrs = list(x['cidr'] for x in target_block['externals']) block_net_cidrs += ext_cidrs for v in target_block['vnets']: diff --git a/tests/azureipam.tests.ps1 b/tests/azureipam.tests.ps1 index 246a8b9..6c51bd3 100644 --- a/tests/azureipam.tests.ps1 +++ b/tests/azureipam.tests.ps1 @@ -58,7 +58,7 @@ BeforeAll { [string]$resource, [Parameter(Mandatory=$True, Position=1)] - [hashtable]$body + [object[]]$body ) $jsonBody = $body | ConvertTo-Json @@ -81,7 +81,7 @@ BeforeAll { [string]$resource, [Parameter(Mandatory=$True, Position=1)] - [hashtable]$body + [hashtable[]]$body ) $jsonBody = $body | ConvertTo-Json @@ -101,27 +101,332 @@ BeforeAll { [CmdletBinding()] Param( [Parameter(Mandatory=$True, Position=0)] - [string]$resource + [string]$resource, + + [Parameter(Mandatory=$False, Position=1)] + [string[]]$body ) + $jsonBody = $body | ConvertTo-Json -AsArray $response = Invoke-RestMethod ` -Method Delete ` - -Autjentication Bearer ` + -Authentication Bearer ` -Token $accessToken ` -Uri "${baseUrl}${resource}" ` - -Headers $headers + -Headers $headers ` + -Body $jsonBody Write-Output $response } } -Describe 'Get-Posts' { +Context 'Spaces' { + It 'Verify No Spaces Exist' { + + $spaces = Get-ApiResource '/spaces' + + $spaces | Should -Be $null + } + + It 'Create Two Spaces' { + $spaceA = @{ + name = 'TestSpace01' + desc = 'Test Space 1' + } - It 'Spaces is empty' { + $spaceB = @{ + name = 'TestSpace02' + desc = 'Test Space 2' + } + + New-ApiResource '/spaces' $spaceA + New-ApiResource '/spaces' $spaceB $spaces = Get-ApiResource '/spaces' - $spaces | Should -Be $null + $spaces.Count | Should -Be 2 + $spaces.Name -contains 'TestSpace01' | Should -Be $true + $spaces.Name -contains 'TestSpace02' | Should -Be $true + } + + It 'Delete a Space' { + Remove-ApiResource '/spaces/TestSpace02' + + $spaces = Get-ApiResource '/spaces' + + $spaces.Count | Should -Be 1 + $spaces.Name -contains 'TestSpace01' | Should -Be $true + $spaces.Name -contains 'TestSpace02' | Should -Be $false + } + + It 'Update a Space' { + $update = @( + @{ + op = 'replace' + path = '/name' + value = 'TestSpaceA' + } + @{ + op = 'replace' + path = '/desc' + value = 'Test Space A' + } + ) + + Update-ApiResource '/spaces/TestSpace01' $update + + $spaces = Get-ApiResource '/spaces' + + $spaces.Count | Should -Be 1 + $spaces[0].Name -eq 'TestSpaceA' | Should -Be $true + $spaces[0].Desc -eq 'Test Space A' | Should -Be $true } +} + +Context 'Blocks' { + It 'Verify No Blocks Exist' { + + $blocks = Get-ApiResource '/spaces/TestSpaceA/blocks' + + $blocks | Should -Be $null + } + + It 'Create Two Blocks' { + $blockA = @{ + name = 'TestBlock01' + cidr = '10.0.0.0/16' + } + + $blockB = @{ + name = 'TestBlock02' + cidr = '192.168.0.0/24' + } + + New-ApiResource '/spaces/TestSpaceA/blocks' $blockA + New-ApiResource '/spaces/TestSpaceA/blocks' $blockB + + $blocks = Get-ApiResource '/spaces/TestSpaceA/blocks' + + $blocks.Count | Should -Be 2 + $blocks.Name -contains 'TestBlock01' | Should -Be $true + $blocks.Name -contains 'TestBlock02' | Should -Be $true + } + + It 'Delete a Block' { + Remove-ApiResource '/spaces/TestSpaceA/blocks/TestBlock02' + + $blocks = Get-ApiResource '/spaces/TestSpaceA/blocks' + + $blocks.Count | Should -Be 1 + $blocks.Name -contains 'TestBlock01' | Should -Be $true + $blocks.Name -contains 'TestBlock02' | Should -Be $false + } + + It 'Update a Block' { + $update = @( + @{ + op = 'replace' + path = '/name' + value = 'TestBlockA' + } + @{ + op = 'replace' + path = '/cidr' + value = '10.1.0.0/16' + } + ) + + Update-ApiResource '/spaces/TestSpaceA/blocks/TestBlock01' $update + + $blocks = Get-ApiResource '/spaces/TestSpaceA/blocks' + + $blocks.Count | Should -Be 1 + $blocks[0].Name -eq 'TestBlockA' | Should -Be $true + $blocks[0].Cidr -eq '10.1.0.0/16' | Should -Be $true + } +} + +Context 'Networks' { + It 'Verify No Networks Exist in Block' { + + $networks = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/networks' + + $networks | Should -Be $null + } + + It 'Add a Virtual Network to a Block' { + $script:newNetA = New-AzVirtualNetwork ` + -Name 'TestVNet01' ` + -ResourceGroupName $env:IPAM_RESOURCE_GROUP ` + -Location 'westus3' ` + -AddressPrefix '10.1.0.0/24' + + Start-Sleep -Seconds 60 + + $body = @{ + id = $script:newNetA.Id + } + $block = New-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/networks' $body + + $($block.vnets | Select-Object -ExpandProperty id) -contains $script:newNetA.Id | Should -Be $true + } + + It 'Replace Block Virtual Networks' { + $script:newNetB = New-AzVirtualNetwork ` + -Name 'TestVNet02' ` + -ResourceGroupName $env:IPAM_RESOURCE_GROUP ` + -Location 'westus3' ` + -AddressPrefix '10.1.1.0/24' + + Start-Sleep -Seconds 60 + + $body = @( + $script:newNetA.Id + $script:newNetB.Id + ) + + Set-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/networks' $body + $networks = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/networks' + + $($networks | Select-Object -ExpandProperty id) -contains $script:newNetA.Id | Should -Be $true + $($networks | Select-Object -ExpandProperty id) -contains $script:newNetB.Id | Should -Be $true + } + + It 'Delete Block Virtual Network' { + $body = @( + $script:newNetB.Id + ) + + Remove-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/networks' $body + $networks = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/networks' + + $($networks | Select-Object -ExpandProperty id) -contains $script:newNetA.Id | Should -Be $true + $($networks | Select-Object -ExpandProperty id) -contains $script:newNetB.Id | Should -Be $false + } +} + +Context 'External Networks' { + It 'Verify No External Networks Exist in Block' { + + $externals = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/externals' + + $externals | Should -Be $null + } + + It 'Add an External Network to Block' { + $script:externalA = @{ + name = "ExternalNetA" + desc = "External Network A" + cidr = "10.1.1.0/24" + } + + New-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/externals' $script:externalA + $externals = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/externals' + + $externals.Name -contains "ExternalNetA" | Should -Be $true + } + + It 'Replace Block External Networks' { + $script:externalB = @{ + name = "ExternalNetB" + desc = "External Network B" + cidr = "10.1.2.0/24" + } + + $script:externalC = @{ + name = "ExternalNetC" + desc = "External Network C" + cidr = "10.1.3.0/24" + } + + $body = @( + $script:externalA + $script:externalB + $script:externalC + ) + + Set-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/externals' $body + $externals = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/externals' + + $externals.Name -contains "ExternalNetA" | Should -Be $true + $externals.Name -contains "ExternalNetB" | Should -Be $true + } + + It 'Delete Block External Network' { + $body = @( + $script:externalC.name + ) + + Remove-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/externals' $body + $externals = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/externals' + + $externals.Name -contains "ExternalNetA" | Should -Be $true + $externals.Name -contains "ExternalNetB" | Should -Be $true + $externals.Name -contains "ExternalNetC" | Should -Be $false + } + + It 'Get Specific Block External Network' { + + $external = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/externals/ExternalNetB' + + $external.Name | Should -Be "ExternalNetB" + $external.Desc | Should -Be "External Network B" + $external.Cidr | Should -Be "10.1.2.0/24" + } + + It 'Delete Specific Block External Network' { + + Remove-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/externals/ExternalNetB' + $externals = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/externals' + + $externals.Name -contains "ExternalNetA" | Should -Be $true + $externals.Name -contains "ExternalNetB" | Should -Be $false + $externals.Name -contains "ExternalNetC" | Should -Be $false + } +} + +Context 'Reservations' { + It 'Verify No Reservations Exist in Block' { + + $reservations = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/reservations' + + $reservations | Should -Be $null + } + + It 'Create Block Reservation' { + $body = @{ + size = 24 + desc = "Test Reservation A" + } + + $script:reservationA = New-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/reservations' $body + $reservations = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/reservations' + + $reservations.Count | Should -Be 1 + $reservations[0].Space -eq "TestSpaceA" | Should -Be $true + $reservations[0].Block -eq "TestBlockA" | Should -Be $true + $reservations[0].Desc -eq "Test Reservation A" | Should -Be $true + $reservations[0].Cidr -eq "10.1.2.0/24" | Should -Be $true + $reservations[0].SettledOn -eq $null | Should -Be $true + } + + It 'Import Virtual Network via Reservation ID' { + $script:newNetC = New-AzVirtualNetwork ` + -Name 'TestVNet03' ` + -ResourceGroupName $env:IPAM_RESOURCE_GROUP ` + -Location 'westus3' ` + -AddressPrefix $script:reservationA.Cidr ` + -Tag $script:reservationA.Tag + + Start-Sleep -Seconds 180 + + $networks = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/networks' + $reservations = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/reservations' + + $($networks | Select-Object -ExpandProperty id) -contains $script:newNetA.Id | Should -Be $true + $($networks | Select-Object -ExpandProperty id) -contains $script:newNetC.Id | Should -Be $true + $reservations[0].SettledOn -eq $null | Should -Be $false + $reservations[0].Status -eq "fulfilled" | Should -Be $true + } } From 55ccc0dacc8fa207fca05deaf4a174d8d98f8b4c Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Wed, 23 Aug 2023 15:59:59 -0700 Subject: [PATCH 30/55] Fixed Tag format when creating a new Virtual Network --- tests/azureipam.tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/azureipam.tests.ps1 b/tests/azureipam.tests.ps1 index 6c51bd3..17477d0 100644 --- a/tests/azureipam.tests.ps1 +++ b/tests/azureipam.tests.ps1 @@ -417,7 +417,7 @@ Context 'Reservations' { -ResourceGroupName $env:IPAM_RESOURCE_GROUP ` -Location 'westus3' ` -AddressPrefix $script:reservationA.Cidr ` - -Tag $script:reservationA.Tag + -Tag @{ "X-IPAM-RES-ID" = $script:reservationA.Id } Start-Sleep -Seconds 180 From 93d9bbd134f0cdbff95c4d3e6bc065940a073e40 Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Wed, 23 Aug 2023 16:40:43 -0700 Subject: [PATCH 31/55] Added query parameters to get back settled reservations --- tests/azureipam.tests.ps1 | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/azureipam.tests.ps1 b/tests/azureipam.tests.ps1 index 17477d0..4178ae4 100644 --- a/tests/azureipam.tests.ps1 +++ b/tests/azureipam.tests.ps1 @@ -14,7 +14,10 @@ BeforeAll { [CmdletBinding()] Param ( [Parameter(Mandatory=$True, Position=0)] - [string]$resource + [string]$resource, + + [Parameter(Mandatory=$False, Position=1)] + [hashtable]$query ) $response = Invoke-RestMethod ` @@ -22,7 +25,8 @@ BeforeAll { -Authentication Bearer ` -Token $accessToken ` -Uri "${baseUrl}${resource}" ` - -Headers $headers + -Headers $headers ` + -Body $query Write-Output $response } @@ -421,11 +425,16 @@ Context 'Reservations' { Start-Sleep -Seconds 180 + $query = @{ + settled = $true + } + $networks = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/networks' - $reservations = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/reservations' + $reservations = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/reservations' $query $($networks | Select-Object -ExpandProperty id) -contains $script:newNetA.Id | Should -Be $true $($networks | Select-Object -ExpandProperty id) -contains $script:newNetC.Id | Should -Be $true + $reservations | Should -Not -Be $null $reservations[0].SettledOn -eq $null | Should -Be $false $reservations[0].Status -eq "fulfilled" | Should -Be $true } From 977b3b0022de9781885e96153250cc40bbfdc5a0 Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Wed, 23 Aug 2023 20:46:35 -0700 Subject: [PATCH 32/55] Added container build process and step to update the Docker-Compose YAML --- .github/workflows/azure-ipam-testing.yml | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index 11997ca..bb993bd 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -13,6 +13,7 @@ on: branches: [ main ] env: + ACR_NAME: azureipamtest IPAM_UI_ID: ipam-ui-${{ github.run_id }}-${{ github.run_attempt }} IPAM_ENGINE_ID: ipam-engine-${{ github.run_id }}-${{ github.run_attempt }} @@ -33,7 +34,7 @@ jobs: shell: pwsh run: | Set-PSRepository PSGallery -InstallationPolicy Trusted - Install-Module Az, Microsoft.Graph -AllowClobber -Force + Install-Module Az, Microsoft.Graph, powershell-yaml -AllowClobber -Force # - name: "Azure Login" # uses: azure/login@v1 @@ -54,6 +55,26 @@ jobs: with: sparse-checkout: | deploy + engine + ui + lb + + - name: Build Azure IPAM Containers + run | + az acr build -r $ACR_NAME -t ipam-engine:${{ github.run_id }}-${{ github.run_attempt }} -f ./engine/Dockerfile.deb ./engine + az acr build -r $ACR_NAME -t ipam-func:${{ github.run_id }}-${{ github.run_attempt }} -f ./engine/Dockerfile.func ./engine + az acr build -r $ACR_NAME -t ipam-ui:${{ github.run_id }}-${{ github.run_attempt }} -f ./ui/Dockerfile.deb ./ui + az acr build -r $ACR_NAME -t ipam-lb:${{ github.run_id }}-${{ github.run_attempt }} -f ./lb/Dockerfile ./lb + + - name: Update Docker-Compose YAML + shell: pwsh + run | + $composeFile = Get-Content -Path ./docker-compose.prod.yml + $composeYaml = $composeFile | ConvertFrom-Yaml + $composeYaml['services']['ipam-ui'].image = "$env:ACR_NAME.azurecr.io/ipam-ui:${{ github.run_id }}-${{ github.run_attempt }}" + $composeYaml['services']['ipam-engine'].image = "$env:ACR_NAME".azurecr.io/ipam-engine:${{ github.run_id }}-${{ github.run_attempt }}" + $composeYaml['services']['nginx-proxy'].image = "$env:ACR_NAME".azurecr.io/ipam-lb:${{ github.run_id }}-${{ github.run_attempt }}" + $composeYaml | ConvertTo-Yaml | Out-File -Path ./docker-compose-prod.yml - name: Deploy Azure IPAM working-directory: "deploy" From 78745c43f8ae2c62299aef5633b37adcef0c535c Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Wed, 23 Aug 2023 20:47:33 -0700 Subject: [PATCH 33/55] Added missing colon --- .github/workflows/azure-ipam-testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index bb993bd..4bdf34e 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -60,7 +60,7 @@ jobs: lb - name: Build Azure IPAM Containers - run | + run: | az acr build -r $ACR_NAME -t ipam-engine:${{ github.run_id }}-${{ github.run_attempt }} -f ./engine/Dockerfile.deb ./engine az acr build -r $ACR_NAME -t ipam-func:${{ github.run_id }}-${{ github.run_attempt }} -f ./engine/Dockerfile.func ./engine az acr build -r $ACR_NAME -t ipam-ui:${{ github.run_id }}-${{ github.run_attempt }} -f ./ui/Dockerfile.deb ./ui From 99657d789ce75acc45c91dbb6f7968dc00714607 Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Wed, 23 Aug 2023 20:48:11 -0700 Subject: [PATCH 34/55] Added another missing colon --- .github/workflows/azure-ipam-testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index 4bdf34e..41e5e12 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -68,7 +68,7 @@ jobs: - name: Update Docker-Compose YAML shell: pwsh - run | + run: | $composeFile = Get-Content -Path ./docker-compose.prod.yml $composeYaml = $composeFile | ConvertFrom-Yaml $composeYaml['services']['ipam-ui'].image = "$env:ACR_NAME.azurecr.io/ipam-ui:${{ github.run_id }}-${{ github.run_attempt }}" From 83892df987a8a5d8e54ea12ac3f5ce56f76e95cf Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Wed, 23 Aug 2023 21:08:37 -0700 Subject: [PATCH 35/55] Added additional cleanup for engine permissions and containers --- .github/workflows/azure-ipam-testing.yml | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index 41e5e12..6a161ce 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -72,8 +72,8 @@ jobs: $composeFile = Get-Content -Path ./docker-compose.prod.yml $composeYaml = $composeFile | ConvertFrom-Yaml $composeYaml['services']['ipam-ui'].image = "$env:ACR_NAME.azurecr.io/ipam-ui:${{ github.run_id }}-${{ github.run_attempt }}" - $composeYaml['services']['ipam-engine'].image = "$env:ACR_NAME".azurecr.io/ipam-engine:${{ github.run_id }}-${{ github.run_attempt }}" - $composeYaml['services']['nginx-proxy'].image = "$env:ACR_NAME".azurecr.io/ipam-lb:${{ github.run_id }}-${{ github.run_attempt }}" + $composeYaml['services']['ipam-engine'].image = "$env:ACR_NAME.azurecr.io/ipam-engine:${{ github.run_id }}-${{ github.run_attempt }}" + $composeYaml['services']['nginx-proxy'].image = "$env:ACR_NAME.azurecr.io/ipam-lb:${{ github.run_id }}-${{ github.run_attempt }}" $composeYaml | ConvertTo-Yaml | Out-File -Path ./docker-compose-prod.yml - name: Deploy Azure IPAM @@ -175,6 +175,18 @@ jobs: - name : Cleanup Azure IPAM Deployment shell: pwsh run: | + $tenantId = (Get-AzContext).Tenant.Id + $scope = "/providers/Microsoft.Management/managementGroups/$TenantId" + $uiApp = Get-AzADApplication -ApplicationId ${{ needs.deploy.outputs.ipamUIAppId }} + $engineApp = Get-AzADApplication -ApplicationId ${{ needs.deploy.outputs.ipamEngineAppId }} Remove-AzResourceGroup -Name ${{ needs.deploy.outputs.ipamResourceGroup }} -Force - Get-AzADApplication -ApplicationId ${{ needs.deploy.outputs.ipamUIAppId }} | Remove-AzADApplication - Get-AzADApplication -ApplicationId ${{ needs.deploy.outputs.ipamEngineAppId }} | Remove-AzADApplication + Remove-AzRoleAssignment -ObjectId $engineApp.ObjectId -Scope $scope -RoleDefinitionName Reader + $uiApp | Remove-AzADApplication + $engineApp | Remove-AzADApplication + + - name: "Remove Azure IPAM Containers" + run: | + az acr repository delete -r $ACR_NAME -n ipam-engine + az acr repository delete -r $ACR_NAME -n ipam-func + az acr repository delete -r $ACR_NAME -n ipam-ui + az acr repository delete -r $ACR_NAME -n ipam-lb From ee414bf8d850d718ba9bc4ffa988bf3be425b423 Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Wed, 23 Aug 2023 21:51:07 -0700 Subject: [PATCH 36/55] Added additional output for troubleshooting --- .github/workflows/azure-ipam-testing.yml | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index 6a161ce..fc5b328 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -69,11 +69,20 @@ jobs: - name: Update Docker-Compose YAML shell: pwsh run: | + $uiContainer = "$env:ACR_NAME.azurecr.io/ipam-ui:${{ github.run_id }}-${{ github.run_attempt }}" + $engineContainer = "$env:ACR_NAME.azurecr.io/ipam-engine:${{ github.run_id }}-${{ github.run_attempt }}" + $lbContainer = "$env:ACR_NAME.azurecr.io/ipam-lb:${{ github.run_id }}-${{ github.run_attempt }}" + $composeFile = Get-Content -Path ./docker-compose.prod.yml $composeYaml = $composeFile | ConvertFrom-Yaml - $composeYaml['services']['ipam-ui'].image = "$env:ACR_NAME.azurecr.io/ipam-ui:${{ github.run_id }}-${{ github.run_attempt }}" - $composeYaml['services']['ipam-engine'].image = "$env:ACR_NAME.azurecr.io/ipam-engine:${{ github.run_id }}-${{ github.run_attempt }}" - $composeYaml['services']['nginx-proxy'].image = "$env:ACR_NAME.azurecr.io/ipam-lb:${{ github.run_id }}-${{ github.run_attempt }}" + + $composeYaml['services']['ipam-ui'].image = $uiContainer + $composeYaml['services']['ipam-engine'].image = $engineContainer + $composeYaml['services']['nginx-proxy'].image = $lbContainer + + Get-ChildItem + $composeYaml | ConvertTo-Yaml + $composeYaml | ConvertTo-Yaml | Out-File -Path ./docker-compose-prod.yml - name: Deploy Azure IPAM @@ -177,10 +186,13 @@ jobs: run: | $tenantId = (Get-AzContext).Tenant.Id $scope = "/providers/Microsoft.Management/managementGroups/$TenantId" + $uiApp = Get-AzADApplication -ApplicationId ${{ needs.deploy.outputs.ipamUIAppId }} $engineApp = Get-AzADApplication -ApplicationId ${{ needs.deploy.outputs.ipamEngineAppId }} + Remove-AzResourceGroup -Name ${{ needs.deploy.outputs.ipamResourceGroup }} -Force Remove-AzRoleAssignment -ObjectId $engineApp.ObjectId -Scope $scope -RoleDefinitionName Reader + $uiApp | Remove-AzADApplication $engineApp | Remove-AzADApplication From 7fbf614302f8d2fe1a3129da4bd73dcbb6bb427a Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Wed, 23 Aug 2023 22:37:47 -0700 Subject: [PATCH 37/55] Trying different directory --- .github/workflows/azure-ipam-testing.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index fc5b328..5e7ab84 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -67,6 +67,7 @@ jobs: az acr build -r $ACR_NAME -t ipam-lb:${{ github.run_id }}-${{ github.run_attempt }} -f ./lb/Dockerfile ./lb - name: Update Docker-Compose YAML + working-directory: . shell: pwsh run: | $uiContainer = "$env:ACR_NAME.azurecr.io/ipam-ui:${{ github.run_id }}-${{ github.run_attempt }}" @@ -86,7 +87,7 @@ jobs: $composeYaml | ConvertTo-Yaml | Out-File -Path ./docker-compose-prod.yml - name: Deploy Azure IPAM - working-directory: "deploy" + working-directory: deploy id: "pwshScript" shell: pwsh run: ./deploy.ps1 -Location "westus3" -UIAppName $Env:IPAM_UI_ID -EngineAppName $Env:IPAM_ENGINE_ID From a86a181bb840cda2aa3ffb367542b850f41654f9 Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Wed, 23 Aug 2023 23:32:24 -0700 Subject: [PATCH 38/55] Added additional output for troubleshooting --- .github/workflows/azure-ipam-testing.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index 5e7ab84..d88faef 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -67,7 +67,6 @@ jobs: az acr build -r $ACR_NAME -t ipam-lb:${{ github.run_id }}-${{ github.run_attempt }} -f ./lb/Dockerfile ./lb - name: Update Docker-Compose YAML - working-directory: . shell: pwsh run: | $uiContainer = "$env:ACR_NAME.azurecr.io/ipam-ui:${{ github.run_id }}-${{ github.run_attempt }}" @@ -81,7 +80,7 @@ jobs: $composeYaml['services']['ipam-engine'].image = $engineContainer $composeYaml['services']['nginx-proxy'].image = $lbContainer - Get-ChildItem + Get-ChildItem | Select-Object Name $composeYaml | ConvertTo-Yaml $composeYaml | ConvertTo-Yaml | Out-File -Path ./docker-compose-prod.yml From e39cf2704d3aecccb7704024063af4421aff70ff Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Thu, 24 Aug 2023 08:00:00 -0700 Subject: [PATCH 39/55] Added additional output for troubleshooting --- .github/workflows/azure-ipam-testing.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index d88faef..3c2aa9a 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -80,10 +80,15 @@ jobs: $composeYaml['services']['ipam-engine'].image = $engineContainer $composeYaml['services']['nginx-proxy'].image = $lbContainer + $composeYaml | ConvertTo-Yaml | Out-File -FilePath ./docker-compose-prod.yml + + Write-Host "-----------------------------------" Get-ChildItem | Select-Object Name + Write-Host "-----------------------------------" $composeYaml | ConvertTo-Yaml - - $composeYaml | ConvertTo-Yaml | Out-File -Path ./docker-compose-prod.yml + Write-Host "-----------------------------------" + Get-Content -Path ./docker-compose.prod.yml + Write-Host "-----------------------------------" - name: Deploy Azure IPAM working-directory: deploy From 59417535df49d8a61a91c02112ea66a2ec854f48 Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Thu, 24 Aug 2023 09:27:31 -0700 Subject: [PATCH 40/55] Identified issue, fixed two identified code bugs --- .github/workflows/azure-ipam-testing.yml | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index 3c2aa9a..d7f95dc 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -80,15 +80,7 @@ jobs: $composeYaml['services']['ipam-engine'].image = $engineContainer $composeYaml['services']['nginx-proxy'].image = $lbContainer - $composeYaml | ConvertTo-Yaml | Out-File -FilePath ./docker-compose-prod.yml - - Write-Host "-----------------------------------" - Get-ChildItem | Select-Object Name - Write-Host "-----------------------------------" - $composeYaml | ConvertTo-Yaml - Write-Host "-----------------------------------" - Get-Content -Path ./docker-compose.prod.yml - Write-Host "-----------------------------------" + $composeYaml | ConvertTo-Yaml | Out-File -FilePath ./docker-compose.prod.yml - name: Deploy Azure IPAM working-directory: deploy @@ -196,7 +188,7 @@ jobs: $engineApp = Get-AzADApplication -ApplicationId ${{ needs.deploy.outputs.ipamEngineAppId }} Remove-AzResourceGroup -Name ${{ needs.deploy.outputs.ipamResourceGroup }} -Force - Remove-AzRoleAssignment -ObjectId $engineApp.ObjectId -Scope $scope -RoleDefinitionName Reader + Remove-AzRoleAssignment -ObjectId $engineApp.Id -Scope $scope -RoleDefinitionName Reader $uiApp | Remove-AzADApplication $engineApp | Remove-AzADApplication From 1add0d3c0aa71b84e5cd9ec95ac258c1b8456399 Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Thu, 24 Aug 2023 10:30:39 -0700 Subject: [PATCH 41/55] Added additional output for troubleshooting --- .github/workflows/azure-ipam-testing.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index d7f95dc..cb9531b 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -187,6 +187,11 @@ jobs: $uiApp = Get-AzADApplication -ApplicationId ${{ needs.deploy.outputs.ipamUIAppId }} $engineApp = Get-AzADApplication -ApplicationId ${{ needs.deploy.outputs.ipamEngineAppId }} + Write-Host "-------------------------------" + Write-Host "Scope: $scope" + $engineApp | ConvertTo-Json + Write-Host "-------------------------------" + Remove-AzResourceGroup -Name ${{ needs.deploy.outputs.ipamResourceGroup }} -Force Remove-AzRoleAssignment -ObjectId $engineApp.Id -Scope $scope -RoleDefinitionName Reader From f554626be115ba74f45ee5d423990b6fc9b966e9 Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Thu, 24 Aug 2023 14:57:22 -0700 Subject: [PATCH 42/55] Updated commands to properly remove Service Principal permissions and remove the SPN --- .github/workflows/azure-ipam-testing.yml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index cb9531b..599df21 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -182,19 +182,16 @@ jobs: shell: pwsh run: | $tenantId = (Get-AzContext).Tenant.Id - $scope = "/providers/Microsoft.Management/managementGroups/$TenantId" + $scope = "/providers/Microsoft.Management/managementGroups/$tenantId" $uiApp = Get-AzADApplication -ApplicationId ${{ needs.deploy.outputs.ipamUIAppId }} $engineApp = Get-AzADApplication -ApplicationId ${{ needs.deploy.outputs.ipamEngineAppId }} - - Write-Host "-------------------------------" - Write-Host "Scope: $scope" - $engineApp | ConvertTo-Json - Write-Host "-------------------------------" + $engineSpn = Get-AzADServicePrincipal -ApplicationId ${{ needs.deploy.outputs.ipamEngineAppId }} Remove-AzResourceGroup -Name ${{ needs.deploy.outputs.ipamResourceGroup }} -Force - Remove-AzRoleAssignment -ObjectId $engineApp.Id -Scope $scope -RoleDefinitionName Reader + Remove-AzRoleAssignment -ObjectId $engineSpn.Id -Scope $scope -RoleDefinitionName Reader + $engineSpn | Remove-AzADServicePrincipal $uiApp | Remove-AzADApplication $engineApp | Remove-AzADApplication From 9f6f3c246cc90da7cf5b9c17618e69d7aca21c22 Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Thu, 24 Aug 2023 17:53:19 -0700 Subject: [PATCH 43/55] Fixed commands to remove ACR registries --- .github/workflows/azure-ipam-testing.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index 599df21..67d6877 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -197,7 +197,7 @@ jobs: - name: "Remove Azure IPAM Containers" run: | - az acr repository delete -r $ACR_NAME -n ipam-engine - az acr repository delete -r $ACR_NAME -n ipam-func - az acr repository delete -r $ACR_NAME -n ipam-ui - az acr repository delete -r $ACR_NAME -n ipam-lb + az acr repository delete --name $ACR_NAME --repository ipam-engine + az acr repository delete --name $ACR_NAME --repository ipam-func + az acr repository delete --name $ACR_NAME --repository ipam-ui + az acr repository delete --name $ACR_NAME --repository ipam-lb From 4243ca9e1f9c483782b65b7d3f1e72ef3671f02d Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Thu, 24 Aug 2023 19:22:52 -0700 Subject: [PATCH 44/55] Added --yes flag --- .github/workflows/azure-ipam-testing.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index 67d6877..96ef7bd 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -197,7 +197,7 @@ jobs: - name: "Remove Azure IPAM Containers" run: | - az acr repository delete --name $ACR_NAME --repository ipam-engine - az acr repository delete --name $ACR_NAME --repository ipam-func - az acr repository delete --name $ACR_NAME --repository ipam-ui - az acr repository delete --name $ACR_NAME --repository ipam-lb + az acr repository delete --name $ACR_NAME --repository ipam-engine --yes + az acr repository delete --name $ACR_NAME --repository ipam-func --yes + az acr repository delete --name $ACR_NAME --repository ipam-ui --yes + az acr repository delete --name $ACR_NAME --repository ipam-lb --yes From 2e61eea2cdbaeb109b3d46cee1e8b6acee503356 Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Sat, 26 Aug 2023 11:36:29 -0700 Subject: [PATCH 45/55] Added status code to API responses and set Pester to skip remaining tests upon failure --- .github/workflows/azure-ipam-testing.yml | 30 +++++++--- tests/azureipam.tests.ps1 | 72 +++++++++++++----------- 2 files changed, 62 insertions(+), 40 deletions(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index 96ef7bd..2b76c5c 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -113,14 +113,12 @@ jobs: Set-AzStorageBlobContent @uploadDetails - - run: echo "${{ github.job }} status is ${{ job.status }}." - sleep: - name: Sleep for 5 Minutes + name: Sleep for 1 Minute runs-on: ubuntu-latest needs: deploy steps: - - name: Test Sleepy Time + - name: Sleep to Allow Azure IPAM Startup run: | echo "Time: $(date +'%T')" echo "Sleeping for 30 seconds" @@ -159,7 +157,21 @@ jobs: shell: pwsh run: | Import-Module Pester -PassThru - Invoke-Pester -Output Detailed ./azureipam.tests.ps1 -PassThru + + $pesterSettings = @{ + Run = @{ + Path = "./azureipam.tests.ps1" + PassThru = $true + SkipRemainingOnFailure = "Run" + } + Output = @{ + Verbosity = "Detailed" + } + } + + $pesterConfig = New-PesterConfiguration -Hashtable $pesterSettings + + Invoke-Pester -Configuration $pesterConfig cleanup: name: Cleanup Azure IPAM Deployment @@ -178,7 +190,12 @@ jobs: creds: ${{ secrets.AZURE_CREDENTIALS }} enable-AzPSSession: true - - name : Cleanup Azure IPAM Deployment + - name : Remove Azure IPAM Resources + shell: pwsh + run: | + Remove-AzResourceGroup -Name ${{ needs.deploy.outputs.ipamResourceGroup }} -Force + + - name : Remove Azure IPAM Identities shell: pwsh run: | $tenantId = (Get-AzContext).Tenant.Id @@ -188,7 +205,6 @@ jobs: $engineApp = Get-AzADApplication -ApplicationId ${{ needs.deploy.outputs.ipamEngineAppId }} $engineSpn = Get-AzADServicePrincipal -ApplicationId ${{ needs.deploy.outputs.ipamEngineAppId }} - Remove-AzResourceGroup -Name ${{ needs.deploy.outputs.ipamResourceGroup }} -Force Remove-AzRoleAssignment -ObjectId $engineSpn.Id -Scope $scope -RoleDefinitionName Reader $engineSpn | Remove-AzADServicePrincipal diff --git a/tests/azureipam.tests.ps1 b/tests/azureipam.tests.ps1 index 4178ae4..dcdd94a 100644 --- a/tests/azureipam.tests.ps1 +++ b/tests/azureipam.tests.ps1 @@ -26,9 +26,10 @@ BeforeAll { -Token $accessToken ` -Uri "${baseUrl}${resource}" ` -Headers $headers ` - -Body $query + -Body $query ` + -StatusCodeVariable status - Write-Output $response + Write-Output $response, $status } # POST API Request @@ -49,9 +50,10 @@ BeforeAll { -Token $accessToken ` -Uri "${baseUrl}${resource}" ` -Headers $headers ` - -Body $jsonBody + -Body $jsonBody ` + -StatusCodeVariable status - Write-Output $response + Write-Output $response, $status } # PUT API Request @@ -72,9 +74,10 @@ BeforeAll { -Token $accessToken ` -Uri "${baseUrl}${resource}" ` -Headers $headers ` - -Body $jsonBody + -Body $jsonBody ` + -StatusCodeVariable status - Write-Output $response + Write-Output $response, $status } # PATCH API Request @@ -95,9 +98,10 @@ BeforeAll { -Token $accessToken ` -Uri "${baseUrl}${resource}" ` -Headers $headers ` - -Body $jsonBody + -Body $jsonBody ` + -StatusCodeVariable status - Write-Output $response + Write-Output $response, $status } # DELETE API Request @@ -118,16 +122,17 @@ BeforeAll { -Token $accessToken ` -Uri "${baseUrl}${resource}" ` -Headers $headers ` - -Body $jsonBody + -Body $jsonBody ` + -StatusCodeVariable status - Write-Output $response + Write-Output $response, $status } } Context 'Spaces' { It 'Verify No Spaces Exist' { - $spaces = Get-ApiResource '/spaces' + $spaces, $spacesStatus = Get-ApiResource '/spaces' $spaces | Should -Be $null } @@ -146,7 +151,7 @@ Context 'Spaces' { New-ApiResource '/spaces' $spaceA New-ApiResource '/spaces' $spaceB - $spaces = Get-ApiResource '/spaces' + $spaces, $spacesStatus = Get-ApiResource '/spaces' $spaces.Count | Should -Be 2 $spaces.Name -contains 'TestSpace01' | Should -Be $true @@ -156,7 +161,7 @@ Context 'Spaces' { It 'Delete a Space' { Remove-ApiResource '/spaces/TestSpace02' - $spaces = Get-ApiResource '/spaces' + $spaces, $spacesStatus = Get-ApiResource '/spaces' $spaces.Count | Should -Be 1 $spaces.Name -contains 'TestSpace01' | Should -Be $true @@ -179,7 +184,7 @@ Context 'Spaces' { Update-ApiResource '/spaces/TestSpace01' $update - $spaces = Get-ApiResource '/spaces' + $spaces, $spacesStatus = Get-ApiResource '/spaces' $spaces.Count | Should -Be 1 $spaces[0].Name -eq 'TestSpaceA' | Should -Be $true @@ -190,7 +195,7 @@ Context 'Spaces' { Context 'Blocks' { It 'Verify No Blocks Exist' { - $blocks = Get-ApiResource '/spaces/TestSpaceA/blocks' + $blocks, $blocksStatus = Get-ApiResource '/spaces/TestSpaceA/blocks' $blocks | Should -Be $null } @@ -209,7 +214,7 @@ Context 'Blocks' { New-ApiResource '/spaces/TestSpaceA/blocks' $blockA New-ApiResource '/spaces/TestSpaceA/blocks' $blockB - $blocks = Get-ApiResource '/spaces/TestSpaceA/blocks' + $blocks, $blocksStatus = Get-ApiResource '/spaces/TestSpaceA/blocks' $blocks.Count | Should -Be 2 $blocks.Name -contains 'TestBlock01' | Should -Be $true @@ -219,7 +224,7 @@ Context 'Blocks' { It 'Delete a Block' { Remove-ApiResource '/spaces/TestSpaceA/blocks/TestBlock02' - $blocks = Get-ApiResource '/spaces/TestSpaceA/blocks' + $blocks, $blocksStatus = Get-ApiResource '/spaces/TestSpaceA/blocks' $blocks.Count | Should -Be 1 $blocks.Name -contains 'TestBlock01' | Should -Be $true @@ -242,7 +247,7 @@ Context 'Blocks' { Update-ApiResource '/spaces/TestSpaceA/blocks/TestBlock01' $update - $blocks = Get-ApiResource '/spaces/TestSpaceA/blocks' + $blocks, $blocksStatus = Get-ApiResource '/spaces/TestSpaceA/blocks' $blocks.Count | Should -Be 1 $blocks[0].Name -eq 'TestBlockA' | Should -Be $true @@ -253,7 +258,7 @@ Context 'Blocks' { Context 'Networks' { It 'Verify No Networks Exist in Block' { - $networks = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/networks' + $networks, $networksStatus = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/networks' $networks | Should -Be $null } @@ -271,7 +276,8 @@ Context 'Networks' { id = $script:newNetA.Id } - $block = New-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/networks' $body + ### FIX THIS ### + $block, $blockStatus = New-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/networks' $body $($block.vnets | Select-Object -ExpandProperty id) -contains $script:newNetA.Id | Should -Be $true } @@ -291,7 +297,7 @@ Context 'Networks' { ) Set-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/networks' $body - $networks = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/networks' + $networks, $networksStatus = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/networks' $($networks | Select-Object -ExpandProperty id) -contains $script:newNetA.Id | Should -Be $true $($networks | Select-Object -ExpandProperty id) -contains $script:newNetB.Id | Should -Be $true @@ -303,7 +309,7 @@ Context 'Networks' { ) Remove-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/networks' $body - $networks = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/networks' + $networks, $networksStatus = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/networks' $($networks | Select-Object -ExpandProperty id) -contains $script:newNetA.Id | Should -Be $true $($networks | Select-Object -ExpandProperty id) -contains $script:newNetB.Id | Should -Be $false @@ -313,7 +319,7 @@ Context 'Networks' { Context 'External Networks' { It 'Verify No External Networks Exist in Block' { - $externals = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/externals' + $externals, $externalsStatus = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/externals' $externals | Should -Be $null } @@ -326,7 +332,7 @@ Context 'External Networks' { } New-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/externals' $script:externalA - $externals = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/externals' + $externals, $externalsStatus = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/externals' $externals.Name -contains "ExternalNetA" | Should -Be $true } @@ -351,7 +357,7 @@ Context 'External Networks' { ) Set-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/externals' $body - $externals = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/externals' + $externals, $externalsStatus = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/externals' $externals.Name -contains "ExternalNetA" | Should -Be $true $externals.Name -contains "ExternalNetB" | Should -Be $true @@ -363,7 +369,7 @@ Context 'External Networks' { ) Remove-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/externals' $body - $externals = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/externals' + $externals, $externalsStatus = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/externals' $externals.Name -contains "ExternalNetA" | Should -Be $true $externals.Name -contains "ExternalNetB" | Should -Be $true @@ -372,7 +378,7 @@ Context 'External Networks' { It 'Get Specific Block External Network' { - $external = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/externals/ExternalNetB' + $external, $externalStatus = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/externals/ExternalNetB' $external.Name | Should -Be "ExternalNetB" $external.Desc | Should -Be "External Network B" @@ -382,7 +388,7 @@ Context 'External Networks' { It 'Delete Specific Block External Network' { Remove-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/externals/ExternalNetB' - $externals = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/externals' + $externals, $externalsStatus = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/externals' $externals.Name -contains "ExternalNetA" | Should -Be $true $externals.Name -contains "ExternalNetB" | Should -Be $false @@ -393,7 +399,7 @@ Context 'External Networks' { Context 'Reservations' { It 'Verify No Reservations Exist in Block' { - $reservations = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/reservations' + $reservations, $reservationsStatus = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/reservations' $reservations | Should -Be $null } @@ -404,8 +410,8 @@ Context 'Reservations' { desc = "Test Reservation A" } - $script:reservationA = New-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/reservations' $body - $reservations = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/reservations' + $script:reservationA, $reservationAStatus = New-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/reservations' $body + $reservations, $reservationsStatus = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/reservations' $reservations.Count | Should -Be 1 $reservations[0].Space -eq "TestSpaceA" | Should -Be $true @@ -429,8 +435,8 @@ Context 'Reservations' { settled = $true } - $networks = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/networks' - $reservations = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/reservations' $query + $networks, $networksStatus = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/networks' + $reservations, $reservationsStatus = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/reservations' $query $($networks | Select-Object -ExpandProperty id) -contains $script:newNetA.Id | Should -Be $true $($networks | Select-Object -ExpandProperty id) -contains $script:newNetC.Id | Should -Be $true From efc0ba9ad537cee8e601fb4c5a45beeb0bb7dbef Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Sun, 27 Aug 2023 22:52:35 -0700 Subject: [PATCH 46/55] Slight tweaks and renamed some workflow jobs --- .github/workflows/azure-ipam-testing.yml | 28 ++++++++++++------------ tests/azureipam.tests.ps1 | 11 ++++++++-- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index 2b76c5c..598f405 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -113,20 +113,20 @@ jobs: Set-AzStorageBlobContent @uploadDetails - sleep: - name: Sleep for 1 Minute - runs-on: ubuntu-latest - needs: deploy - steps: - - name: Sleep to Allow Azure IPAM Startup - run: | - echo "Time: $(date +'%T')" - echo "Sleeping for 30 seconds" - sleep 30 - echo "Time: $(date +'%T')" + # sleep: + # name: Sleep for 1 Minute + # runs-on: ubuntu-latest + # needs: deploy + # steps: + # - name: Sleep to Allow Azure IPAM Startup + # run: | + # echo "Time: $(date +'%T')" + # echo "Sleeping for 30 seconds" + # sleep 30 + # echo "Time: $(date +'%T')" test: - name: Test Azure IPAM via Pester + name: Test Azure IPAM runs-on: ubuntu-latest needs: [ deploy, sleep ] steps: @@ -148,7 +148,7 @@ jobs: sparse-checkout: | tests - - name: Invoke Pester Tests + - name: Test Azure IPAM w/ Pester working-directory: tests env: IPAM_RESOURCE_GROUP: ${{ needs.deploy.outputs.ipamResourceGroup }} @@ -174,7 +174,7 @@ jobs: Invoke-Pester -Configuration $pesterConfig cleanup: - name: Cleanup Azure IPAM Deployment + name: Cleanup Azure IPAM runs-on: ubuntu-latest needs: [ deploy, sleep, test ] steps: diff --git a/tests/azureipam.tests.ps1 b/tests/azureipam.tests.ps1 index dcdd94a..625e5ea 100644 --- a/tests/azureipam.tests.ps1 +++ b/tests/azureipam.tests.ps1 @@ -276,8 +276,9 @@ Context 'Networks' { id = $script:newNetA.Id } - ### FIX THIS ### - $block, $blockStatus = New-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/networks' $body + New-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/networks' $body + + $block, $blockStatus = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA' $($block.vnets | Select-Object -ExpandProperty id) -contains $script:newNetA.Id | Should -Be $true } @@ -297,6 +298,7 @@ Context 'Networks' { ) Set-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/networks' $body + $networks, $networksStatus = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/networks' $($networks | Select-Object -ExpandProperty id) -contains $script:newNetA.Id | Should -Be $true @@ -309,6 +311,7 @@ Context 'Networks' { ) Remove-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/networks' $body + $networks, $networksStatus = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/networks' $($networks | Select-Object -ExpandProperty id) -contains $script:newNetA.Id | Should -Be $true @@ -332,6 +335,7 @@ Context 'External Networks' { } New-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/externals' $script:externalA + $externals, $externalsStatus = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/externals' $externals.Name -contains "ExternalNetA" | Should -Be $true @@ -357,6 +361,7 @@ Context 'External Networks' { ) Set-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/externals' $body + $externals, $externalsStatus = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/externals' $externals.Name -contains "ExternalNetA" | Should -Be $true @@ -369,6 +374,7 @@ Context 'External Networks' { ) Remove-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/externals' $body + $externals, $externalsStatus = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/externals' $externals.Name -contains "ExternalNetA" | Should -Be $true @@ -388,6 +394,7 @@ Context 'External Networks' { It 'Delete Specific Block External Network' { Remove-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/externals/ExternalNetB' + $externals, $externalsStatus = Get-ApiResource '/spaces/TestSpaceA/blocks/TestBlockA/externals' $externals.Name -contains "ExternalNetA" | Should -Be $true From 88f7aa1f8c8290a285da340f22fbeaf7656bdf9b Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Sun, 27 Aug 2023 22:53:50 -0700 Subject: [PATCH 47/55] Fixed workflow dependencies --- .github/workflows/azure-ipam-testing.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index 598f405..fe55a7a 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -128,7 +128,7 @@ jobs: test: name: Test Azure IPAM runs-on: ubuntu-latest - needs: [ deploy, sleep ] + needs: [ deploy ] steps: - name: Install Testing Prerequisites shell: pwsh @@ -176,7 +176,7 @@ jobs: cleanup: name: Cleanup Azure IPAM runs-on: ubuntu-latest - needs: [ deploy, sleep, test ] + needs: [ deploy, test ] steps: - name: Install Deployment Prerequisites shell: pwsh From d84afa8309dcefda16e0f2351beed9b2c0742e6b Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Mon, 28 Aug 2023 08:17:11 -0700 Subject: [PATCH 48/55] Moved some hard-coded values to repository variables --- .github/workflows/azure-ipam-testing.yml | 56 ++++++++++-------------- 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index fe55a7a..c43627e 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -1,9 +1,5 @@ name: Azure IPAM Testing -# permissions: -# id-token: write -# contents: read - run-name: Azure IPAM Deployment & Testing on: @@ -13,7 +9,7 @@ on: branches: [ main ] env: - ACR_NAME: azureipamtest + ACR_NAME: ${{ vars.IPAM_TEST_ACR }} IPAM_UI_ID: ipam-ui-${{ github.run_id }}-${{ github.run_attempt }} IPAM_ENGINE_ID: ipam-engine-${{ github.run_id }}-${{ github.run_attempt }} @@ -36,14 +32,6 @@ jobs: Set-PSRepository PSGallery -InstallationPolicy Trusted Install-Module Az, Microsoft.Graph, powershell-yaml -AllowClobber -Force - # - name: "Azure Login" - # uses: azure/login@v1 - # with: - # client-id: ${{ secrets.AZURE_CLIENT_ID }} - # subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - # tenant-id: ${{ secrets.AZURE_TENANT_ID }} - # enable-AzPSSession: true - - name: Azure Login uses: azure/login@v1 with: @@ -86,26 +74,28 @@ jobs: working-directory: deploy id: "pwshScript" shell: pwsh - run: ./deploy.ps1 -Location "westus3" -UIAppName $Env:IPAM_UI_ID -EngineAppName $Env:IPAM_ENGINE_ID - - - name: "Output PowerShell Value 'ipamSuffix'" - run: echo "${{ steps.pwshScript.outputs.ipamSuffix }}" + run: ./deploy.ps1 -Location "westus3" -UIAppName $env:IPAM_UI_ID -EngineAppName $env:IPAM_ENGINE_ID - name: "Upload Logs" working-directory: logs + env: + AZURE_IPAM_SUFFIX: ${{ steps.pwshScript.outputs.ipamSuffix }} + STORAGE_ACCT_RG: ${{ vars.LOGGING_STORAGE_RG }} + STORAGE_ACCT_NAME: ${{ vars.LOGGING_STORAGE_NAME }} + STORAGE_ACCT_CTR: ${{ vars.LOGGING_STORAGE_CTR }} shell: pwsh run: | $dateStamp = (Get-Date -UFormat "%Y-%m-%d_%I-%M-%S_%p").tostring() - $archiveName = "ipam-${dateStamp}.zip" + $archiveName = "ipam-${env:AZURE_IPAM_SUFFIX}-${dateStamp}.zip" - Compress-Archive -Pat ./* -DestinationPath /tmp/$archiveName + Compress-Archive -Path ./* -DestinationPath /tmp/$archiveName - $storage = Get-AzStorageAccount -Name "ipamghactionlogs" -ResourceGroupName "Logging-RG" + $storage = Get-AzStorageAccount -Name $env:STORAGE_ACCT_NAME -ResourceGroupName $env:STORAGE_ACCT_RG $context = $storage.Context $uploadDetails = @{ File = "/tmp/$archiveName" - Container = "deploy-logs" + Container = $env:STORAGE_ACCT_CTR Blob = $archiveName Context = $context StandardBlobTier = "Hot" @@ -113,17 +103,19 @@ jobs: Set-AzStorageBlobContent @uploadDetails - # sleep: - # name: Sleep for 1 Minute - # runs-on: ubuntu-latest - # needs: deploy - # steps: - # - name: Sleep to Allow Azure IPAM Startup - # run: | - # echo "Time: $(date +'%T')" - # echo "Sleeping for 30 seconds" - # sleep 30 - # echo "Time: $(date +'%T')" + Write-Output "ipamLogFile=$archiveName" >> $Env:GITHUB_OUTPUT + + - name: "Output Azure IPAM Deployment Details" + shell: pwsh + run: | + Write-Host "Deployment Details:" + Write-Host "-------------------" + Write-Host "IPAM Suffix: ${{ steps.pwshScript.outputs.ipamSuffix }}" + Write-Host "IPAM UI App ID: ${{ steps.pwshScript.outputs.ipamUIAppId }}" + Write-Host "IPAM Engine App ID: ${{ steps.pwshScript.outputs.ipamEngineAppId }}" + Write-Host "IPAM URL: ${{ steps.pwshScript.outputs.ipamURL }}" + Write-Host "IPAM Log File: ${{ steps.pwshScript.outputs.ipamLogFile }}}}" + Write-Host "-------------------" test: name: Test Azure IPAM From 35f4a5163c4aef2bd297863a565b4d5dc123bb8a Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Mon, 28 Aug 2023 10:18:02 -0700 Subject: [PATCH 49/55] Added additonal output to logs file --- .github/workflows/azure-ipam-testing.yml | 28 +++++++++++++++--------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index c43627e..c4559ff 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -85,8 +85,20 @@ jobs: STORAGE_ACCT_CTR: ${{ vars.LOGGING_STORAGE_CTR }} shell: pwsh run: | - $dateStamp = (Get-Date -UFormat "%Y-%m-%d_%I-%M-%S_%p").tostring() - $archiveName = "ipam-${env:AZURE_IPAM_SUFFIX}-${dateStamp}.zip" + # $dateStamp = (Get-Date -UFormat "%Y-%m-%d_%I-%M-%S_%p").tostring() + # $archiveName = "ipam-${env:AZURE_IPAM_SUFFIX}-${dateStamp}.zip" + $archiveName = "ipam-${{ github.run_id }}(${{ github.run_attempt }})-${dateStamp}.zip" + + $logDetails = @{ + GITHUB_RUN_ID = "${{ github.run_id }}/${{ github.run_attempt }}" + IPAM_SUFFIX = "${{ steps.pwshScript.outputs.ipamSuffix }}" + IPAM_UI_APP_ID = "${{ steps.pwshScript.outputs.ipamUIAppId }}" + IPAM_ENGINE_APP_ID = "${{ steps.pwshScript.outputs.ipamEngineAppId }}" + IPAM_URL = "${{ steps.pwshScript.outputs.ipamURL }}" + IPAM_LOG_FILE = "${{ steps.pwshScript.outputs.ipamLogFile }}" + } + + $logDetails | ConvertTo-Json | Out-File -FilePath ./deploymentDetails.json Compress-Archive -Path ./* -DestinationPath /tmp/$archiveName @@ -103,19 +115,15 @@ jobs: Set-AzStorageBlobContent @uploadDetails - Write-Output "ipamLogFile=$archiveName" >> $Env:GITHUB_OUTPUT + Write-Output "deployDetails=$logDetails" >> $Env:GITHUB_OUTPUT - name: "Output Azure IPAM Deployment Details" + env: + DEPLOYMENT_DETAILS: ${{ steps.pwshScript.outputs.deployDetails }} shell: pwsh run: | Write-Host "Deployment Details:" - Write-Host "-------------------" - Write-Host "IPAM Suffix: ${{ steps.pwshScript.outputs.ipamSuffix }}" - Write-Host "IPAM UI App ID: ${{ steps.pwshScript.outputs.ipamUIAppId }}" - Write-Host "IPAM Engine App ID: ${{ steps.pwshScript.outputs.ipamEngineAppId }}" - Write-Host "IPAM URL: ${{ steps.pwshScript.outputs.ipamURL }}" - Write-Host "IPAM Log File: ${{ steps.pwshScript.outputs.ipamLogFile }}}}" - Write-Host "-------------------" + $env:DEPLOYMENT_DETAILS test: name: Test Azure IPAM From 2700d6203a117915a733e44cca722eae963514ba Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Mon, 28 Aug 2023 11:55:17 -0700 Subject: [PATCH 50/55] Adjusted logfile name and deployment details output --- .github/workflows/azure-ipam-testing.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index c4559ff..dc10673 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -85,7 +85,7 @@ jobs: STORAGE_ACCT_CTR: ${{ vars.LOGGING_STORAGE_CTR }} shell: pwsh run: | - # $dateStamp = (Get-Date -UFormat "%Y-%m-%d_%I-%M-%S_%p").tostring() + $dateStamp = (Get-Date -UFormat "%Y-%m-%d_%I-%M-%S_%p").tostring() # $archiveName = "ipam-${env:AZURE_IPAM_SUFFIX}-${dateStamp}.zip" $archiveName = "ipam-${{ github.run_id }}(${{ github.run_attempt }})-${dateStamp}.zip" @@ -123,7 +123,7 @@ jobs: shell: pwsh run: | Write-Host "Deployment Details:" - $env:DEPLOYMENT_DETAILS + Write-Output $env:DEPLOYMENT_DETAILS test: name: Test Azure IPAM From 1130e2be3d2d53892cd3178fd000f4b258c4479e Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Mon, 28 Aug 2023 14:21:47 -0700 Subject: [PATCH 51/55] Fixed log output issues --- .github/workflows/azure-ipam-testing.yml | 32 +++++++++++++----------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index dc10673..3e952d0 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -18,11 +18,11 @@ jobs: name: Deploy Azure IPAM runs-on: ubuntu-latest outputs: - ipamURL: ${{ steps.pwshScript.outputs.ipamURL }} - ipamUIAppId: ${{ steps.pwshScript.outputs.ipamUIAppId }} - ipamEngineAppId: ${{ steps.pwshScript.outputs.ipamEngineAppId }} - ipamSuffix: ${{ steps.pwshScript.outputs.ipamSuffix }} - ipamResourceGroup: ${{ steps.pwshScript.outputs.ipamResourceGroup }} + ipamURL: ${{ steps.deployScript.outputs.ipamURL }} + ipamUIAppId: ${{ steps.deployScript.outputs.ipamUIAppId }} + ipamEngineAppId: ${{ steps.deployScript.outputs.ipamEngineAppId }} + ipamSuffix: ${{ steps.deployScript.outputs.ipamSuffix }} + ipamResourceGroup: ${{ steps.deployScript.outputs.ipamResourceGroup }} steps: - run: echo "Job triggered by a ${{ github.event_name }} event from ${{ github.head_ref }} to main." @@ -72,14 +72,15 @@ jobs: - name: Deploy Azure IPAM working-directory: deploy - id: "pwshScript" + id: deployScript shell: pwsh run: ./deploy.ps1 -Location "westus3" -UIAppName $env:IPAM_UI_ID -EngineAppName $env:IPAM_ENGINE_ID - name: "Upload Logs" working-directory: logs + id: uploadLogs env: - AZURE_IPAM_SUFFIX: ${{ steps.pwshScript.outputs.ipamSuffix }} + AZURE_IPAM_SUFFIX: ${{ steps.deployScript.outputs.ipamSuffix }} STORAGE_ACCT_RG: ${{ vars.LOGGING_STORAGE_RG }} STORAGE_ACCT_NAME: ${{ vars.LOGGING_STORAGE_NAME }} STORAGE_ACCT_CTR: ${{ vars.LOGGING_STORAGE_CTR }} @@ -91,11 +92,11 @@ jobs: $logDetails = @{ GITHUB_RUN_ID = "${{ github.run_id }}/${{ github.run_attempt }}" - IPAM_SUFFIX = "${{ steps.pwshScript.outputs.ipamSuffix }}" - IPAM_UI_APP_ID = "${{ steps.pwshScript.outputs.ipamUIAppId }}" - IPAM_ENGINE_APP_ID = "${{ steps.pwshScript.outputs.ipamEngineAppId }}" - IPAM_URL = "${{ steps.pwshScript.outputs.ipamURL }}" - IPAM_LOG_FILE = "${{ steps.pwshScript.outputs.ipamLogFile }}" + IPAM_SUFFIX = "${{ steps.deployScript.outputs.ipamSuffix }}" + IPAM_UI_APP_ID = "${{ steps.deployScript.outputs.ipamUIAppId }}" + IPAM_ENGINE_APP_ID = "${{ steps.deployScript.outputs.ipamEngineAppId }}" + IPAM_URL = "${{ steps.deployScript.outputs.ipamURL }}" + IPAM_LOG_FILE = "${{ steps.deployScript.outputs.ipamLogFile }}" } $logDetails | ConvertTo-Json | Out-File -FilePath ./deploymentDetails.json @@ -119,11 +120,14 @@ jobs: - name: "Output Azure IPAM Deployment Details" env: - DEPLOYMENT_DETAILS: ${{ steps.pwshScript.outputs.deployDetails }} + DEPLOYMENT_DETAILS: ${{ steps.uploadLogs.outputs.deployDetails }} shell: pwsh run: | + Write-Host "-------------------" Write-Host "Deployment Details:" - Write-Output $env:DEPLOYMENT_DETAILS + Write-Host "-------------------" + Write-Host ($env:DEPLOYMENT_DETAILS | Format-Table | Out-String) -NoNewline + Write-Host "-------------------" test: name: Test Azure IPAM From 8061ddc98e037987b320030783a45f7f5baa3091 Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Mon, 28 Aug 2023 15:51:06 -0700 Subject: [PATCH 52/55] Passing deployment details as JSON --- .github/workflows/azure-ipam-testing.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index 3e952d0..60b6c00 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -116,7 +116,7 @@ jobs: Set-AzStorageBlobContent @uploadDetails - Write-Output "deployDetails=$logDetails" >> $Env:GITHUB_OUTPUT + Write-Output "deployDetails=$($logDetails | ConvertTo-Json)" >> $Env:GITHUB_OUTPUT - name: "Output Azure IPAM Deployment Details" env: @@ -126,7 +126,7 @@ jobs: Write-Host "-------------------" Write-Host "Deployment Details:" Write-Host "-------------------" - Write-Host ($env:DEPLOYMENT_DETAILS | Format-Table | Out-String) -NoNewline + Write-Host ($env:DEPLOYMENT_DETAILS | ConvertFrom-Json -AsHashtable | Format-Table | Out-String) -NoNewline Write-Host "-------------------" test: From 56fb34ce423be027760791f3b318a306e80d5575 Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Mon, 28 Aug 2023 20:46:38 -0700 Subject: [PATCH 53/55] Further refined logging output --- .github/workflows/azure-ipam-testing.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index 60b6c00..f4d56fb 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -86,17 +86,18 @@ jobs: STORAGE_ACCT_CTR: ${{ vars.LOGGING_STORAGE_CTR }} shell: pwsh run: | - $dateStamp = (Get-Date -UFormat "%Y-%m-%d_%I-%M-%S_%p").tostring() + # $dateStamp = (Get-Date -UFormat "%Y-%m-%d_%I-%M-%S_%p").tostring() # $archiveName = "ipam-${env:AZURE_IPAM_SUFFIX}-${dateStamp}.zip" - $archiveName = "ipam-${{ github.run_id }}(${{ github.run_attempt }})-${dateStamp}.zip" + # $archiveName = "ipam-${{ github.run_id }}(${{ github.run_attempt }})-${dateStamp}.zip" + $archiveName = "IPAM-RUN(${{ github.run_id }})-ATTEMPT(${{ github.run_attempt }})-SUFFIX($env:AZURE_IPAM_SUFFIX).zip" $logDetails = @{ - GITHUB_RUN_ID = "${{ github.run_id }}/${{ github.run_attempt }}" + GITHUB_RUN_ID = "${{ github.run_id }}(${{ github.run_attempt }})" IPAM_SUFFIX = "${{ steps.deployScript.outputs.ipamSuffix }}" IPAM_UI_APP_ID = "${{ steps.deployScript.outputs.ipamUIAppId }}" IPAM_ENGINE_APP_ID = "${{ steps.deployScript.outputs.ipamEngineAppId }}" IPAM_URL = "${{ steps.deployScript.outputs.ipamURL }}" - IPAM_LOG_FILE = "${{ steps.deployScript.outputs.ipamLogFile }}" + IPAM_LOG_FILE = $archiveName } $logDetails | ConvertTo-Json | Out-File -FilePath ./deploymentDetails.json From 96c460429c6228f12205de2cc6b1b5af8ce21579 Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Mon, 28 Aug 2023 21:27:34 -0700 Subject: [PATCH 54/55] Fixed deployment details output issues --- .github/workflows/azure-ipam-testing.yml | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index f4d56fb..27f4510 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -91,17 +91,6 @@ jobs: # $archiveName = "ipam-${{ github.run_id }}(${{ github.run_attempt }})-${dateStamp}.zip" $archiveName = "IPAM-RUN(${{ github.run_id }})-ATTEMPT(${{ github.run_attempt }})-SUFFIX($env:AZURE_IPAM_SUFFIX).zip" - $logDetails = @{ - GITHUB_RUN_ID = "${{ github.run_id }}(${{ github.run_attempt }})" - IPAM_SUFFIX = "${{ steps.deployScript.outputs.ipamSuffix }}" - IPAM_UI_APP_ID = "${{ steps.deployScript.outputs.ipamUIAppId }}" - IPAM_ENGINE_APP_ID = "${{ steps.deployScript.outputs.ipamEngineAppId }}" - IPAM_URL = "${{ steps.deployScript.outputs.ipamURL }}" - IPAM_LOG_FILE = $archiveName - } - - $logDetails | ConvertTo-Json | Out-File -FilePath ./deploymentDetails.json - Compress-Archive -Path ./* -DestinationPath /tmp/$archiveName $storage = Get-AzStorageAccount -Name $env:STORAGE_ACCT_NAME -ResourceGroupName $env:STORAGE_ACCT_RG @@ -117,17 +106,26 @@ jobs: Set-AzStorageBlobContent @uploadDetails - Write-Output "deployDetails=$($logDetails | ConvertTo-Json)" >> $Env:GITHUB_OUTPUT + Write-Output "logFile=$archiveName" >> $Env:GITHUB_OUTPUT - name: "Output Azure IPAM Deployment Details" env: DEPLOYMENT_DETAILS: ${{ steps.uploadLogs.outputs.deployDetails }} shell: pwsh run: | + $deployDetails = @{ + GITHUB_RUN_ID = "${{ github.run_id }}(${{ github.run_attempt }})" + IPAM_SUFFIX = "${{ steps.deployScript.outputs.ipamSuffix }}" + IPAM_UI_APP_ID = "${{ steps.deployScript.outputs.ipamUIAppId }}" + IPAM_ENGINE_APP_ID = "${{ steps.deployScript.outputs.ipamEngineAppId }}" + IPAM_URL = "${{ steps.deployScript.outputs.ipamURL }}" + IPAM_LOG_FILE = "${{ steps.uploadLogs.outputs.logFile }}" + } + Write-Host "-------------------" Write-Host "Deployment Details:" Write-Host "-------------------" - Write-Host ($env:DEPLOYMENT_DETAILS | ConvertFrom-Json -AsHashtable | Format-Table | Out-String) -NoNewline + Write-Host ($deployDetails | Format-Table | Out-String) -NoNewline Write-Host "-------------------" test: From 2c01af9729687ad3772545f1cbe2518d185feef0 Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Fri, 1 Sep 2023 16:04:07 -0700 Subject: [PATCH 55/55] Updated action trigger only on PR to main --- .github/workflows/azure-ipam-testing.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/azure-ipam-testing.yml b/.github/workflows/azure-ipam-testing.yml index 27f4510..141e53a 100644 --- a/.github/workflows/azure-ipam-testing.yml +++ b/.github/workflows/azure-ipam-testing.yml @@ -3,8 +3,6 @@ name: Azure IPAM Testing run-name: Azure IPAM Deployment & Testing on: - push: - branches: [ github-actions ] pull_request: branches: [ main ]