Description
openedon Aug 14, 2024
Feature Request
Background
I found references online to being able to set an AZURE_ENVIRONMENT
to control which cloud the SDK connects to. And you could use this to tell the SDK to connect to Azure Government.
I found content in this repo's docs about this too but it's marked as legacy.
When I tested this manually, it didn't seem to work. I wasn't able to set the env var to a value that caused it to connect to any host other than management.azure.com
.
Request
It would be helpful if the SDK supported the environment variable so that it can be set to the name of the cloud to be connected to. This would mean less need to write code to make the SDK connect to the desired cloud.
Workaround
My workaround for this is to manually configure it via the options struct with added code.
First, create a credential like you would when connecting to the public Azure cloud instead of Azure Government.
cred, err := azidentity.NewDefaultAzureCredential(nil)Then, use the credential alongside an options structs where the desired cloud is selected. This works for both the approach where you instantiate a factory and then instantiate clients from it and the approach where you instaniate clients directly. Here's a factory example where a resource groups client is instantiated from the factory.
opts := azcore.ClientOptions{Cloud: cloud.AzureGovernment} clientFactory, _ := armresources.NewClientFactory(<subscription ID>, cred, &arm.ClientOptions{ ClientOptions: opts, }) resourceGroupsClient = clientFactory.NewResourceGroupsClient()
This is easy in new projects but more tedious to do in projects where you have already created multiple components that talk to each other via env vars. With env var support, env var values can be propagated through such systems without code changes required in the component that uses the Azure Go SDK.