Skip to content

Commit

Permalink
pr-fix: use env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnmoreels committed Jul 25, 2024
1 parent d4daa9e commit 4540054
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions build/templates/import-keyvault-secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ parameters:
steps:
- task: AzureCLI@2
displayName: 'Import secrets from Azure Key Vault'
env:
KeyVault_Name: ${{ variables['KeyVault.Name'] }}
ApplicationInsights_InstrumentationKey_SecretName: ${{ variables['ApplicationInsights.InstrumentationKey.SecretName'] }}
ApplicationInsights_ApiKey_SecretName: ${{ variables['ApplicationInsights.ApiKey.SecretName'] }}
ApplicationInsights_ApplicationId_SecretName: ${{ variables['ApplicationInsights.ApplicationId.SecretName'] }}
inputs:
azureSubscription: '${{ parameters.azureServiceConnection }}'
scriptType: 'pscore'
Expand All @@ -12,15 +17,15 @@ steps:
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Install-Module -Name Arcus.Scripting.DevOps -AllowClobber
$instrumentationKeySecretName = ${{ variables['ApplicationInsights.InstrumentationKey.SecretName'] }}
$apiKeySecretName = ${{ variables['ApplicationInsights.ApiKey.SecretName'] }}
$applicationIdSecretName = ${{ variables['ApplicationInsights.ApplicationId.SecretName'] }}
$secretNames = @( $instrumentationKeySecretName, $apiKeySecretName, $applicationIdSecretName )
$secretNames = @(
$env:ApplicationInsights_InstrumentationKey_SecretName,
$env:ApplicationInsights_ApiKey_SecretName,
$env:ApplicationInsights_ApplicationId_SecretName)
$secretNames | ForEach-Object {
$secretName = $_
$variableName = $secretName -replace '-','.'
Write-Host "Importing Azure Key vault secret '$secretName' as Azure DevOps pipeline variable '$variableName'"
$secret = az keyvault secret show --name $secretName --vault-name ${{ variables['KeyVault.Name'] }} | ConvertFrom-Json
$secret = az keyvault secret show --name $secretName --vault-name $env:KeyVault_Name | ConvertFrom-Json
Set-AzDevOpsVariable $variableName -Value $secret.value -AsSecret }

0 comments on commit 4540054

Please sign in to comment.