Skip to content

Commit 5f7fc6f

Browse files
Merge pull request #455 from microsoft/psl-addcreatedbyparaminyml
fix: Added createdBy tag in resourcedeployment.ps1 file
2 parents 454cbb2 + 3b1f102 commit 5f7fc6f

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

Deployment/main.bicep

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ var resourceGroupLocation = resourceGroup().location
2323
// Load the abbrevations file required to name the azure resources.
2424
var abbrs = loadJsonContent('./abbreviations.json')
2525

26-
var deployerInfo = deployer()
26+
@description('Optional created by user name')
27+
param createdBy string
2728

2829
resource resourceGroupTags 'Microsoft.Resources/tags@2021-04-01' = {
2930
name: 'default'
3031
properties: {
3132
tags: {
3233
TemplateName: 'DKM'
33-
CreatedBy: split(deployerInfo.userPrincipalName, '@')[0]
34+
CreatedBy: createdBy
3435
}
3536
}
3637
}
@@ -213,3 +214,5 @@ output gs_containerregistry_endpoint string = gs_containerregistry.outputs.acrEn
213214
//return resourcegroup resource ID
214215
output gs_resourcegroup_id string = resourceGroup().id
215216

217+
output createdByOutput string = createdBy
218+

Deployment/resourcedeployment.ps1

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ function PromptForParameters {
8080
[string]$location,
8181
[string]$modelLocation,
8282
[string]$email
83-
)
83+
84+
)
8485

8586
Clear-Host
8687

@@ -148,7 +149,7 @@ function PromptForParameters {
148149
resourceGroupName = $resourceGroupName
149150
location = $location
150151
modelLocation = $modelLocation
151-
email = $email
152+
email = $email
152153
}
153154
}
154155

@@ -169,7 +170,7 @@ function LoginAzure([string]$subscriptionID) {
169170
az login --service-principal `
170171
--username $env:AZURE_CLIENT_ID `
171172
--password $env:AZURE_CLIENT_SECRET `
172-
--tenant $env:AZURE_TENANT_ID
173+
--tenant $env:AZURE_TENANT_ID `
173174
Write-Host "CI deployment mode"
174175
}
175176
else{
@@ -185,12 +186,19 @@ function LoginAzure([string]$subscriptionID) {
185186
Write-Host "manual deployment mode"
186187
}
187188
az account set --subscription $subscriptionID
188-
Write-Host "Switched subscription to '$subscriptionID' `r`n" -ForegroundColor Yellow
189+
Write-Host "Switched subscription to '$subscriptionID' `r`n" -ForegroundColor Yellow
189190
}
190191

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

195+
if ($env:CI -eq "true"){
196+
$createdBy = 'Pipeline'
197+
}
198+
else{
199+
$createdBy = $email.Split('@')[0]
200+
}
201+
194202
try {
195203
# Generate a random number between 0 and 99999
196204
$randomNumber = Get-Random -Minimum 0 -Maximum 99999
@@ -230,23 +238,23 @@ function DeployAzureResources([string]$location, [string]$modelLocation) {
230238
Write-Host "Generated Resource Group Name: $resourceGroupName"
231239

232240
Write-Host "No RG provided. Creating new RG: $resourceGroupName" -ForegroundColor Yellow
233-
az group create --name $resourceGroupName --location $location --tags EnvironmentName=$environmentName TemplateName="DKM" | Out-Null
241+
az group create --name $resourceGroupName --location $location --tags EnvironmentName=$environmentName TemplateName="DKM" createdBy=$createdBy | Out-Null
234242
}
235243
else {
236244
$exists = az group exists --name $resourceGroupName | ConvertFrom-Json
237245
if (-not $exists) {
238246
Write-Host "Specified RG does not exist. Creating RG: $resourceGroupName" -ForegroundColor Yellow
239-
az group create --name $resourceGroupName --location $location --tags EnvironmentName=$environmentName TemplateName="DKM" | Out-Null
247+
az group create --name $resourceGroupName --location $location --tags EnvironmentName=$environmentName TemplateName="DKM" createdBy=$createdBy | Out-Null
240248
}
241249
else {
242-
az group update --name $resourceGroupName --set tags.EnvironmentName=$environmentName tags.TemplateName="DKM" | Out-Null
250+
az group update --name $resourceGroupName --set tags.EnvironmentName=$environmentName tags.TemplateName="DKM" tags.createdBy=$createdBy | Out-Null
243251
Write-Host "Using existing RG: $resourceGroupName" -ForegroundColor Green
244252
}
245253
}
246254

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

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

0 commit comments

Comments
 (0)