Instead of using Pulumi service (managed) backend, I am using Azure blob container as stack state backend. According to the documentation, Pulumi CLI would expect AZURE_STORAGE_KEY
(or AZURE_STORAGE_SAS_TOKEN
) environment variable in the Pipeline Agent.
When account key is provided as pipeline variable, it's working. But when account key is stored in KeyVault as secret, it's not working.
What I did:
Account key in KayVault as secret
→ (pipeline variable group) Link secrets from an Azure key vault as variables
→ → (Pipeline variables) Link variable group
→ → → Make account key available to Pulumi CLI (in pipeline agent) as environment variable
The problem:
AZURE-STORAGE-KEY
(not AZURE_STORAGE_KEY
since secret name can not contain '_')AZURE-STORAGE-KEY
So, the problem is obvious: environment variable name mismatch → Pulumi CLI is not getting what it expects (AZURE_STORAGE_KEY
).
FYI,
azure.storage.key
, Value: $(AZURE-STORAGE-KEY)
", hoping that this variable value will be set from KeyVault secret since secrets are linked to variable group → did not working$env:AZURE_STORAGE_KEY = "$(AZURE-STORAGE-KEY)"
) mentioned that this PowerShell task is in front of "Pulumi Azure Pipelines Task" → did not workHow to solve this problem?
Is there any better approach? (providing account key to Pulumi CLI in pipeline agent securely).
Is there any way to achieve this if YAML (azure-pipelines.yml
) is used? how? (Any work around or hint would also help)
I was able to solve the problem :
env
for task to inject environment variables (that are expected by Pulumi CLI) by interpolating pipeline variablesazure-pipelines.yml
pool:
vmImage: 'ubuntu-latest'
variables:
- group: "pulumi-demo-vg"
job: PulumiUpJob
displayName: Pulumi Up Stack Deployment Job
steps:
- task: Pulumi@1
inputs:
azureSubscription: 'pulumi-demo-sc' # sc -> Service Connection
command: 'up'
loginArgs: 'azblob://pulumi-backend-container'
args: '--yes'
stack: 'dev'
env:
AZURE_STORAGE_ACCOUNT: "xxxsa"
AZURE_STORAGE_KEY: $(AZURE-STORAGE-KEY)
AZURE_CLIENT_ID: $(AZURE-CLIENT-ID)
AZURE_CLIENT_SECRET: $(AZURE-CLIENT-SECRET)
AZURE_TENANT_ID: $(AZURE-TENANT-ID)