使用 Visual Studio Code 中的 Azure 帳戶擴充功能連線到 Azure Stack HubConnect to Azure Stack Hub using Azure Account Extension in Visual Studio Code

在本文中,我們將逐步解說如何使用 Azure 帳戶擴充功能連線到 Azure Stack Hub。In this article, we will walk you through how to connect to Azure Stack Hub using the Azure Account extension. 您必須更新 Visual Studio Code (VS Code) 設定。You will need to update your Visual Studio Code (VS Code) settings.

VS Code 是用於 Web 及雲端應用程式建置和偵錯的輕量級編輯器。VS Code is a light-weight editor for building and debug web and cloud applications. ASP.NET Core、Python、NodeJS、Go 和其他開發人員都會使用 VS Code。ASP.NET Core, Python, NodeJS, Go, and other developers use VS Code. 透過 Azure 帳戶擴充功能,您可以搭配訂用帳戶使用單一 Azure 登入來篩選其他 Azure 擴充功能。With the Azure Account extension, you can use a single Azure sign-in with subscription filtering for additional Azure extensions. 擴充功能可讓您在與 VS Code 整合的終端機中使用 Azure Cloud Shell。The extension makes the Azure Cloud Shell available in the VS Code-integrated terminal. 藉由使用擴充功能,您可以對身分識別管理員使用 Azure AD (Azure AD) 和 Active Directory Federated Services (AD FS) 來連線到 Azure Stack Hub 訂用帳戶。Using the extension, you can connect to your Azure Stack Hub subscription using both Azure AD (Azure AD) and Active Directory Federated Services (AD FS) for your identity manager. 您可以登入 Azure Stack Hub、選取您的訂用帳戶,以及在 Cloud Shell 中開啟新的命令列。You can sign in to Azure Stack Hub, select your subscription, and open a new command line in a cloud shell.

注意

針對 Active Directory Federated Services (AD FS) 環境,您可以使用本文中的步驟。You can use the steps in this article for an Active Directory Federated Services (AD FS) environment. 使用您的 AD FS 認證和端點。Use your AD FS credentials and endpoints.

Azure 帳戶擴充功能的必要條件Pre-requisites for the Azure Account Extension

  1. Azure Stack Hub 環境 1904 組建或更新版本Azure Stack Hub environment 1904 build or later
  2. Visual Studio CodeVisual Studio Code
  3. Azure 帳戶擴充功能Azure Account Extension
  4. Azure Stack Hub 訂用帳戶An Azure Stack Hub subscription

連線到 Azure Stack Hub 的步驟Steps to connect to Azure Stack Hub

  1. 從 GitHub 中的 Azure Stack Hub 工具執行 身分識別 指令碼。Run the Identity script from Azure Stack Hub Tools in GitHub.

    Update-AzsHomeDirectoryTenant -AdminResourceManagerEndpoint $adminResourceManagerEndpoint `
    -DirectoryTenantName $homeDirectoryTenantName -Verbose
    Register-AzsWithMyDirectoryTenant -TenantResourceManagerEndpoint $tenantARMEndpoint `
    -DirectoryTenantName $guestDirectoryTenantName
    
  2. 開啟 VS Code。Open VS Code.

  3. 選取左下角的 [擴充功能] 。Select Extensions on the left-side corner.

  4. 在搜尋方塊中,輸入 Azure AccountIn the search box, enter Azure Account.

  5. 選取 [Azure 帳戶] ,然後選取 [安裝] 。Select Azure Account and select Install.

    Azure Stack Hub Visual Studio Code

  6. 重新啟動 VS Code 以載入擴充功能。Restart VS Code to load the extension.

  7. 擷取中繼資料以連線到 Azure Stack Hub 中的 Azure Resource Manager。Retrieve the metadata to connect to the Azure Resource Manager in your Azure Stack Hub.

    Microsoft Azure Resource Manager 是可讓您部署、管理及監視 Azure 資源的管理架構。The Microsoft Azure Resource Manager is a management framework that allows you to deploy, manage, and monitor Azure resources.

    • Azure Stack 開發套件 (ASDK) 的 Resource Manager URL 為:https://management.local.azurestack.external/The Resource Manager URL for the Azure Stack Development Kit (ASDK) is: https://management.local.azurestack.external/
    • 整合系統中的 Resource Manager URL 為:https://management.region.<fqdn>/,其中 <fqdn> 是完整網域名稱。The Resource Manager URL for an integrated system is: https://management.region.<fqdn>/, where <fqdn> is your fully qualified domain name.
    • 將下列文字新增至您的 URL,以存取中繼資料:<ResourceManagerUrl>/metadata/endpoints?api-version=1.0Add the following text to your URL to access the metadata: <ResourceManagerUrl>/metadata/endpoints?api-version=1.0

    例如,用來擷取您 Azure Resource Manager 端點中繼資料的 URL 可能看起來像:https://management.local.azurestack.external/metadata/endpoints?api-version=1.0For example, the URL to retrieve the metadata for your Azure Resource Manager endpoint may look something like: https://management.local.azurestack.external/metadata/endpoints?api-version=1.0

    記下傳回的 JSON。Make a note of the return JSON. 您需要 loginEndpointaudiences 屬性的值。You will need the values for the loginEndpoint and audiences property.

  8. 按下 Ctrl + Shift + P,然後選取 [喜好設定:開啟使用者設定 (JSON) ]。Press Ctrl+Shift+P, and select Preferences: Open User Settings (JSON).

  9. 在程式碼編輯器中,以您環境中的值來更新下列 JSON 程式碼片段,然後將程式碼片段貼入設定區塊。In the code editor, update the following JSON snippet with the values for your environment, and then paste snippet into the settings block.

    • 值:Values:

      參數Parameter 描述Description
      tenant-ID 您 Azure Stack Hub 租用戶識別碼的值。The value of your Azure Stack Hub tenant ID.
      activeDirectoryEndpointUrl 這是 loginEndpoint 屬性中的 URL。This is the URL from loginEndpoint property.
      activeDirectoryResourceId 這是對象屬性中的 URL。This is the URL from the audiences property.
      resourceManagerEndpointUrl 這是 Azure Stack Hub 的 Azure Resource Manager 根 URL。This is the root URL for the Azure Resource Manager for Azure Stack Hub.
      validateAuthority 如果您使用 Azure AD 作為身分識別管理員,可以省略此參數。You can leave out this parameter if you are using Azure AD as your identity manager. 如果您使用 AD FS,請以的值加入參數 falseAdd the parameter with a value of false if you are using AD FS.
    • JSON 程式碼片段:JSON snippet:

      "azure.tenant": "tenant-ID",
      "azure.ppe": {
          "activeDirectoryEndpointUrl": "Login endpoint",
          "activeDirectoryResourceId": "This is the URL from the audiences property.",
          "resourceManagerEndpointUrl": "Aure Resource Management Endpoint",
          "validateAuthority" : false, 
      },
      "azure.cloud": "AzurePPE"
      
  10. 儲存使用者設定並再次使用 Ctrl + Shift + PSave the User Settings and use Ctrl+Shift+P once again. 選取 azure:登入 Azure 雲端Select Azure: Sign in to Azure Cloud. 新選項 [AzurePPE] 會隨即出現在目標清單中。The new option, AzurePPE, appears in the list of targets.

  11. 選取 [AzurePPE]。Select AzurePPE. 驗證頁面會載入您的瀏覽器中。The authentication page loads in your browser. 登入您的端點。Sign in to your endpoint.

  12. 若要測試您是否已成功登入 Azure Stack Hub 訂用帳戶,請使用 Ctrl + Shift + P ,然後選取 [ Azure:選取訂 用帳戶],並查看您擁有的訂用帳戶是否可用。To test that you have successfully logged into your Azure Stack Hub subscription, use Ctrl+Shift+ P and select Azure: Select Subscription and see if the subscription you have is available.

命令Commands

Azure:登入Azure: Sign In 登入您的 Azure 訂用帳戶:Sign in to your Azure subscription
Azure:使用裝置程式碼登入Azure: Sign In with Device Code 使用裝置代碼登入您的 Azure 訂用帳戶。Sign in to your Azure subscription with a device code. Sign In 命令無法運作時,請在設定中使用裝置程式碼。Use a device code in setups where the Sign In command doesn't work.
Azure:登入 Azure 雲端Azure: Sign In to Azure Cloud 登入其中一個主權雲端中的 Azure 訂用帳戶。Sign in to your Azure subscription in one of the sovereign clouds.
Azure:登出Azure: Sign Out 登出您的 Azure 訂用帳戶。Sign out of your Azure subscription.
Azure:選取訂用帳戶Azure: Select Subscriptions 挑選您想要使用的訂用帳戶集合。Pick the set of subscriptions you want to work with. 擴充功能只會顯示所篩選訂用帳戶內的資源。The extension only shows resources within the filtered subscriptions.
Azure:建立帳戶Azure: Create an Account 如果您沒有 Azure 帳戶,您可以立即註冊一個帳戶,並獲得 $200 的可用額度。If you don't have an Azure Account, you can sign up for one today and receive $200 in free credits.
Azure:在 Cloud Shell 中開啟 BashAzure: Open Bash in Cloud Shell 在 Cloud Shell 中開啟執行 Bash 的新終端機。Open a new terminal running Bash in Cloud Shell.
Azure:在 Cloud Shell 中開啟 PowerShellAzure: Open PowerShell in Cloud Shell 在 Cloud Shell 中開啟執行 PowerShell 的新終端機。Open a new terminal running PowerShell in Cloud Shell.
Azure:上傳至 Cloud ShellAzure: Upload to Cloud Shell 將檔案上傳至 Cloud Shell 儲存體帳戶。Upload a file to your Cloud Shell storage account.

後續步驟Next steps

在 Azure Stack Hub 中設定開發環境Set up a development environment in Azure Stack Hub