Azure / Azure/azure-cli

Can't inject a non-certificate secret into vm with az vm create

Open
#10,211 7 comments 0 reactions 2 assignees Claimed by @zhoxing-ms View on GitHub
act-observability-squad Compute Compute - VM feature-request
Dominant language
Python
Stars
4.6k
Forks
3.5k
Avg merge
3d 2h
Merged PRs (30d)
60

Description

**Describe the bug**
Hi, I'm trying to use cloud-init to automate the configuration and registration of a Linux build agent self-hosted in an ASE, since the agent will be redeployed regularly. To automate the registration, I need to inject an Azure DevOps personal access token into cloud-init. I added the token to a key vault and tried using [this tutorial](https://docs.microsoft.com/en-us/azure/virtual-machines/linux/tutorial-automate-vm-deployment) to inject the token, but received the following error:
```
Deployment failed. Correlation ID: 6a440bdb-b5fb-48df-9e0b-fa3bc03d8fe4. {
"status": "Failed",
"error": {
"code": "ResourceDeploymentFailure",
"message": "The resource operation completed with terminal provisioning state 'Failed'.",
"details": [
{
"code": "CertificateImproperlyFormatted",
"message": "The data retrieved from *** is not deserializable into JSON."
}
]
}
}
```

**To Reproduce**
```
secret=$(az keyvault secret list-versions --subscription "{subscription}" --vault-name {vault name} --name {secret name} --query "[?attributes.enabled].id" --output tsv)

vm_secret=$(az vm secret format --subscription "{subscription}" -g "{resource group}" -s "$secret" --keyvault {vault name})

az vm create \
--name {vm name} \
--resource-group {resource group name} \
--image Canonical:UbuntuServer:18.04-LTS:latest \
--location eastus2 \
--size Standard_B1ms \
--admin-username {admin username} \
--vnet-name {vnet name} \
--subnet {subnet name} \
--custom-data cloud-init.txt \
--nsg {nsg name} \
--ssh-key-values {public ssh} \
--secrets "$vm_secret" \
--tags environment=test
```
**Expected behavior**
I would be allowed to inject actual secrets with az vm create --secrets, rather than only certificates.

If this isn't possible, I would like to be guided on the best practice for injecting secrets into cloud-init.

**Environment summary**
CLI version 2.0.70 , bash shell

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.