Skip to content

Support AZURE_CLOUD environment variable for connecting to Azure Government #23328

Open

Description

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()

https://stackoverflow.com/questions/78872532/how-can-i-connect-the-azure-go-sdk-to-azure-government/78872533

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Labels

MgmtThis issue is related to a management-plane library.customer-reportedIssues that are reported by GitHub users external to the Azure organization.feature-requestThis issue requires a new behavior in the product in order be resolved.needs-team-attentionWorkflow: This issue needs attention from Azure service team or SDK team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions