Azure Arc を使用して VMware vCenter に仮想マシンを作成する方法

この記事では、Azure portal から vCenter リソースを使用して VM をプロビジョニングする方法について説明します。

Azure portal で VM を作成する

管理者が VMware vCenter を Azure に接続し、Azure で VMware vCenter リソースを表現し、それらのリソースに対するアクセス許可を付与したら、仮想マシンを作成します。

前提条件

  • Arc VMware VM 共同作成者の役割を持つ、Azure サブスクリプションとリソース グループ。
  • Arc プライベート クラウド リソース ユーザー ロールが設定されているリソース プール/クラスター/ホスト。
  • Arc プライベート クラウド リソース ユーザー ロールが設定されている仮想マシン テンプレートのリソース。
  • Arc プライベート クラウド リソース ユーザー ロールが設定されている仮想ネットワーク リソース。

Azure portal で VM を作成するには、次の手順に従います。

  1. お使いのブラウザーで Azure portal に移動します。 仮想マシン参照ビューに移動します。 Azure と Arc 仮想マシンを統一したブラウザが表示されます。

    Azure と Arc 仮想マシンの統一された参照エクスペリエンスを示すスクリーンショット。

  2. [追加] を選択し、ドロップダウン メニューから [Azure Arc マシン] を選びます。

    Azure Arc 仮想マシンを作成するための [基本] タブを示すスクリーンショット。

  3. VM をデプロイするサブスクリプションリソース グループを選びます。

  4. 仮想マシン名を指定し、管理者が共有しているカスタムの場所を選びます。

    複数の種類の VM がサポートされている場合は、[仮想マシンの種類] ドロップダウンから [VMware] を選択します。

  5. VM をデプロイする [リソースプール/クラスター/ホスト] を選択します。

  6. ストレージに使用するデータストアを選択します。

  7. VM の作成に基づいてテンプレートを選択します。

    ヒント

    CPU コアメモリのテンプレートの既定値を上書きできます。

    Windows テンプレートを選んだ場合は、管理者アカウントユーザー名パスワードを入力します。

  8. (オプション)テンプレートで構成されているディスクを変更します。 たとえば、ディスクを追加したり、既存のディスクを更新したりすることができます。 すべてのディスクと VM は、手順 6 で選択したデータストアに配置されます。

  9. (オプション)テンプレートで構成されているネットワーク インターフェイスを変更します。 たとえば、ネットワーク インターフェイス (NIC) カードを追加したり、既存の NIC を更新したりできます。 ネットワーク リソースに対して適切なアクセス許可がある場合は、この NIC がアタッチされるネットワークを変更することもできます。

  10. (省略可能) 必要に応じて、VM リソースにタグを追加します。

  11. すべてのプロパティをレビューした後、[作成] を選択します。 VM の作成には数分かかります。

この記事では、Bicep テンプレートを使う vCenter リソースを使用して VM をプロビジョニングする方法について説明します。

Bicep テンプレートを使用して Arc VMware マシンを作成する

次の bicep テンプレートを使用して、Arc VMware マシンを作成できます。 こちらは、Arc 対応 VMware リソース用に使用できる Azure Resource Manager (ARM)、Bicep、Terraform テンプレートの一覧です。 他の Arc 操作をトリガーするには、対応する ARM テンプレートを Bicep テンプレートに変換します。

// Parameters
param vmName string = 'contoso-vm'
param vmAdminPassword string = 'examplepassword!#'
param vCenterId string = '/subscriptions/01234567-0123-0123-0123-0123456789ab/resourceGroups/contoso-rg/providers/Microsoft.ConnectedVMwarevSphere/vcenters/contoso-vcenter'
param templateId string = '/subscriptions/01234567-0123-0123-0123-0123456789ab/resourceGroups/contoso-rg/providers/Microsoft.ConnectedVMwarevSphere/VirtualMachineTemplates/contoso-template-win22'
param resourcePoolId string = '/subscriptions/01234567-0123-0123-0123-0123456789ab/resourceGroups/contoso-rg/providers/Microsoft.ConnectedVMwarevSphere/ResourcePools/contoso-respool'
param datastoreId string = '/subscriptions/01234567-0123-0123-0123-0123456789ab/resourceGroups/contoso-rg/providers/Microsoft.ConnectedVMwarevSphere/Datastores/contoso-datastore'
param networkId string = '/subscriptions/01234567-0123-0123-0123-0123456789ab/resourceGroups/contoso-rg/providers/Microsoft.ConnectedVMwarevSphere/VirtualNetworks/contoso-network'
param extendedLocation object = {
  type: 'customLocation'
  name: '/subscriptions/01234567-0123-0123-0123-0123456789ab/resourceGroups/contoso-rg/providers/Microsoft.ExtendedLocation/customLocations/contoso-customlocation'
}
param ipSettings object = {
  allocationMethod: 'static'
  gateway: ['172.24.XXX.1']
  ipAddress: '172.24.XXX.105'
  subnetMask: '255.255.255.0'
  dnsServers: ['172.24.XXX.9']
}

resource contosoMachine 'Microsoft.HybridCompute/machines@2023-10-03-preview' = {
  name: vmName
  location:'westeurope'
  kind:'VMware'
  properties:{}
  tags: {
    foo: 'bar'
  }
}

resource vm 'Microsoft.ConnectedVMwarevSphere/virtualMachineInstances@2023-12-01' = {
  name: 'default'
  scope: contosoMachine
  extendedLocation: extendedLocation
  properties: {
    hardwareProfile: {
      memorySizeMB: 4096
      numCPUs: 2
    }
    osProfile: {
      computerName: vmName
      adminPassword: vmAdminPassword
    }
    placementProfile: {
      resourcePoolId: resourcePoolId
      datastoreId: datastoreId
    }
    infrastructureProfile: {
      templateId: templateId
      vCenterId: vCenterId
    }
    networkProfile: {
      networkInterfaces: [
        {
          nicType: 'vmxnet3'
          ipSettings: ipSettings
          networkId: networkId
          name: 'VLAN103NIC'
          powerOnBoot: 'enabled'
        }
      ]
    }
  }
}

// Outputs
output vmId string = vm.id

この記事では、Terraform テンプレートを使う vCenter リソースを使用して VM をプロビジョニングする方法について説明します。

Terraform を使用して Arc VMware マシンを作成する

前提条件

  • Azure サブスクリプション: アクティブな Azure サブスクリプションがあることを確認します。
  • Terraform: Terraform をマシンにインストールします。
  • Azure CLI: Azure CLI をインストールして、リソースを認証および管理します。

Terraform を使用して Arc VMware マシンを作成するには、次の手順に従います。 この記事では、次の 2 つのシナリオについて説明します。

  1. vCenter インベントリで検出された VM の場合は、Azure の操作で有効化を実行し、Arc エージェントをインストールします。
  2. テンプレート、リソース共有元、データストアを使用して新しい Arc VMware VM を作成し、Arc エージェントをインストールします。

シナリオ 1

vCenter インベントリで検出された VM の場合は、Azure の操作で有効化を実行し、Arc エージェントをインストールします。

手順 1: variables.tf ファイルで変数を定義する

variables.tf という名前のファイルを作成し、必要な変数をすべて定義します。

variable "subscription_id" {
  description = "The subscription ID for the Azure account."
  type        = string
}

variable "resource_group_name" {
  description = "The name of the resource group."
  type        = string
}

variable "location" {
  description = "The location/region where the resources will be created."
  type        = string
}

variable "machine_name" {
  description = "The name of the machine."
  type        = string
}

variable "inventory_item_id" {
  description = "The ID of the Inventory Item for the VM."
  type        = string
}

variable "custom_location_id" {
  description = "The ID of the custom location."
  type        = string
}

variable "vm_username" {
  description = "The admin username for the VM."
  type        = string
}

variable "vm_password" {
  description = "The admin password for the VM."
  type        = string
}

variable "resource_group_name" {
  description = "The name of the resource group."
  type        = string
}

variable "location" {
  description = "The location/region where the resources will be created."
  type        = string
}

variable "machine_name" {
  description = "The name of the machine."
  type        = string
}

variable "vm_username" {
  description = "The admin username for the VM."
  type        = string
}

variable "vm_password" {
  description = "The admin password for the VM."
  type        = string
}

variable "inventory_id" {
  description = "The Inventory ID for the VM."
  type        = string
}

variable "vcenter_id" {
  description = "The ID of the vCenter."
  type        = string
}

variable "custom_location_id" {
  description = "The ID of the custom location."
  type        = string
}

手順 2: tfvars ファイルを作成する

CreateVMwareVM.tfvars という名前のファイルを作成し、変数のサンプル値を指定します。

subscription_id      = "your-subscription-id"
resource_group_name  = "your-resource-group"
location             = "eastus"
machine_name         = "test_machine0001"
inventory_item_id    = "/subscriptions/your-subscription-id/resourceGroups/your-resource-group/providers/Microsoft.ConnectedVMwarevSphere/VCenters/your-vcenter-id/InventoryItems/your-inventory-item-id"
custom_location_id   = "/subscriptions/your-subscription-id/resourceGroups/your-resource-group/providers/Microsoft.ExtendedLocation/customLocations/your-custom-location-id"
vm_username          = "Administrator"
vm_password          = " The admin password for the VM "

手順 3: 変数を使用するように構成を変更する

main.tf という名前のファイルを作成し、次のコードを挿入します。

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = ">= 3.0"
    }
    azapi = {
      source  = "azure/azapi"
      version = ">= 1.0.0"
    }
  }
}

# Configure the AzureRM provider with the subscription ID
provider "azurerm" {
  features {}
  subscription_id = var.subscription_id
}

# Configure the AzAPI provider with the subscription ID
provider "azapi" {
  subscription_id = var.subscription_id
}

# Retrieve the resource group details
data "azurerm_resource_group" "example" {
  name = var.resource_group_name
}

# Create a VMware machine resource in Azure
resource "azapi_resource" "test_machine0001" {
  schema_validation_enabled = false
  parent_id = data.azurerm_resource_group.example.id
  type = "Microsoft.HybridCompute/machines@2023-06-20-preview"
  name = var.machine_name
  location = data.azurerm_resource_group.example.location
  body = jsonencode({
      kind = "VMware"
      identity = {
        type = "SystemAssigned"
      }
  })
}

# Create a Virtual Machine instance using the VMware machine and Inventory Item ID
resource "azapi_resource" "test_inventory_vm0001" {
  schema_validation_enabled = false
  type = "Microsoft.ConnectedVMwarevSphere/VirtualMachineInstances@2023-10-01"
  name = "default"
  parent_id = azapi_resource.test_machine0001.id
  body = jsonencode({
      properties = {
          infrastructureProfile = {
            inventoryItemId = var.inventory_item_id
          }
      }
      extendedLocation = {
        type = "CustomLocation"
        name = var.custom_location_id
      }
  })
  depends_on = [azapi_resource.test_machine0001]
}

# Install Arc agent on the VM
resource "azapi_resource" "guestAgent" {
  type      = "Microsoft.ConnectedVMwarevSphere/virtualMachineInstances/guestAgents@2023-10-01"
  parent_id = azapi_resource.test_inventory_vm0001.id
  name      = "default"
  body = jsonencode({
    properties = {
      credentials = {
        username = var.vm_username
        password = var.vm_password
      }
      provisioningAction = "install"
    }
  })
  schema_validation_enabled = false
  ignore_missing_property   = false
  depends_on = [azapi_resource.test_inventory_vm0001]
}

手順 4: Terraform コマンドを実行する

-var- ファイル フラグを使用して、Terraform コマンド実行時に .tfvars ファイルを渡します。

  1. Terraform を初期化します (まだ初期化されていない場合): terraform init
  2. 構成を検証します: terraform validate -var-file="CreateVMwareVM.tfvars"
  3. 変更を計画します: terraform plan -var-file="CreateVMwareVM.tfvars"
  4. 変更を適用します: terraform apply -var-file="CreateVMwareVM.tfvars"

プロンプトに「yes」と入力して確認し、変更を適用します。

ベスト プラクティス

  • バージョン コントロールを使用する: Terraform 構成ファイルをバージョン コントロール (Git など) で管理し、時間の経過に伴う変更を追跡します。
  • 計画を慎重に確認する: 変更を適用する前に、必ず terraform 計画の出力を確認して、どのような変更が加えられるかを確実に理解してください。
  • 状態管理: データの損失を回避するために、Terraform 状態ファイルを定期的にバックアップします。

これらの手順に従うことで、Terraform を使用して Azure 上で HCRP および Arc VMware VM を効果的に作成および管理し、作成された VM にゲスト エージェントをインストールできます。

シナリオ 2

テンプレート、リソース共有元、データストアを使用して新しい Arc VMware VM を作成し、Arc エージェントをインストールします。

手順 1: variables.tf ファイルで変数を定義する

variables.tf という名前のファイルを作成し、必要な変数をすべて定義します。

variable "subscription_id" {
  description = "The subscription ID for the Azure account."
  type        = string
}

variable "resource_group_name" {
  description = "The name of the resource group."
  type        = string
}

variable "location" {
  description = "The location/region where the resources will be created."
  type        = string
}

variable "machine_name" {
  description = "The name of the machine."
  type        = string
}

variable "vm_username" {
  description = "The admin username for the VM."
  type        = string
}

variable "vm_password" {
  description = "The admin password for the VM."
  type        = string
}

variable "template_id" {
  description = "The ID of the VM template."
  type        = string
}

variable "vcenter_id" {
  description = "The ID of the vCenter."
  type        = string
}

variable "resource_pool_id" {
  description = "The ID of the resource pool."
  type        = string
}

variable "datastore_id" {
  description = "The ID of the datastore."
  type        = string
}

variable "custom_location_id" {
  description = "The ID of the custom location."
  type        = string
}

手順 2: tfvars ファイルを作成する

CreateVMwareVM.tfvars という名前のファイルを作成し、変数のサンプル値を指定します。

subscription_id      = "your-subscription-id"
resource_group_name  = "your-resource-group"
location             = "eastus"
machine_name         = "test_machine0002"
vm_username          = "Administrator"
vm_password          = "*********"
template_id          = "/subscriptions/your-subscription-id/resourceGroups/your-resource-group/providers/Microsoft.ConnectedVMwarevSphere/virtualmachinetemplates/your-template-id"
vcenter_id           = "/subscriptions/your-subscription-id/resourceGroups/your-resource-group/providers/Microsoft.ConnectedVMwarevSphere/VCenters/your-vcenter-id"
resource_pool_id     = "/subscriptions/your-subscription-id/resourceGroups/your-resource-group/providers/Microsoft.ConnectedVMwarevSphere/resourcepools/your-resource-pool-id"
datastore_id         = "/subscriptions/your-subscription-id/resourceGroups/your-resource-group/providers/Microsoft.ConnectedVMwarevSphere/datastores/your-datastore-id"
custom_location_id   = "/subscriptions/your-subscription-id/resourceGroups/your-resource-group/providers/Microsoft.ExtendedLocation/customLocations/your-custom-location-id"

手順 3: 変数を使用するように構成を変更する

main.tf という名前のファイルを作成し、次のコードを挿入します。

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = ">= 3.0"
    }
    azapi = {
      source  = "azure/azapi"
      version = ">= 1.0.0"
    }
  }
}

# Configure the AzureRM provider with the subscription ID
provider "azurerm" {
  features {}
  subscription_id = var.subscription_id
}

# Configure the AzAPI provider with the subscription ID
provider "azapi" {
  subscription_id = var.subscription_id
}

# Retrieve the resource group details
data "azurerm_resource_group" "example" {
  name = var.resource_group_name
}

# Create a VMware machine resource in Azure
resource "azapi_resource" "test_machine0002" {
  schema_validation_enabled = false
  parent_id = data.azurerm_resource_group.example.id
  type = "Microsoft.HybridCompute/machines@2023-06-20-preview"
  name = var.machine_name
  location = data.azurerm_resource_group.example.location
  body = jsonencode({
      kind = "VMware"
      identity = {
        type = "SystemAssigned"
      }
  })
}

# Create a Virtual Machine instance using the VMware machine created above
resource "azapi_resource" "test_vm0002" {
  schema_validation_enabled = false
  type = "Microsoft.ConnectedVMwarevSphere/VirtualMachineInstances@2023-10-01"
  name = "default"
  parent_id = azapi_resource.test_machine0002.id
  body = jsonencode({
      properties = {
          infrastructureProfile = {
            templateId = var.template_id
            vCenterId = var.vcenter_id
          }

          placementProfile = {
            resourcePoolId = var.resource_pool_id
            datastoreId = var.datastore_id
          }

          osProfile = {
            adminPassword = var.vm_password
          }
      }
      extendedLocation = {
        type = "CustomLocation"
        name = var.custom_location_id
      }
  })
  depends_on = [azapi_resource.test_machine0002]
}

# Create a guest agent for the VM instance
resource "azapi_resource" "guestAgent" {
  type      = "Microsoft.ConnectedVMwarevSphere/virtualMachineInstances/guestAgents@2023-10-01"
  parent_id = azapi_resource.test_vm0002.id
  name      = "default"
  body = jsonencode({
    properties = {
      credentials = {
        username = var.vm_username
        password = var.vm_password
      }
      provisioningAction = "install"
    }
  })
  schema_validation_enabled = false
  ignore_missing_property   = false
  depends_on = [azapi_resource.test_vm0002]
}

手順 4: Terraform コマンドを実行する

-var- ファイル フラグを使用して、Terraform コマンド実行時に .tfvars ファイルを渡します。

  1. Terraform を初期化します (まだ初期化されていない場合): terraform init
  2. 構成を検証します: terraform validate -var-file="CreateVMwareVM.tfvars"
  3. 変更を計画します: terraform plan -var-file="CreateVMwareVM.tfvars"
  4. 変更を適用します: terraform apply -var-file="CreateVMwareVM.tfvars"

プロンプトに「yes」と入力して確認し、変更を適用します。

ベスト プラクティス

  • バージョン コントロールを使用する: Terraform 構成ファイルをバージョン コントロール (Git など) で管理し、時間の経過に伴う変更を追跡します。
  • 計画を慎重に確認する: 変更を適用する前に、必ず terraform 計画の出力を確認して、どのような変更が加えられるかを確実に理解してください。
  • 状態管理: データの損失を回避するために、Terraform 状態ファイルを定期的にバックアップします。

次のステップ

Azure で VMware VM に対して操作を実行する