Skip to content

Commit 0d18ce1

Browse files
azure-sdkbenbp
andauthored
Add AZURE_SERVICE_DIRECTORY environment variable in test deployment script (Azure#27296)
Co-authored-by: Ben Broderick Phillips <bebroder@microsoft.com>
1 parent 17d6ca1 commit 0d18ce1

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

eng/common/TestResources/New-TestResources.ps1

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ function BuildBicepFile([System.IO.FileSystemInfo] $file)
236236
return $templateFilePath
237237
}
238238

239-
function BuildDeploymentOutputs([string]$serviceDirectoryPrefix, [object]$azContext, [object]$deployment) {
239+
function BuildDeploymentOutputs([string]$serviceName, [object]$azContext, [object]$deployment) {
240+
$serviceDirectoryPrefix = BuildServiceDirectoryPrefix $serviceName
240241
# Add default values
241242
$deploymentOutputs = [Ordered]@{
242243
"${serviceDirectoryPrefix}CLIENT_ID" = $TestApplicationId;
@@ -249,6 +250,7 @@ function BuildDeploymentOutputs([string]$serviceDirectoryPrefix, [object]$azCont
249250
"${serviceDirectoryPrefix}AZURE_AUTHORITY_HOST" = $azContext.Environment.ActiveDirectoryAuthority;
250251
"${serviceDirectoryPrefix}RESOURCE_MANAGER_URL" = $azContext.Environment.ResourceManagerUrl;
251252
"${serviceDirectoryPrefix}SERVICE_MANAGEMENT_URL" = $azContext.Environment.ServiceManagementUrl;
253+
"AZURE_SERVICE_DIRECTORY" = $serviceName.ToUpperInvariant();
252254
}
253255

254256
MergeHashes $EnvironmentVariables $(Get-Variable deploymentOutputs)
@@ -268,8 +270,7 @@ function BuildDeploymentOutputs([string]$serviceDirectoryPrefix, [object]$azCont
268270
}
269271

270272
function SetDeploymentOutputs([string]$serviceName, [object]$azContext, [object]$deployment, [object]$templateFile) {
271-
$serviceDirectoryPrefix = $serviceName.ToUpperInvariant() + "_"
272-
$deploymentOutputs = BuildDeploymentOutputs $serviceDirectoryPrefix $azContext $deployment
273+
$deploymentOutputs = BuildDeploymentOutputs $serviceName $azContext $deployment
273274

274275
if ($OutFile) {
275276
if (!$IsWindows) {
@@ -300,7 +301,7 @@ function SetDeploymentOutputs([string]$serviceName, [object]$azContext, [object]
300301
$EnvironmentVariables[$key] = $value
301302

302303
if ($CI) {
303-
if (ShouldMarkValueAsSecret $serviceDirectoryPrefix $key $value $notSecretValues) {
304+
if (ShouldMarkValueAsSecret $serviceName $key $value $notSecretValues) {
304305
# Treat all ARM template output variables as secrets since "SecureString" variables do not set values.
305306
# In order to mask secrets but set environment variables for any given ARM template, we set variables twice as shown below.
306307
LogVsoCommand "##vso[task.setvariable variable=_$key;issecret=true;]$value"

eng/common/TestResources/SubConfig-Helpers.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
function ShouldMarkValueAsSecret([string]$serviceDirectoryPrefix, [string]$key, [string]$value, [array]$allowedValues = @())
1+
function BuildServiceDirectoryPrefix([string]$serviceName) {
2+
return $serviceName.ToUpperInvariant() + "_"
3+
}
4+
5+
function ShouldMarkValueAsSecret([string]$serviceName, [string]$key, [string]$value, [array]$allowedValues = @())
26
{
37
$logOutputNonSecret = @(
48
# Environment Variables
@@ -14,6 +18,7 @@ function ShouldMarkValueAsSecret([string]$serviceDirectoryPrefix, [string]$key,
1418
"RESOURCE_MANAGER_URL",
1519
"SERVICE_MANAGEMENT_URL",
1620
"ENDPOINT_SUFFIX",
21+
"SERVICE_DIRECTORY",
1722
# This is used in many places and is harder to extract from the base subscription config, so hardcode it for now.
1823
"STORAGE_ENDPOINT_SUFFIX",
1924
# Parameters
@@ -25,6 +30,8 @@ function ShouldMarkValueAsSecret([string]$serviceDirectoryPrefix, [string]$key,
2530
"ProvisionerApplicationId"
2631
)
2732

33+
$serviceDirectoryPrefix = BuildServiceDirectoryPrefix $serviceName
34+
2835
$suffix1 = $key -replace $serviceDirectoryPrefix, ""
2936
$suffix2 = $key -replace "AZURE_", ""
3037
$variants = @($key, $suffix1, $suffix2)

0 commit comments

Comments
 (0)