Azure / azure-cli

Azure Command-Line Interface
MIT License
3.98k stars 2.96k forks source link

Azure CLI configuration - make everything configurable via environment variables and configuration files #29033

Open ohads-MSFT opened 4 months ago

ohads-MSFT commented 4 months ago

Related command az

In automated scenarios (especially CI/CD), passing in some arguments in the command line can be problematic

  1. You might not have access to the command line, for example when using some pipeline task that doesn't expose it: https://github.com/microsoft/azure-pipelines-tasks/issues/19912
  2. You might not want to pass secrets to the shell, to minimize the chance of secret leaks (e.g. set -x)

Describe the solution you'd like It seems like the general mechanism already exists: https://learn.microsoft.com/en-us/cli/azure/azure-cli-configuration#cli-configuration-values-and-environment-variables. All we need is to make it generic, perhaps some mapping like az foo list --name bar => $env:AZURE__FOO__LIST__NAME="bar". And then when I run az foo list, the --name argument would default to bar. In my specific case, I'd do something like $env:AZURE__LOGIN__USE_CERT_SN_ISSUER=$true and then all my logins would support SNI automatically.

Describe alternatives you've considered Specific environment variables could be added for each requested scenario (for example the az login configuration requested here: https://github.com/Azure/azure-cli/issues/10241). However, this would be a never-ending chase for more and more configuration. IMHO it would be much better to have a generic mechanism that works for everything.

Additional Context A similar approach is taken by ASP.NET: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-8.0#default-application-configuration-sources

Possibly related: https://github.com/Azure/azure-cli/issues/709

yonzhan commented 4 months ago

Thank you for opening this issue, we will look into it.