From cb6c4e5b9085153ef1e5951aedef0ffe15854f9c Mon Sep 17 00:00:00 2001 From: Helder Pinto Date: Mon, 8 Apr 2024 17:54:03 +0100 Subject: [PATCH] Fixed silent deployment with custom workspace --- .github/workflows/continuous-deployment-dev.yml | 12 ++++++++---- .github/workflows/continuous-deployment.yml | 6 ++++-- Deploy-AzureOptimizationEngine.ps1 | 11 ++++++++--- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/.github/workflows/continuous-deployment-dev.yml b/.github/workflows/continuous-deployment-dev.yml index 5ed72c9..b31f0c9 100644 --- a/.github/workflows/continuous-deployment-dev.yml +++ b/.github/workflows/continuous-deployment-dev.yml @@ -15,6 +15,10 @@ jobs: AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} AOE_SQL_ADMIN: ${{ secrets.AOE_SQL_ADMIN }} AOE_SQL_PASSWD: ${{ secrets.AOE_SQL_PASSWD }} + AOE_LOCATION: ${{ secrets.AOE_LOCATION }} + AOE_NAMEPREFIX: ${{ secrets.AOE_NAMEPREFIX }} + AOE_WORKSPACENAME: ${{ secrets.AOE_WORKSPACENAME }} + AOE_WORKSPACERG: ${{ secrets.AOE_WORKSPACERG }} steps: - run: echo "This job is now running on a ${{ runner.os }} server hosted by GitHub for the ${{ github.ref }} branch of the ${{ github.repository }} repository!" - name: Installing modules @@ -35,14 +39,14 @@ jobs: run: | echo '{ "SubscriptionId": "'"$AZURE_SUBSCRIPTION_ID"'", - "NamePrefix": "aoedevgithub", + "NamePrefix": "'"$AOE_NAMEPREFIX"'", "WorkspaceReuse": "y", - "WorkspaceName": "helderpintopfe", - "WorkspaceResourceGroupName": "pfe-governance-rg", + "WorkspaceName": "'"$AOE_WORKSPACENAME"'", + "WorkspaceResourceGroupName": "'"$AOE_WORKSPACERG"'", "DeployWorkbooks": "y", "SqlAdmin": "'"$AOE_SQL_ADMIN"'", "SqlPass": "'"$AOE_SQL_PASSWD"'", - "TargetLocation": "westeurope", + "TargetLocation": "'"$AOE_LOCATION"'", "DeployBenefitsUsageDependencies": "n" }' > ./deploymentSettings.json - name: Testing PowerShell script call diff --git a/.github/workflows/continuous-deployment.yml b/.github/workflows/continuous-deployment.yml index 4cacd2b..aa3fd8c 100644 --- a/.github/workflows/continuous-deployment.yml +++ b/.github/workflows/continuous-deployment.yml @@ -15,6 +15,8 @@ jobs: AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} AOE_SQL_ADMIN: ${{ secrets.AOE_SQL_ADMIN }} AOE_SQL_PASSWD: ${{ secrets.AOE_SQL_PASSWD }} + AOE_LOCATION: ${{ secrets.AOE_LOCATION }} + AOE_NAMEPREFIX: ${{ secrets.AOE_NAMEPREFIX }} steps: - run: echo "This job is now running on a ${{ runner.os }} server hosted by GitHub for the ${{ github.ref }} branch of the ${{ github.repository }} repository!" - name: Installing modules @@ -35,12 +37,12 @@ jobs: run: | echo '{ "SubscriptionId": "'"$AZURE_SUBSCRIPTION_ID"'", - "NamePrefix": "aoeprdgithub", + "NamePrefix": "'"$AOE_NAMEPREFIX"'", "WorkspaceReuse": "n", "DeployWorkbooks": "y", "SqlAdmin": "'"$AOE_SQL_ADMIN"'", "SqlPass": "'"$AOE_SQL_PASSWD"'", - "TargetLocation": "westeurope", + "TargetLocation": "'"$AOE_LOCATION"'", "DeployBenefitsUsageDependencies": "n" }' > ./deploymentSettings.json - name: Testing PowerShell script call diff --git a/Deploy-AzureOptimizationEngine.ps1 b/Deploy-AzureOptimizationEngine.ps1 index 702dc04..ee234ed 100644 --- a/Deploy-AzureOptimizationEngine.ps1 +++ b/Deploy-AzureOptimizationEngine.ps1 @@ -378,8 +378,13 @@ if (-not($deploymentOptions["ResourceGroupName"])) $resourceGroupName = $resourceGroupNameTemplate -f $namePrefix $storageAccountName = $storageAccountNameTemplate -f $namePrefix $automationAccountName = $automationAccountNameTemplate -f $namePrefix - $sqlServerName = $sqlServerNameTemplate -f $namePrefix - $laWorkspaceName = $laWorkspaceNameTemplate -f $namePrefix + $sqlServerName = $sqlServerNameTemplate -f $namePrefix + if ("Y", "y" -contains $workspaceReuse -and $silentDeploy) { + $laWorkspaceName = $deploymentOptions["WorkspaceName"] + } + else { + $laWorkspaceName = $laWorkspaceNameTemplate -f $namePrefix + } $sqlDatabaseName = "azureoptimization" } @@ -393,7 +398,7 @@ if (-not($deploymentOptions["ResourceGroupName"])) else { # With a silent deploy, overrule any custom resource naming if a NamePrefix is provided - if($silentDeploy -and (![string]::IsNullOrEmpty($namePrefix))) + if($silentDeploy -and ![string]::IsNullOrEmpty($namePrefix) -and $namePrefix -ne "EmptyNamePrefix") { $deploymentName = $deploymentNameTemplate -f $namePrefix $resourceGroupName = $resourceGroupNameTemplate -f $namePrefix