Azure Stack Hub Development Kit の Azure 登録解除

3 minute read

はじめに

Azure Stack Hub Development Kit (ASDK) の再インストールについてです。 ASDK は、Azure Stack Hub の POC バージョンで、シングルノードにインストールして利用することができます。POC 用途になるので、バージョンアップなどを実施することができず、新しいバージョンで再インストールする必要があります。
今回は、Azure に登録した ASDK の情報を削除する方法をご紹介します。

Azure Stack Hub 用 AZ Powershell のインストール

Azure Stack Hub には専用の Powershell が準備されています。Azure Stack Hub の登録や削除に利用しますので、az モジュールをインストールします。

もし AzureRM Powershell モジュールがインストールされている場合は、AzureRM コマンド用の手順が別にあります。そちらを参照してください。

AZ Powershell をインストールしたい場合は、下記のコマンドよりインストールが可能です。

Azure Stack Hub Tools の準備

まず、ASDK を Azure に登録した際にも利用した Azure Stack Hub Tool のダウンロードを実施します。

# Change directory to the root directory.
cd \

# Download the tools archive.
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 
invoke-webrequest https://github.com/Azure/AzureStack-Tools/archive/az.zip -OutFile az.zip

# Expand the downloaded files.
expand-archive az.zip -DestinationPath . -Force

# Change to the tools directory.
cd AzureStack-Tools-az

Github からダウンロードした後、Azure Stack Hub Tools の AZ モジュールは下記のように配置されます。

PS C:\AzureStack-Tools-az> ls


    Directory: C:\AzureStack-Tools-az


Mode                LastWriteTime         Length Name                                                                                                          
----                -------------         ------ ----                                                                                                          
d-----         1/2/2021   4:08 AM                CloudCapabilities                                                                                             
d-----         1/2/2021   4:08 AM                Connect                                                                                                       
d-----         1/2/2021   4:08 AM                DatacenterIntegration                                                                                         
d-----         1/2/2021   4:08 AM                Deployment                                                                                                    
d-----         1/2/2021   4:08 AM                Identity                                                                                                      
d-----         1/2/2021   4:08 AM                Policy                                                                                                        
d-----         1/2/2021   4:08 AM                Registration                                                                                                  
d-----         1/2/2021   4:08 AM                Support                                                                                                       
d-----         1/2/2021   4:08 AM                Syndication                                                                                                   
d-----         1/2/2021   4:08 AM                TemplateValidator                                                                                             
d-----         1/2/2021   4:08 AM                ToolTestingUtils                                                                                              
d-----         1/2/2021   4:08 AM                Usage                                                                                                         
-a----        10/9/2020   1:41 PM            397 CONTRIBUTING.md                                                                                               
-a----        10/9/2020   1:41 PM           1075 LICENSE.txt                                                                                                   
-a----        10/9/2020   1:41 PM           7794 README.md                                                                                                     
-a----        10/9/2020   1:41 PM           5432 ThirdPartyNotices.txt                                                                                       

Azure 登録の削除

先ほどダウンロードした Azure Stack Hub Tools - AZ を利用して、Azure に登録した Azure Stack の情報を削除します。

#Import the registration module that was downloaded with the GitHub tools
Import-Module C:\AzureStack-Tools-az\Registration\RegisterWithAzure.psm1

# Provide Azure subscription admin credentials
Add-AzAccount

# Provide ASDK admin credentials
$CloudAdminCred = Get-Credential -UserName AZURESTACK\CloudAdmin -Message "Enter the cloud domain credentials to access the privileged endpoint"

# Unregister Azure Stack
Remove-AzsRegistration `
   -PrivilegedEndpointCredential $CloudAdminCred `
   -PrivilegedEndpoint AzS-ERCS01
   -RegistrationName $RegistrationName

# Remove the Azure Stack resource group
Remove-AzResourceGroup -Name azurestack -Force

$RegistrationName について

Azure Stack Hub の登録を削除する際に指定する $RegistrationName ですが、Azure Stack Hub Admin ポータルから確認することができます。

Registration Name コマンド発行後に RegistrationName を指定できますので、RegistrationName に登録名を記載してください。

Remove-AzResourceGroup コマンドでエラーになる

ロックの設定値が残っていることで、リソースグループを削除できない状況になっているようです。

Azure ポータルから azurestack リソースグループに移動し、ロックを削除するこで、コマンドからリソースグループの削除が可能になります。

Azure AD に Application 登録された Azure Stack Hub オブジェクトの削除

何度も ASDK をインストールすると、Azure AD にアプリケーション登録されたオブジェクトが複数存在します。

Azure のクラウドシェル (Powershell) から下記コマンドを実行するだけで、簡単に Azure Stac Hub に関する 登録された アプリケーションオブジェクトを削除できます。 GUI から1つ1つ削除するのはかなり面倒なので、クラウドシェルから削除してみてください。

  1. クラウドシェルを起動して、AAD に接続します。
     Connect-AzureAD
    
  2. アプリケーション登録された Azure Stack Hub のオブジェクトを削除します。
     Get-AzureADApplication -SearchString "Azure Stack" | Remove-AzureADApplication
    
  3. Azure Stack Hub の登録されたオブジェクトが削除されたか確認します。
     Get-AzureADApplication -SearchString "Azure Stack"
    

ここまで完了すれば、キレイに Azure Stack のリソースを削除できたことになります。新しいバージョンの ASDK をインストールしてください!