diff --git a/.github/workflows/deploy_dev_env.yml b/.github/workflows/deploy_dev_env.yml index 16fe5d68..a81e9db9 100644 --- a/.github/workflows/deploy_dev_env.yml +++ b/.github/workflows/deploy_dev_env.yml @@ -47,11 +47,13 @@ jobs: run: | $moduleCodeFilesObjs = Get-ChildItem -Path .\src -Recurse -Include *.psm1 -Exclude '*-GSA*','*GuardrailsSolutionAcceleratorSetup*','*Deploy-GuardrailsSolutionAccelerator*' Write-Host "'$($moduleCodeFilesObjs.count)' module manifest files " + ForEach ($moduleCodeFile in $moduleCodeFilesObjs) { $moduleManifestFile = Get-Item -Path $moduleCodeFile.FullName.replace('psm1','psd1') If ($moduleCodeFilesObjs.FullName -icontains $moduleCodeFile.FullName -or $moduleCodeFilesObjs.FullName -icontains $moduleManifestFile.FullName) { Write-Host "Module '$($moduleCodeFile.BaseName)' found, zipping module files..." + $destPath = "./psmodules/$($moduleCodeFile.BaseName).zip" If ($moduleCodeFile.DIrectory.Name -eq 'Guardrails-Localization') { Compress-Archive -Path "$($moduleCodeFile.Directory)/*" -DestinationPath $destPath -Force @@ -106,8 +108,9 @@ jobs: PIPELINEMODULESTAGING_RGNAME: ${{ vars.PIPELINEMODULESTAGING_RGNAME }} PIPELINEMODULESTAGING_STORAGEACCOUNTNAME: ${{ vars.PIPELINEMODULESTAGING_SANAME_DEV }} DEVSUBSCRIPTION_ID: ${{ secrets.DEV_AZURE_SUBSCRIPTION_ID}} - + - name: Pre-Clean Dev environment + if: ${{ env.DEV_UPGRADE_VAR != 'true'}} uses: azure/powershell@v1 continue-on-error: true with: @@ -128,6 +131,8 @@ jobs: $DEVLAW_SEC = $env:DEVLAW_SEC $DEVLAW_HEALTH = $env:DEVLAW_HEALTH + $DEV_UPGRADE_VAR = $env:DEV_UPGRADE_VAR + $configContent = @" { "keyVaultName": "kvcac", @@ -157,6 +162,7 @@ jobs: } "@ Set-Content -Path $configFilePath -Value $configContent + Push-Location -Path setup try { @@ -187,6 +193,8 @@ jobs: LOCATIONPOLICY_ID: ${{ vars.LOCATIONPOLICY_ID }} DEVLAW_SEC: ${{ vars.DEVLAW_SEC }} DEVLAW_HEALTH: ${{ vars.DEVLAW_HEALTH }} + DEV_UPGRADE_VAR: ${{ vars.DEV_UPGRADE_VAR}} + - name: Relogin AZ uses: azure/login@v1 with: @@ -213,6 +221,8 @@ jobs: $DEVLAW_SEC = $env:DEVLAW_SEC $DEVLAW_HEALTH = $env:DEVLAW_HEALTH + $DEV_UPGRADE_VAR = $env:DEV_UPGRADE_VAR + $configContent = @" { "keyVaultName": "kvcac", @@ -246,7 +256,9 @@ jobs: # Load tags JSON content into a variable $setupFileRelativePath = "setup/tags.json" $setupFullPath = Join-Path $env:GITHUB_WORKSPACE $setupFileRelativePath + $jsonContent = Get-Content -Raw -Path $setupFullPath | ConvertFrom-Json + # Add additional tags for dev tenant $jsonContent | Add-Member -Type NoteProperty -Name 'ClientOrganization' -Value 'SSC' $jsonContent | Add-Member -Type NoteProperty -Name 'CostCenter' -Value 'SSC Cloud Operations' @@ -254,20 +266,34 @@ jobs: $jsonContent | Add-Member -Type NoteProperty -Name 'ProjectContact' -Value 'Amrinder' $jsonContent | Add-Member -Type NoteProperty -Name 'ProjectName' -Value 'ComplianceAsCodeAzure' $jsonContent | Add-Member -Type NoteProperty -Name 'TechnicalContact' -Value 'Amrinder' + # Save the modified content back to the tags JSON file $jsonContent | ConvertTo-Json | Set-Content -Path $setupFullPath + $storageContext = (Get-AzStorageAccount -ResourceGroupName $env:PIPELINEMODULESTAGING_RGNAME -Name $env:PIPELINEMODULESTAGING_STORAGEACCOUNTNAME).context $modulesStagingURI = $storageContext.BlobEndpoint.ToString() + 'psmodules' + $alternatePSModulesURL = $modulesStagingURI Write-Output "alternatePSModulesURL is '$alternatePSModulesURL'" + $optionalParams = @{} if ($alternatePSModulesURL) { $optionalParams['alternatePSModulesURL'] = $alternatePSModulesURL } + try { $ErrorActionPreference = 'Stop' ipmo ./src/GuardrailsSolutionAcceleratorSetup - Deploy-GuardrailsSolutionAccelerator -configFilePath $configFilePath -newComponents CoreComponents, CentralizedCustomerDefenderForCloudSupport, CentralizedCustomerReportingSupport -Yes @optionalParams -verbose + if ($DEV_UPGRADE_VAR -eq "true"){ + Write-Output "Upgrade workflow flag is set to '$DEV_UPGRADE_VAR'" + Write-Output "Upgrading the CaC solution" + Deploy-GuardrailsSolutionAccelerator -configFilePath $configFilePath -update -Yes @optionalParams -verbose + } + else { + Write-Output "Upgrade workflow flag is set to '$DEV_UPGRADE_VAR'" + Write-Output "Deploying a new installation of the CaC solution" + Deploy-GuardrailsSolutionAccelerator -configFilePath $configFilePath -newComponents CoreComponents, CentralizedCustomerDefenderForCloudSupport, CentralizedCustomerReportingSupport -Yes @optionalParams -verbose + } } catch { throw "Failed test deploy of solution with error: $_" @@ -292,6 +318,7 @@ jobs: LOCATIONPOLICY_ID: ${{ vars.LOCATIONPOLICY_ID }} DEVLAW_SEC: ${{ vars.DEVLAW_SEC }} DEVLAW_HEALTH: ${{ vars.DEVLAW_HEALTH }} + DEV_UPGRADE_VAR: ${{ vars.DEV_UPGRADE_VAR}} - name: Check for AA Job Errors uses: azure/powershell@v1