Skip to content

Commit 1bff11f

Browse files
Added mandatory ARM endpoints
1 parent 84b4d96 commit 1bff11f

9 files changed

Lines changed: 130 additions & 167 deletions

File tree

ComputeAdmin/AzureStack.ComputeAdmin.psm1

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ Function Add-VMImage{
7676
[Parameter(Mandatory=$true, ParameterSetName='VMImageFromAzure')]
7777
[System.Management.Automation.PSCredential] $azureStackCredentials,
7878

79-
[Parameter(ParameterSetName='VMImageFromLocal')]
80-
[Parameter(ParameterSetName='VMImageFromAzure')]
81-
[string] $ArmEndpoint = 'https://api.local.azurestack.external',
79+
[Parameter(Mandatory=$true, ParameterSetName='VMImageFromLocal')]
80+
[Parameter(Mandatory=$true, ParameterSetName='VMImageFromAzure')]
81+
[string] $ArmEndpoint,
8282

8383
[Parameter(ParameterSetName='VMImageFromLocal')]
8484
[Parameter(ParameterSetName='VMImageFromAzure')]
@@ -312,7 +312,8 @@ Function Remove-VMImage{
312312

313313
[switch] $KeepMarketplaceItem,
314314

315-
[string] $ArmEndpoint = 'https://api.local.azurestack.external'
315+
[Parameter(Mandatory=$true)]
316+
[string] $ArmEndpoint
316317

317318
)
318319

@@ -387,8 +388,8 @@ function New-Server2016VMImage {
387388
[Parameter(ParameterSetName = 'ManualCUPath')]
388389
[string] $CUPath,
389390

390-
[Parameter()]
391-
[string] $ArmEndpoint = 'https://api.local.azurestack.external',
391+
[Parameter(Mandatory)]
392+
[string] $ArmEndpoint,
392393

393394
[Parameter()]
394395
[string] $VHDSizeInMB = 40960,
@@ -765,7 +766,8 @@ Function Get-VMImage{
765766

766767
[System.Management.Automation.PSCredential] $azureStackCredentials,
767768

768-
[string] $ArmEndpoint = 'https://api.local.azurestack.external'
769+
[Parameter(Mandatory=$true)]
770+
[string] $ArmEndpoint
769771

770772
)
771773

@@ -845,9 +847,9 @@ Function Add-VMExtension{
845847
[Parameter(Mandatory=$true, ParameterSetName='VMExtesionFromAzure')]
846848
[System.Management.Automation.PSCredential] $azureStackCredentials,
847849

848-
[Parameter(ParameterSetName='VMExtensionFromLocal')]
849-
[Parameter(ParameterSetName='VMExtesionFromAzure')]
850-
[string] $ArmEndpoint = 'https://adminmanagement.local.azurestack.external'
850+
[Parameter(Mandatory=$true, ParameterSetName='VMExtensionFromLocal')]
851+
[Parameter(Mandatory=$true, ParameterSetName='VMExtesionFromAzure')]
852+
[string] $ArmEndpoint
851853
)
852854

853855
$resourceGroupName = "addvmextresourcegroup"
@@ -959,7 +961,8 @@ Function Remove-VMExtension{
959961
[Parameter(Mandatory=$true)]
960962
[System.Management.Automation.PSCredential] $azureStackCredentials,
961963

962-
[string] $ArmEndpoint = 'https://adminmanagement.local.azurestack.external'
964+
[Parameter(Mandatory=$true)]
965+
[string] $ArmEndpoint
963966
)
964967

965968
$subscription, $headers = (Get-AzureStackAdminSubTokenHeader -TenantId $tenantId -AzureStackCredentials $azureStackCredentials -ArmEndpoint $ArmEndpoint)

ComputeAdmin/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ As a prerequisite, you need to obtain the Windows Server 2016 Evaluation ISO whi
4040
An example usage is the following:
4141
```powershell
4242
$ISOPath = "<Path to ISO>"
43-
New-Server2016VMImage -ISOPath $ISOPath -TenantId $aadTenant
43+
New-Server2016VMImage -ISOPath $ISOPath -TenantId $aadTenant -ArmEndpoint "https://adminmanagement.local.azurestack.external"
4444
```
45+
Please make sure to specify the correct administrator ARM endpoint for your environment.
4546

46-
This command may show a popup prompt that can be ignored without issue.
47+
This command may show a **popup prompt that can be ignored** without issue.
4748

4849
To ensure that the Windows Server 2016 VM Image has the latest cumulative update, provide the -IncludeLatestCU parameter.
4950

Connect/AzureStack.Connect.psm1

Lines changed: 19 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,15 @@ function Get-AzureStackAadTenant {
3636
param (
3737
[parameter(mandatory=$true, HelpMessage="Azure Stack One Node host address or name such as '1.2.3.4'")]
3838
[string] $HostComputer,
39-
[Parameter(HelpMessage="The Admin ARM endpoint of the Azure Stack Environment")]
40-
[string] $ArmEndpoint = 'https://api.local.azurestack.external',
4139
[Parameter(HelpMessage="The Domain suffix of the environment VMs")]
4240
[string] $DomainSuffix = 'azurestack.local',
4341
[parameter(HelpMessage="Administrator user name of this Azure Stack Instance")]
4442
[string] $User = "administrator",
4543
[parameter(mandatory=$true, HelpMessage="Administrator password used to deploy this Azure Stack instance")]
4644
[securestring] $Password
4745
)
48-
49-
$Domain = ""
50-
try {
51-
$uriARMEndpoint = [System.Uri] $ArmEndpoint
52-
$i = $ArmEndpoint.IndexOf('.')
53-
$Domain = ($ArmEndpoint.Remove(0,$i+1)).TrimEnd('/')
54-
}
55-
catch {
56-
Write-Error "The specified ARM endpoint was invalid"
57-
}
5846

59-
if($DomainSuffix){
60-
$Domain = $DomainSuffix
61-
}
47+
$Domain = $DomainSuffix
6248

6349
$UserCred = "$Domain\$User"
6450
$credential = New-Object System.Management.Automation.PSCredential -ArgumentList $UserCred, $Password
@@ -67,13 +53,13 @@ function Get-AzureStackAadTenant {
6753
return Invoke-Command -ComputerName "$HostComputer" -Credential $credential -ScriptBlock `
6854
{
6955
Write-Verbose "Retrieving Azure Stack configuration..." -Verbose
70-
$configFile = Get-ChildItem -Path C:\EceStore -Recurse | ?{-not $_.PSIsContainer} | sort Length -Descending | select -First 1
56+
$configFile = Get-ChildItem -Path C:\EceStore -Recurse | Where-Object {-not $_.PSIsContainer} | Sort-Object Length -Descending | Select-Object -First 1
7157
$customerConfig = [xml] (Get-Content -Path $configFile.FullName)
7258

7359
$Parameters = $customerConfig.CustomerConfiguration
74-
$fabricRole = $Parameters.Role.Roles.Role | ?{$_.Id -eq "Fabric"}
60+
$fabricRole = $Parameters.Role.Roles.Role | Where-Object {$_.Id -eq "Fabric"}
7561
$allFabricRoles = $fabricRole.Roles.ChildNodes
76-
$idProviderRole = $allFabricRoles | ?{$_.Id -eq "IdentityProvider"}
62+
$idProviderRole = $allFabricRoles | Where-Object {$_.Id -eq "IdentityProvider"}
7763
$idProviderRole.PublicInfo.AADTenant.Id
7864
}
7965
}
@@ -88,10 +74,10 @@ function Add-AzureStackAzureRmEnvironment {
8874
param (
8975
[parameter(mandatory=$true, HelpMessage="AAD Tenant name or ID used when deploying Azure Stack such as 'mydirectory.onmicrosoft.com'")]
9076
[string] $AadTenant,
91-
[Parameter(HelpMessage="The Admin ARM endpoint of the Azure Stack Environment")]
92-
[string] $ArmEndpoint = 'https://api.local.azurestack.external',
93-
[parameter(HelpMessage="Azure Stack environment name for use with AzureRM commandlets")]
94-
[string] $Name = "AzureStack"
77+
[Parameter(mandatory=$true, HelpMessage="The Admin ARM endpoint of the Azure Stack Environment")]
78+
[string] $ArmEndpoint,
79+
[parameter(mandatory=$true, HelpMessage="Azure Stack environment name for use with AzureRM commandlets")]
80+
[string] $Name
9581
)
9682

9783
if(!$ARMEndpoint.Contains('https://')){
@@ -164,8 +150,6 @@ function Get-AzureStackNatServerAddress {
164150
param (
165151
[parameter(mandatory=$true, HelpMessage="Azure Stack One Node host address or name such as '1.2.3.4'")]
166152
[string] $HostComputer,
167-
[Parameter(HelpMessage="The Admin ARM endpoint of the Azure Stack Environment")]
168-
[string] $ArmEndpoint = 'https://api.local.azurestack.external',
169153
[Parameter(HelpMessage="The Domain suffix of the environment VMs")]
170154
[string] $DomainSuffix = 'azurestack.local',
171155
[parameter(HelpMessage="NAT computer name in this Azure Stack Instance")]
@@ -176,19 +160,7 @@ function Get-AzureStackNatServerAddress {
176160
[securestring] $Password
177161
)
178162

179-
$Domain = ""
180-
try {
181-
$uriARMEndpoint = [System.Uri] $ArmEndpoint
182-
$i = $ArmEndpoint.IndexOf('.')
183-
$Domain = ($ArmEndpoint.Remove(0,$i+1)).TrimEnd('/')
184-
}
185-
catch {
186-
Write-Error "The specified ARM endpoint was invalid"
187-
}
188-
189-
if($DomainSuffix){
190-
$Domain = $DomainSuffix
191-
}
163+
$Domain = $DomainSuffix
192164

193165
$UserCred = "$Domain\$User"
194166
$credential = New-Object System.Management.Automation.PSCredential -ArgumentList $UserCred, $Password
@@ -202,7 +174,7 @@ function Get-AzureStackNatServerAddress {
202174
Invoke-Command -ComputerName "$using:nat" -Credential $using:credential -ScriptBlock `
203175
{
204176
Write-Verbose "Obtaining external IP..." -Verbose
205-
Get-NetIPConfiguration | ? { $_.IPv4DefaultGateway -ne $null } | foreach { $_.IPv4Address.IPAddress }
177+
Get-NetIPConfiguration | Where-Object { $_.IPv4DefaultGateway -ne $null } | ForEach-Object { $_.IPv4Address.IPAddress }
206178
}
207179
}
208180
}
@@ -257,8 +229,6 @@ function Connect-AzureStackVpn {
257229
param (
258230
[parameter(HelpMessage="Azure Stack VPN Connection Name such as 'my-poc'")]
259231
[string] $ConnectionName = "azurestack",
260-
[Parameter(HelpMessage="The Admin ARM endpoint of the Azure Stack Environment")]
261-
[string] $ArmEndpoint = 'https://api.local.azurestack.external',
262232
[Parameter(HelpMessage="The Domain suffix of the environment VMs")]
263233
[string] $DomainSuffix = 'azurestack.local',
264234
[parameter(HelpMessage="Certificate Authority computer name in this Azure Stack Instance")]
@@ -268,21 +238,8 @@ function Connect-AzureStackVpn {
268238
[parameter(mandatory=$true, HelpMessage="Administrator password used to deploy this Azure Stack instance")]
269239
[securestring] $Password
270240
)
271-
272-
$Domain = ""
273-
try {
274-
$uriARMEndpoint = [System.Uri] $ArmEndpoint
275-
$i = $ArmEndpoint.IndexOf('.')
276-
$Domain = ($ArmEndpoint.Remove(0,$i+1)).TrimEnd('/')
277-
}
278-
catch {
279-
Write-Error "The specified ARM endpoint was invalid"
280-
}
281-
282241

283-
if($DomainSuffix){
284-
$Domain = $DomainSuffix
285-
}
242+
$Domain = $DomainSuffix
286243

287244
Write-Verbose "Connecting to Azure Stack VPN using connection named $ConnectionName..." -Verbose
288245

@@ -335,16 +292,16 @@ Export-ModuleMember Connect-AzureStackVpn
335292
function Get-AzureStackAdminSubTokenHeader {
336293
param (
337294
[parameter(HelpMessage="Name of the Azure Stack Environment")]
338-
[string] $EnvironmentName = "AzureStack",
295+
[string] $EnvironmentName = "AzureStackAdmin",
339296

340297
[parameter(mandatory=$true, HelpMessage="TenantID of Identity Tenant")]
341298
[string] $tenantID,
342299

343300
[parameter(HelpMessage="Credentials to retrieve token header for")]
344301
[System.Management.Automation.PSCredential] $azureStackCredentials,
345302

346-
[Parameter(HelpMessage="The administration ARM endpoint of the Azure Stack Environment")]
347-
[string] $ArmEndpoint = 'https://api.local.azurestack.external'
303+
[Parameter(mandatory=$true, HelpMessage="The administration ARM endpoint of the Azure Stack Environment")]
304+
[string] $ArmEndpoint
348305
)
349306

350307
if(-not $azureStackCredentials){
@@ -380,15 +337,15 @@ function Get-AzureStackAdminSubTokenHeader {
380337

381338
$subscriptionName = "Default Provider Subscription"
382339

383-
if (-not (Get-AzureRmEnvironment -Name AzureStack -ErrorAction SilentlyContinue)){
384-
Add-AzureStackAzureRmEnvironment -AadTenant $tenantID -ArmEndpoint $ArmEndpoint | Out-Null
340+
if (-not (Get-AzureRmEnvironment -Name $EnvironmentName -ErrorAction SilentlyContinue)){
341+
Add-AzureStackAzureRmEnvironment -AadTenant $tenantID -ArmEndpoint $ArmEndpoint -Name $EnvironmentName | Out-Null
385342
}
386343

387-
$azureStackEnvironment = Get-AzureRmEnvironment -Name AzureStack -ErrorAction SilentlyContinue
344+
$azureStackEnvironment = Get-AzureRmEnvironment -Name $EnvironmentName -ErrorAction SilentlyContinue
388345
$authority = $azureStackEnvironment.ActiveDirectoryAuthority
389346
$activeDirectoryServiceEndpointResourceId = $azureStackEnvironment.ActiveDirectoryServiceEndpointResourceId
390347

391-
Login-AzureRmAccount -EnvironmentName "AzureStack" -TenantId $tenantID -Credential $azureStackCredentials | Out-Null
348+
Login-AzureRmAccount -EnvironmentName $EnvironmentName -TenantId $tenantID -Credential $azureStackCredentials | Out-Null
392349

393350
try {
394351
$subscription = Get-AzureRmSubscription -SubscriptionName $subscriptionName
@@ -430,7 +387,7 @@ function Get-AADTenantGUID () {
430387
)
431388
$ADauth = (Get-AzureRmEnvironment -Name $AzureCloud).ActiveDirectoryAuthority
432389
$endpt = "{0}{1}/.well-known/openid-configuration" -f $ADauth, $AADTenantName
433-
$OauthMetadata = (wget -UseBasicParsing $endpt).Content | ConvertFrom-Json
390+
$OauthMetadata = (Invoke-WebRequest -UseBasicParsing $endpt).Content | ConvertFrom-Json
434391
$AADid = $OauthMetadata.Issuer.Split('/')[3]
435392
$AADid
436393
}

Connect/README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,31 +70,32 @@ See the [Azure Stack Install PowerShell](https://docs.microsoft.com/en-us/azure/
7070

7171
AzureRM cmdlets can be targeted at multiple Azure clouds such as Azure China, Government, and Azure Stack.
7272

73-
To retrieve your Azure Active Directory Tenant ID (this will be a GUID value), do the following:
73+
Connecting requires that you obtain the GUID value of your Directory Tenant. If you know the non-GUID form of the Azure Active Directory Tenant used to deploy your Azure Stack instance, you can retrieve the GUID value with the following:
7474

75-
First, make sure that your host is added to the list of trusted hosts:
7675
```powershell
77-
Set-Item wsman:\localhost\Client\TrustedHosts -Value "<Azure Stack host address>" -Concatenate
76+
$aadTenant = Get-AADTenantGUID -AADTenantName "<myaadtenant>.onmicrosoft.com"
7877
```
7978

79+
Otherwise, your home directory can be retrieved directly from your Azure Stack deployment. This method can also be used for AD FS. First, add your host to the list of TrustedHosts:
80+
```powershell
81+
Set-Item wsman:\localhost\Client\TrustedHosts -Value "<Azure Stack host address>" -Concatenate
82+
```
8083
Then execute the following:
8184
```powershell
8285
$Password = ConvertTo-SecureString "<Admin password provided when deploying Azure Stack>" -AsPlainText -Force
8386
$AadTenant = Get-AzureStackAadTenant -HostComputer <Host IP Address> -Password $Password
8487
```
8588

86-
The AadTenant parameter specifies the directory that was used when deploying Azure Stack.
87-
88-
To target your Azure Stack instance, an AzureRM environment needs to be registered as follows. This will give you access to the administrative portal.
89+
To target your Azure Stack instance as a tenant, an AzureRM environment needs to be registered as follows. The ARM endpoint below is the tenant default for a one-node environment.
8990

9091
```powershell
91-
Add-AzureStackAzureRmEnvironment -AadTenant $AadTenant
92+
Add-AzureStackAzureRmEnvironment -Name AzureStack -ArmEndpoint "https://management.local.azurestack.external" -AadTenant $aadTenant
9293
```
9394

94-
To get access to the tenant portal, run the following instead:
95+
To create an administrator environment use the below. The ARM endpoint below is the administrator default for a one-node environment.
9596

9697
```powershell
97-
Add-AzureStackAzureRmEnvironment -Name AzureStackTenant -ArmEndpoint "https://publicapi.local.azurestack.external" -AadTenant $aadTenant
98+
Add-AzureStackAzureRmEnvironment -Name AzureStackAdmin -ArmEndpoint "https://adminmanagement.local.azurestack.external" -AadTenant $aadTenant
9899
```
99100

100101
After registering the AzureRM environment, cmdlets can be easily targeted at your Azure Stack instance. For example:
@@ -103,10 +104,10 @@ After registering the AzureRM environment, cmdlets can be easily targeted at you
103104
Login-AzureRmAccount -EnvironmentName "AzureStack" -TenantId $AadTenant
104105
```
105106

106-
Similarly, for the tenant portal:
107+
Similarly, for targeting the administrator endpoints:
107108

108109
```powershell
109-
Login-AzureRmAccount -EnvironmentName "AzureStackTenant" -TenantId $AadTenant
110+
Login-AzureRmAccount -EnvironmentName "AzureStackAdmin" -TenantId $AadTenant
110111
```
111112

112113
## Register Azure RM Providers on new subscriptions

Connect/Tests/Connect.Tests.ps1

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ InModuleScope $script:ModuleName {
7070

7171
Describe 'ConnectModule - Accessing Environment Data' {
7272
It 'Recovered AAD Tenant ID should be correct' {
73-
$global:AadTenantID = Get-AzureStackAadTenant -HostComputer $HostComputer -ArmEndpoint $armEndpoint -User $AdminUser -Password $AdminPassword
73+
$global:AadTenantID = Get-AzureStackAadTenant -HostComputer $HostComputer -User $AdminUser -Password $AdminPassword
7474
Write-Verbose "Aad Tenant ID is $global:AadTenantID" -Verbose
7575
$global:AadTenantID | Should Not Be $null
7676
}
7777

7878
It 'Get-AzureStackNatServerAddress should return valid NAT address' {
79-
$script:NatIPAddress = Get-AzureStackNatServerAddress -natServer $natServer -HostComputer $HostComputer -ArmEndpoint $armEndpoint -User $AdminUser -Password $AdminPassword
79+
$script:NatIPAddress = Get-AzureStackNatServerAddress -natServer $natServer -HostComputer $HostComputer -User $AdminUser -Password $AdminPassword
8080
Write-Verbose "Returned NAT IP Address of $natIPAddress" -Verbose
8181
[IPAddress]$script:NatIPAddress | Should Not Be $null
8282
}
@@ -87,19 +87,19 @@ InModuleScope $script:ModuleName {
8787
}
8888

8989
It 'Connect-AzureStackVpn should successfully connect to a One Node environment' {
90-
{Connect-AzureStackVpn -ConnectionName $VPNConnectionName -User $AdminUser -ArmEndpoint $armEndpoint -Password $AdminPassword} | Should Not Throw
90+
{Connect-AzureStackVpn -ConnectionName $VPNConnectionName -User $AdminUser -Password $AdminPassword} | Should Not Throw
9191
}
9292

93-
It 'Add-AzureStackAzureRmEnvironment should successfully add a One Node environment' {
94-
Remove-AzureRmEnvironment -Name "AzureStack" -ErrorAction SilentlyContinue -Force
95-
Add-AzureStackAzureRmEnvironment -AadTenant $global:AadTenantID -ArmEndpoint $armEndpoint
96-
Get-AzureRmEnvironment -Name "AzureStack" | Should Not Be $null
93+
It 'Add-AzureStackAzureRmEnvironment should successfully add a an administrator environment' {
94+
Remove-AzureRmEnvironment -Name "AzureStackAdmin" -ErrorAction SilentlyContinue
95+
Add-AzureStackAzureRmEnvironment -AadTenant $global:AadTenantID -ArmEndpoint $armEndpoint -Name "AzureStackAdmin"
96+
Get-AzureRmEnvironment -Name "AzureStackAdmin" | Should Not Be $null
9797
}
9898

9999
It 'User should be able to login to environment successfully created by Add-AzureStackAzureRmEnvironment' {
100100
Write-Verbose "Aad Tenant ID is $global:AadTenantID" -Verbose
101101
Write-Verbose "Passing credential to Login-AzureRmAccount" -Verbose
102-
{Login-AzureRmAccount -EnvironmentName "AzureStack" -TenantId $global:AadTenantID -Credential $global:AzureStackLoginCredentials} | Should Not Throw
102+
{Login-AzureRmAccount -EnvironmentName "AzureStackAdmin" -TenantId $global:AadTenantID -Credential $global:AzureStackLoginCredentials} | Should Not Throw
103103
}
104104

105105
It 'User should be able to list resource groups successfully in connected Azure Stack' {

0 commit comments

Comments
 (0)