Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Deployment/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ var resourceGroupLocation = resourceGroup().location
// Load the abbrevations file required to name the azure resources.
var abbrs = loadJsonContent('./abbreviations.json')

var deployerInfo = deployer()
@description('Optional created by user name')
param createdBy string

resource resourceGroupTags 'Microsoft.Resources/tags@2021-04-01' = {
name: 'default'
properties: {
tags: {
TemplateName: 'DKM'
CreatedBy: split(deployerInfo.userPrincipalName, '@')[0]
CreatedBy: createdBy
}
}
}
Expand Down Expand Up @@ -213,3 +214,5 @@ output gs_containerregistry_endpoint string = gs_containerregistry.outputs.acrEn
//return resourcegroup resource ID
output gs_resourcegroup_id string = resourceGroup().id

output createdByOutput string = createdBy

26 changes: 17 additions & 9 deletions Deployment/resourcedeployment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ function PromptForParameters {
[string]$location,
[string]$modelLocation,
[string]$email
)

)

Clear-Host

Expand Down Expand Up @@ -148,7 +149,7 @@ function PromptForParameters {
resourceGroupName = $resourceGroupName
location = $location
modelLocation = $modelLocation
email = $email
email = $email
}
}

Expand All @@ -169,7 +170,7 @@ function LoginAzure([string]$subscriptionID) {
az login --service-principal `
--username $env:AZURE_CLIENT_ID `
--password $env:AZURE_CLIENT_SECRET `
--tenant $env:AZURE_TENANT_ID
--tenant $env:AZURE_TENANT_ID `
Write-Host "CI deployment mode"
}
else{
Expand All @@ -185,12 +186,19 @@ function LoginAzure([string]$subscriptionID) {
Write-Host "manual deployment mode"
}
az account set --subscription $subscriptionID
Write-Host "Switched subscription to '$subscriptionID' `r`n" -ForegroundColor Yellow
Write-Host "Switched subscription to '$subscriptionID' `r`n" -ForegroundColor Yellow
}

function DeployAzureResources([string]$location, [string]$modelLocation) {
Write-Host "Started Deploying Knowledge Mining Solution Accelerator Service Azure resources.....`r`n" -ForegroundColor Yellow

if ($env:CI -eq "true"){
$createdBy = 'Pipeline'
}
else{
$createdBy = $email.Split('@')[0]
}

try {
# Generate a random number between 0 and 99999
$randomNumber = Get-Random -Minimum 0 -Maximum 99999
Expand Down Expand Up @@ -230,23 +238,23 @@ function DeployAzureResources([string]$location, [string]$modelLocation) {
Write-Host "Generated Resource Group Name: $resourceGroupName"

Write-Host "No RG provided. Creating new RG: $resourceGroupName" -ForegroundColor Yellow
az group create --name $resourceGroupName --location $location --tags EnvironmentName=$environmentName TemplateName="DKM" | Out-Null
az group create --name $resourceGroupName --location $location --tags EnvironmentName=$environmentName TemplateName="DKM" createdBy=$createdBy | Out-Null
}
else {
$exists = az group exists --name $resourceGroupName | ConvertFrom-Json
if (-not $exists) {
Write-Host "Specified RG does not exist. Creating RG: $resourceGroupName" -ForegroundColor Yellow
az group create --name $resourceGroupName --location $location --tags EnvironmentName=$environmentName TemplateName="DKM" | Out-Null
az group create --name $resourceGroupName --location $location --tags EnvironmentName=$environmentName TemplateName="DKM" createdBy=$createdBy | Out-Null
}
else {
az group update --name $resourceGroupName --set tags.EnvironmentName=$environmentName tags.TemplateName="DKM" | Out-Null
az group update --name $resourceGroupName --set tags.EnvironmentName=$environmentName tags.TemplateName="DKM" tags.createdBy=$createdBy | Out-Null
Write-Host "Using existing RG: $resourceGroupName" -ForegroundColor Green
}
}

# Perform a what-if deployment to preview changes
Write-Host "Evaluating Deployment resource availabilities to preview changes..." -ForegroundColor Yellow
$whatIfResult = az deployment group what-if --resource-group $resourceGroupName --template-file "./main.bicep" --name $deploymentName --parameters modeldatacenter=$modelLocation location=$location environmentName=$environmentName
$whatIfResult = az deployment group what-if --resource-group $resourceGroupName --template-file "./main.bicep" --name $deploymentName --parameters modeldatacenter=$modelLocation location=$location environmentName=$environmentName createdBy=$createdBy

if ($LASTEXITCODE -ne 0) {
Write-Host "There might be something wrong with your deployment." -ForegroundColor Red
Expand All @@ -257,7 +265,7 @@ function DeployAzureResources([string]$location, [string]$modelLocation) {
# Proceed with the actual deployment
Write-Host "Proceeding with Deployment..." -ForegroundColor Yellow
Write-Host "Resource Group Name: $resourceGroupName" -ForegroundColor Yellow
$deploymentResult = az deployment group create --resource-group $resourceGroupName --template-file "./main.bicep" --name $deploymentName --parameters modeldatacenter=$modelLocation location=$location environmentName=$environmentName
$deploymentResult = az deployment group create --resource-group $resourceGroupName --template-file "./main.bicep" --name $deploymentName --parameters modeldatacenter=$modelLocation location=$location environmentName=$environmentName createdBy=$createdBy
# Check if deploymentResult is valid
ValidateVariableIsNullOrEmpty -variableValue $deploymentResult -variableName "Deployment Result"
if ($LASTEXITCODE -ne 0) {
Expand Down