Azure / aztfexport

A tool to bring existing Azure resources under Terraform's management
https://azure.github.io/aztfexport/
Mozilla Public License 2.0
1.63k stars 190 forks source link

Support full set of authentication configuration flags #546

Closed magodo closed 4 months ago

magodo commented 4 months ago

Previously, there are some (though incomplete) authentication related flags, e.g. --env, --use-azure-cli-cred, these flags only affect the behavior of the aztfexport (e.g. listing resources), but won't be passed through to the providers. The providers' behaviors are only affected by either the -provider-config flag or by the environment of their owns.

The reason was there are a bunch of provider level properties (currently there are two providers). It would be a mass if we wrap all these flags and provide a bunch of flags back to users, and probably mentioning which set of flags are only usable for azurerm provider, and which are only for azapi.

However for the standview of the authentication, this separation brings a burden to users who will now need to take care of the two parts: aztfexport and the provider. It would be much easier for them to regard the both as a whole in terms of authentication. By reviewing the authentication flags between azurerm and azapi, they are actually quite the same. Based on this, we created this PR to wrap and expose all these authentication related flags, which will affect both the aztfexport and the providers.

Changes

The new flags (or existing flags but now passed to providers) are listed below:

Note that the flags above are following the naming convention as the azurerm provider. All of them are configurable via environment variables as well, which include the same env var as is defined in the azurerm provider.

The default authentication of the aztfexport will attempt to authenticate with each of the credential types, in the following order, stopping when one provides a token:

If one or more use-xxx-cred is not true, then that credential type will be skipped. This behavior is the same as the provider. This changes the old behavior where when any use-xxx-cred is specified, it will only use that credential type exclusively. Also note that the old flag use-environment-cred is now removed.

The last thing to call out is that the priority of these new auth flags have lower priority than what is defined in the provider-config, which means users can override any auth config for the provider in the provider-config. This makes it possible for users to use different credential types between the aztfexport and the provider.

Tests

With TF

Without TF

References

Fix #540