From e077374ea5018a013f330a4ebb72e656361f814c Mon Sep 17 00:00:00 2001 From: Azure SDK Bot <53356347+azure-sdk@users.noreply.github.com> Date: Wed, 9 Mar 2022 13:57:53 -0800 Subject: [PATCH] Add AZURE_SERVICE_DIRECTORY environment variable in test deployment script (#3373) Co-authored-by: Ben Broderick Phillips --- eng/common/TestResources/New-TestResources.ps1 | 9 +++++---- eng/common/TestResources/SubConfig-Helpers.ps1 | 9 ++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/eng/common/TestResources/New-TestResources.ps1 b/eng/common/TestResources/New-TestResources.ps1 index fe01142b0..c3455c981 100644 --- a/eng/common/TestResources/New-TestResources.ps1 +++ b/eng/common/TestResources/New-TestResources.ps1 @@ -236,7 +236,8 @@ function BuildBicepFile([System.IO.FileSystemInfo] $file) return $templateFilePath } -function BuildDeploymentOutputs([string]$serviceDirectoryPrefix, [object]$azContext, [object]$deployment) { +function BuildDeploymentOutputs([string]$serviceName, [object]$azContext, [object]$deployment) { + $serviceDirectoryPrefix = BuildServiceDirectoryPrefix $serviceName # Add default values $deploymentOutputs = [Ordered]@{ "${serviceDirectoryPrefix}CLIENT_ID" = $TestApplicationId; @@ -249,6 +250,7 @@ function BuildDeploymentOutputs([string]$serviceDirectoryPrefix, [object]$azCont "${serviceDirectoryPrefix}AZURE_AUTHORITY_HOST" = $azContext.Environment.ActiveDirectoryAuthority; "${serviceDirectoryPrefix}RESOURCE_MANAGER_URL" = $azContext.Environment.ResourceManagerUrl; "${serviceDirectoryPrefix}SERVICE_MANAGEMENT_URL" = $azContext.Environment.ServiceManagementUrl; + "AZURE_SERVICE_DIRECTORY" = $serviceName.ToUpperInvariant(); } MergeHashes $EnvironmentVariables $(Get-Variable deploymentOutputs) @@ -268,8 +270,7 @@ function BuildDeploymentOutputs([string]$serviceDirectoryPrefix, [object]$azCont } function SetDeploymentOutputs([string]$serviceName, [object]$azContext, [object]$deployment, [object]$templateFile) { - $serviceDirectoryPrefix = $serviceName.ToUpperInvariant() + "_" - $deploymentOutputs = BuildDeploymentOutputs $serviceDirectoryPrefix $azContext $deployment + $deploymentOutputs = BuildDeploymentOutputs $serviceName $azContext $deployment if ($OutFile) { if (!$IsWindows) { @@ -300,7 +301,7 @@ function SetDeploymentOutputs([string]$serviceName, [object]$azContext, [object] $EnvironmentVariables[$key] = $value if ($CI) { - if (ShouldMarkValueAsSecret $serviceDirectoryPrefix $key $value $notSecretValues) { + if (ShouldMarkValueAsSecret $serviceName $key $value $notSecretValues) { # Treat all ARM template output variables as secrets since "SecureString" variables do not set values. # In order to mask secrets but set environment variables for any given ARM template, we set variables twice as shown below. LogVsoCommand "##vso[task.setvariable variable=_$key;issecret=true;]$value" diff --git a/eng/common/TestResources/SubConfig-Helpers.ps1 b/eng/common/TestResources/SubConfig-Helpers.ps1 index df4dc9cd0..4e8119883 100644 --- a/eng/common/TestResources/SubConfig-Helpers.ps1 +++ b/eng/common/TestResources/SubConfig-Helpers.ps1 @@ -1,4 +1,8 @@ -function ShouldMarkValueAsSecret([string]$serviceDirectoryPrefix, [string]$key, [string]$value, [array]$allowedValues = @()) +function BuildServiceDirectoryPrefix([string]$serviceName) { + return $serviceName.ToUpperInvariant() + "_" +} + +function ShouldMarkValueAsSecret([string]$serviceName, [string]$key, [string]$value, [array]$allowedValues = @()) { $logOutputNonSecret = @( # Environment Variables @@ -14,6 +18,7 @@ function ShouldMarkValueAsSecret([string]$serviceDirectoryPrefix, [string]$key, "RESOURCE_MANAGER_URL", "SERVICE_MANAGEMENT_URL", "ENDPOINT_SUFFIX", + "SERVICE_DIRECTORY", # This is used in many places and is harder to extract from the base subscription config, so hardcode it for now. "STORAGE_ENDPOINT_SUFFIX", # Parameters @@ -25,6 +30,8 @@ function ShouldMarkValueAsSecret([string]$serviceDirectoryPrefix, [string]$key, "ProvisionerApplicationId" ) + $serviceDirectoryPrefix = BuildServiceDirectoryPrefix $serviceName + $suffix1 = $key -replace $serviceDirectoryPrefix, "" $suffix2 = $key -replace "AZURE_", "" $variants = @($key, $suffix1, $suffix2)