-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Added support for custom Azure Environments #29067
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Added support for custom Azure Environments #29067
Conversation
| Thanks for your contribution! The pull request validation has started. Please revisit this comment for updated status. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds support for custom Azure Environments that customers might have configured using Add-AzEnvironment. The changes enable Stack HCI registration to work with non-standard Azure cloud environments beyond the built-in ones (Azure Public Cloud, China Cloud, US Government Cloud, German Cloud, etc.).
Changes:
- Added fallback logic to query custom Azure Environments using
Get-AzEnvironmentwhen the environment name doesn't match built-in clouds - Updated four helper functions to retrieve environment-specific endpoints from custom Azure Environments
- Added a default billing service API scope constant for custom environments
- Updated ChangeLog.md with the new capability
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| src/StackHCI/StackHCI/ChangeLog.md | Added changelog entry describing custom Azure Environment support |
| src/StackHCI/StackHCI.Autorest/custom/stackhci.ps1 | Added custom environment support to Get-ManagementUrl, Get-PortalDomain, Get-EnvironmentEndpoints functions and registerArcScript; defined default billing API scope constant |
| elseif ($null -ne (Get-AzEnvironment -Name $EnvironmentName)) | ||
| { | ||
| $managementUrl = (Get-AzEnvironment -Name $EnvironmentName).ResourceManagerUrl |
Copilot
AI
Jan 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential null reference error if ResourceManagerUrl property is null. The code checks if the environment exists with $null -ne (Get-AzEnvironment -Name $EnvironmentName) but doesn't validate that the returned object has a non-null ResourceManagerUrl property. Consider adding a null check: $env = Get-AzEnvironment -Name $EnvironmentName; if ($null -ne $env -and $null -ne $env.ResourceManagerUrl) { ... }
| elseif ($null -ne (Get-AzEnvironment -Name $EnvironmentName)) | |
| { | |
| $managementUrl = (Get-AzEnvironment -Name $EnvironmentName).ResourceManagerUrl | |
| elseif ($null -ne ($environment = Get-AzEnvironment -Name $EnvironmentName) -and $null -ne $environment.ResourceManagerUrl) | |
| { | |
| $managementUrl = $environment.ResourceManagerUrl |
| elseif ($null -ne (Get-AzEnvironment -Name $EnvironmentName)) | ||
| { | ||
| $managementUrl = (Get-AzEnvironment -Name $EnvironmentName).ResourceManagerUrl | ||
| } | ||
| else | ||
| { | ||
| throw "Invalid Azure Environment name" |
Copilot
AI
Jan 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential null reference error if ResourceManagerUrl property is null. Same issue as in the registerArcScript - the environment object's properties may be null even when the environment exists. Add proper null validation before accessing the property.
| elseif ($null -ne (Get-AzEnvironment -Name $EnvironmentName)) | |
| { | |
| $managementUrl = (Get-AzEnvironment -Name $EnvironmentName).ResourceManagerUrl | |
| } | |
| else | |
| { | |
| throw "Invalid Azure Environment name" | |
| else | |
| { | |
| $environment = Get-AzEnvironment -Name $EnvironmentName | |
| if ($null -ne $environment -and $null -ne $environment.ResourceManagerUrl) | |
| { | |
| $managementUrl = $environment.ResourceManagerUrl | |
| } | |
| else | |
| { | |
| throw "Invalid Azure Environment name" | |
| } |
| } | ||
| elseif ($null -ne (Get-AzEnvironment -Name $EnvironmentName)) | ||
| { | ||
| return (Get-AzEnvironment -Name $EnvironmentName).ManagementPortalUrl |
Copilot
AI
Jan 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential null reference error if ManagementPortalUrl property is null. Custom Azure Environments may not have this property configured. Consider adding validation and a meaningful error message or default value.
| $ServiceEndpoint.Value = "https://doesnotmatter/" | ||
| $Authority.Value = (Get-AzEnvironment -Name $EnvironmentName).ActiveDirectoryAuthority | ||
| $BillingServiceApiScope.Value = $DefaultBillingServiceApiScope | ||
| $GraphServiceApiScope.Value = (Get-AzEnvironment -Name $EnvironmentName).GraphEndpointResourceId + "/.default" |
Copilot
AI
Jan 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential null reference errors if ActiveDirectoryAuthority or GraphEndpointResourceId properties are null. Custom environments may not have these properties configured. Add null checks and provide meaningful error messages if critical properties are missing.
| $ServiceEndpoint.Value = "https://doesnotmatter/" | |
| $Authority.Value = (Get-AzEnvironment -Name $EnvironmentName).ActiveDirectoryAuthority | |
| $BillingServiceApiScope.Value = $DefaultBillingServiceApiScope | |
| $GraphServiceApiScope.Value = (Get-AzEnvironment -Name $EnvironmentName).GraphEndpointResourceId + "/.default" | |
| $environment = Get-AzEnvironment -Name $EnvironmentName | |
| if (-not $environment.ActiveDirectoryAuthority) | |
| { | |
| throw "The ActiveDirectoryAuthority endpoint is not configured for Azure environment '$EnvironmentName'. Configure this property for the environment and try again." | |
| } | |
| if (-not $environment.GraphEndpointResourceId) | |
| { | |
| throw "The GraphEndpointResourceId endpoint is not configured for Azure environment '$EnvironmentName'. Configure this property for the environment and try again." | |
| } | |
| $ServiceEndpoint.Value = "https://doesnotmatter/" | |
| $Authority.Value = $environment.ActiveDirectoryAuthority | |
| $BillingServiceApiScope.Value = $DefaultBillingServiceApiScope | |
| $GraphServiceApiScope.Value = $environment.GraphEndpointResourceId + "/.default" |
| $GraphServiceApiScope.Value = $GraphServiceApiScopeAzureLocal | ||
| } | ||
| elseif ($null -ne (Get-AzEnvironment -Name $EnvironmentName)) | ||
| { |
Copilot
AI
Jan 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hardcoded value 'https://doesnotmatter/' is unclear and potentially confusing. Add a comment explaining why this placeholder URL is used and whether it's actually utilized in the custom environment scenario.
| { | |
| { | |
| # Use a dummy URL for custom Az environments. The Stack HCI service endpoint is not | |
| # resolved from this value in this code path; only the authority and scopes taken | |
| # from Get-AzEnvironment are used for authentication, so the exact URL does not matter. |
| --> | ||
| ## Upcoming Release | ||
| * Improved cloud deployment detection during Azure Arc repair operations to prevent duplicate enablement attempts and ensure smoother deployment experiences. | ||
| * Added ability to register in custom Azure Environments |
Copilot
AI
Jan 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changelog entry should reference the cmdlet affected and explain the impact to users more clearly. According to ChangeLog guidelines (CodingGuidelineID: 1000002), entries should be written from the user's perspective. Consider: 'Added support for registering Stack HCI clusters in custom Azure Environments configured via Add-AzEnvironment'
| $BillingServiceApiScopeAzureLocal = "https://dp.aszrp.$DOMAINFQDNMACRO/.default" | ||
| $GraphServiceApiScopeAzureLocal = "https://graph.$DOMAINFQDNMACRO" | ||
|
|
||
| $DefaultBillingServiceApiScope = "1322e676-dee7-41ee-a874-ac923822781c/.default" |
Copilot
AI
Jan 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The GUID 1322e676-dee7-41ee-a874-ac923822781c is the Azure Stack HCI Usage Service first-party app ID (defined on line 148 as $UsageServiceFirstPartyAppId). Consider using the existing variable for consistency: $DefaultBillingServiceApiScope = \"$UsageServiceFirstPartyAppId/.default\" or add a comment explaining this is intentionally duplicated.
| $DefaultBillingServiceApiScope = "1322e676-dee7-41ee-a874-ac923822781c/.default" | |
| $DefaultBillingServiceApiScope = "$UsageServiceFirstPartyAppId/.default" |
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
Description
This PR adds changes for supporting custom Azure Environments that customers might have added using Add-AzEnvironment
Mandatory Checklist
Please choose the target release of Azure PowerShell. (⚠️ Target release is a different concept from API readiness. Please click below links for details.)
Check this box to confirm: I have read the Submitting Changes section of
CONTRIBUTING.mdand reviewed the following information:ChangeLog.mdfile(s) appropriatelysrc/{{SERVICE}}/{{SERVICE}}/ChangeLog.md.## Upcoming Releaseheader in the past tense.ChangeLog.mdif no new release is required, such as fixing test case only.