Skip to content

Conversation

@prateekprshr-nith
Copy link
Member

Description

This PR adds changes for supporting custom Azure Environments that customers might have added using Add-AzEnvironment

Mandatory Checklist

  • SHOULD update ChangeLog.md file(s) appropriately
    • Update src/{{SERVICE}}/{{SERVICE}}/ChangeLog.md.
      • A snippet outlining the change(s) made in the PR should be written under the ## Upcoming Release header in the past tense.
    • Should not change ChangeLog.md if no new release is required, such as fixing test case only.
  • SHOULD regenerate markdown help files if there is cmdlet API change. Instruction
  • SHOULD have proper test coverage for changes in pull request.
  • SHOULD NOT adjust version of module manually in pull request

Copilot AI review requested due to automatic review settings January 16, 2026 12:42
@azure-client-tools-bot-prd
Copy link

Thanks for your contribution! The pull request validation has started. Please revisit this comment for updated status.

Copy link
Contributor

Copilot AI left a 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-AzEnvironment when 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

Comment on lines +724 to +726
elseif ($null -ne (Get-AzEnvironment -Name $EnvironmentName))
{
$managementUrl = (Get-AzEnvironment -Name $EnvironmentName).ResourceManagerUrl
Copy link

Copilot AI Jan 16, 2026

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) { ... }

Suggested change
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

Copilot uses AI. Check for mistakes.
Comment on lines +1027 to 1033
elseif ($null -ne (Get-AzEnvironment -Name $EnvironmentName))
{
$managementUrl = (Get-AzEnvironment -Name $EnvironmentName).ResourceManagerUrl
}
else
{
throw "Invalid Azure Environment name"
Copy link

Copilot AI Jan 16, 2026

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.

Suggested change
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"
}

Copilot uses AI. Check for mistakes.
}
elseif ($null -ne (Get-AzEnvironment -Name $EnvironmentName))
{
return (Get-AzEnvironment -Name $EnvironmentName).ManagementPortalUrl
Copy link

Copilot AI Jan 16, 2026

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.

Copilot uses AI. Check for mistakes.
Comment on lines +1339 to +1342
$ServiceEndpoint.Value = "https://doesnotmatter/"
$Authority.Value = (Get-AzEnvironment -Name $EnvironmentName).ActiveDirectoryAuthority
$BillingServiceApiScope.Value = $DefaultBillingServiceApiScope
$GraphServiceApiScope.Value = (Get-AzEnvironment -Name $EnvironmentName).GraphEndpointResourceId + "/.default"
Copy link

Copilot AI Jan 16, 2026

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.

Suggested change
$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"

Copilot uses AI. Check for mistakes.
$GraphServiceApiScope.Value = $GraphServiceApiScopeAzureLocal
}
elseif ($null -ne (Get-AzEnvironment -Name $EnvironmentName))
{
Copy link

Copilot AI Jan 16, 2026

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.

Suggested change
{
{
# 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.

Copilot uses AI. Check for mistakes.
-->
## 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
Copy link

Copilot AI Jan 16, 2026

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'

Copilot generated this review using guidance from repository custom instructions.
$BillingServiceApiScopeAzureLocal = "https://dp.aszrp.$DOMAINFQDNMACRO/.default"
$GraphServiceApiScopeAzureLocal = "https://graph.$DOMAINFQDNMACRO"

$DefaultBillingServiceApiScope = "1322e676-dee7-41ee-a874-ac923822781c/.default"
Copy link

Copilot AI Jan 16, 2026

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.

Suggested change
$DefaultBillingServiceApiScope = "1322e676-dee7-41ee-a874-ac923822781c/.default"
$DefaultBillingServiceApiScope = "$UsageServiceFirstPartyAppId/.default"

Copilot uses AI. Check for mistakes.
@isra-fel
Copy link
Member

/azp run

@azure-pipelines
Copy link
Contributor

Azure Pipelines successfully started running 3 pipeline(s).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants