I have a need to download a certificate file from Azure Secure filestorage when deploying a microservice. I have about a dozen microservices with about 6 lifecycles/environments each. The certificates names do not follow a strict naming convention. I would like to create a variable hashmap/map/associative array.
I tried inputting these as a parameter in azure-pipeline.yaml
- name: sslCerts
type: object
default:
- environmentName: Development
sslCertificate: service1-dev.p12
sslCertificateKey: service1-dev
- environmentName: Sandbox
sslCertificate: service1-sbxdev.p12
sslCertificateKey: service-sbxdev-key
But I could not figure out how to dereference them:
jobs:
# ######################## Stage: Terraform Plan and Apply in Dev ########################
- template: ../azure-pipelines-template/apply-stages.yml
parameters:
sslCertificate: ${{ parameters.sslCerts[${{ parameters.envName }} ].sslCertificate)
I then tried plan 'B' to write a powershell script to output simple variables. It failed as the DownLoadSecureFile task errors before the job starts running (Secure file not found). So the below code never gets a chance to run.
$DeploymentPath = $args[0]
$certs = @{
Sandbox = {
certName = "sbx-cert"
certKey = "sbx-cert-key"
}
Development = {
certName = "dev-cert"
certKey = "dev-cert-key"
}
}
$cert = $certs[$DeploymentPath]
# These Magic Codes create variable in Azure Devops
write-output "##vso[task.setvariable variable=sslCertificate]$cert.certName"
write-output "##vso[task.setvariable variable=sslCertificateKeyFile]$cert.certKey"
I don't really want to create 70+ variable files (each combination of microservice and environment). Is there some interpolation of object parameters that I'm missing. Can I duplicate the DownloadSecureFile task in a script or terraform and take it out of AzureDevops yaml?
You're very close, two things need changing:
Declare your parameter as map (not as array):
parameter:
- name: sslCerts
type: object
default:
Development:
sslCertificate: service1-dev.p12
sslCertificateKey: service1-dev
Sandbox:
sslCertificate: service1-sbxdev.p12
sslCertificateKey: service-sbxdev-key
This way the environment name becomes key, which you can use when referencing.
Once you're inside ${{ }}, there's no need to nest it:
jobs:
# ######################## Stage: Terraform Plan and Apply in Dev ########################
- template: ../azure-pipelines-template/apply-stages.yml
parameters:
sslCertificate: ${{ parameters.sslCerts[parameters.envName].sslCertificate $}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With