When creating pipelines for a company there is often secrets that need to be used by more than 1 repository. This is something that GitHub can't do natively. A developer is also unable to read the secrets in GitHub once they are entered. Although this is for security a simple typo can't be found and instead the entire secret needs to be reentered. There is also no visible history for GitHub secrets and no ability to revert to an earlier version of a secret.
Solution: Store them in Azure KeyVault.
✅ Figure: Resource Group with 4 Azure KeyVaults ready to go
- name: Azure CLI scriptuses: azure/CLI@v1with:inlineScript: |az keyvault secret show --vault-name dev-kvconfig --name myAppInsightsKey --query value
Figure: Retrieve KeyVault Secrets to use in GitHub Actions
resource environmentKeyVault 'Microsoft.KeyVault/vaults@2022-07-01' existing = {name: '${environmentName}-kvconfig'scope: resourceGroup(envSubscriptionId, envResourceGroup)}
Then reference the value like this to provide parameters for other bicep modules:
module azuredeployment 'environment-keyvault.bicep' ={name: '${projectName}-${lastDeploymentDate}'scope: resourceGroup()params: {location: locationtags: tagsAppInsightsKey: environmentKeyVault.getSecret('myAppInsightsKey')}
Figure: Retrieve KeyVault Secrets using Bicep
Get-AzKeyVaultSecret -VaultName "$environmentName-kvconfig" -Name myAppInsightsKey -AsPlainText
Figure: Retrieve KeyVault Secrets using PowerShell