Nuta
Dostęp do tej strony wymaga autoryzacji. Możesz spróbować się zalogować lub zmienić katalog.
Dostęp do tej strony wymaga autoryzacji. Możesz spróbować zmienić katalogi.
W tym artykule opisano sposób aprowizacji maszyny wirtualnej przy użyciu zasobów vCenter przy użyciu szablonu Bicep.
Tworzenie maszyny VMware usługi Arc przy użyciu szablonu Bicep
Do utworzenia maszyny VMware usługi Arc można użyć następującego szablonu bicep. Oto lista dostępnych szablonów usługi Azure Resource Manager (ARM), Bicep i Terraform dla zasobów VMware z obsługą usługi Arc. Aby wyzwolić dowolną inną operację usługi Arc, przekonwertuj odpowiedni szablon usługi ARM na szablon Bicep.
// Parameters
param vmName string = 'contoso-vm'
param vmAdminPassword string = 'examplepassword!#'
param vCenterId string = '/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/contoso-rg/providers/Microsoft.ConnectedVMwarevSphere/vcenters/contoso-vcenter'
param templateId string = '/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/contoso-rg/providers/Microsoft.ConnectedVMwarevSphere/VirtualMachineTemplates/contoso-template-win22'
param resourcePoolId string = '/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/contoso-rg/providers/Microsoft.ConnectedVMwarevSphere/ResourcePools/contoso-respool'
param datastoreId string = '/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/contoso-rg/providers/Microsoft.ConnectedVMwarevSphere/Datastores/contoso-datastore'
param networkId string = '/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/contoso-rg/providers/Microsoft.ConnectedVMwarevSphere/VirtualNetworks/contoso-network'
param extendedLocation object = {
type: 'customLocation'
name: '/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/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
W tym artykule opisano sposób aprowizowania maszyny wirtualnej przy użyciu zasobów programu vCenter przy użyciu szablonu programu Terraform.
Tworzenie maszyny VMware usługi Arc za pomocą programu Terraform
Wymagania wstępne
- Subskrypcja platformy Azure: upewnij się, że masz aktywną subskrypcję platformy Azure.
- Terraform: zainstaluj program Terraform na maszynie.
- Interfejs wiersza polecenia platformy Azure: instalowanie interfejsu wiersza polecenia platformy Azure w celu uwierzytelniania zasobów i zarządzania nimi.
Wykonaj następujące kroki, aby utworzyć maszynę VMware usługi Arc przy użyciu programu Terraform. W tym artykule omówiono następujące dwa scenariusze:
- W przypadku maszyn wirtualnych odnalezionych w spisie programu vCenter włącz operację platformy Azure i zainstaluj agentów usługi Arc.
- Utwórz nową maszynę wirtualną usługi Arc VMware przy użyciu szablonów, puli zasobów, magazynu danych i zainstalowania agentów usługi Arc.
Scenariusz 1
W przypadku maszyn wirtualnych odnalezionych w spisie programu vCenter włącz operację platformy Azure i zainstaluj agentów usługi Arc.
Krok 1. Definiowanie zmiennych w pliku variables.tf
Utwórz plik o nazwie variables.tf i zdefiniuj wszystkie niezbędne zmienne.
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
}
Krok 2. Tworzenie pliku tfvars
Utwórz plik o nazwie CreateVMwareVM.tfvars i podaj przykładowe wartości zmiennych.
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 "
Krok 3. Modyfikowanie konfiguracji w celu używania zmiennych
Utwórz plik o nazwie main.tf i wstaw następujący kod.
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]
}
Krok 4. Uruchamianie poleceń narzędzia Terraform
Użyj flagi -var-file, aby przekazać plik tfvars podczas poleceń narzędzia Terraform.
- Zainicjuj program Terraform (jeśli jeszcze nie został zainicjowany):
terraform init - Zweryfikuj konfigurację:
terraform validate -var-file="CreateVMwareVM.tfvars" - Zaplanuj zmiany:
terraform plan -var-file="CreateVMwareVM.tfvars" - Zastosuj zmiany:
terraform apply -var-file="CreateVMwareVM.tfvars"
Potwierdź monit, wprowadzając wartość tak, aby zastosować zmiany.
Najlepsze rozwiązania
- Użyj kontroli wersji: zachowaj pliki konfiguracji programu Terraform pod kontrolą wersji (na przykład Git), aby śledzić zmiany w czasie.
- Uważnie przejrzyj plany: zawsze przejrzyj dane wyjściowe planu terraform przed zastosowaniem zmian, aby upewnić się, że rozumiesz, jakie zmiany zostaną wprowadzone.
- Zarządzanie stanem: regularnie kopii zapasowej plików stanu programu Terraform, aby uniknąć utraty danych.
Wykonując te kroki, można skutecznie tworzyć maszyny wirtualne HCRP i Arc VMware na platformie Azure oraz zarządzać nimi przy użyciu narzędzia Terraform i instalować agentów gościa na utworzonych maszynach wirtualnych.
Scenariusz 2
Utwórz nową maszynę wirtualną usługi Arc VMware przy użyciu szablonów, puli zasobów, magazynu danych i zainstalowania agentów usługi Arc.
Krok 1. Definiowanie zmiennych w pliku variables.tf
Utwórz plik o nazwie variables.tf i zdefiniuj wszystkie niezbędne zmienne.
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
}
Krok 2. Tworzenie pliku tfvars
Utwórz plik o nazwie CreateVMwareVM.tfvars i podaj przykładowe wartości zmiennych.
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"
Krok 3. Modyfikowanie konfiguracji w celu używania zmiennych
Utwórz plik o nazwie main.tf i wstaw następujący kod.
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]
}
Krok 4. Uruchamianie poleceń narzędzia Terraform
Użyj flagi -var-file, aby przekazać plik tfvars podczas poleceń narzędzia Terraform.
- Zainicjuj program Terraform (jeśli jeszcze nie został zainicjowany):
terraform init - Zweryfikuj konfigurację:
terraform validate -var-file="CreateVMwareVM.tfvars" - Zaplanuj zmiany:
terraform plan -var-file="CreateVMwareVM.tfvars" - Zastosuj zmiany:
terraform apply -var-file="CreateVMwareVM.tfvars"
Potwierdź monit, wprowadzając wartość tak, aby zastosować zmiany.
Najlepsze rozwiązania
- Użyj kontroli wersji: zachowaj pliki konfiguracji programu Terraform pod kontrolą wersji (na przykład Git), aby śledzić zmiany w czasie.
- Uważnie przejrzyj plany: zawsze przejrzyj dane wyjściowe planu terraform przed zastosowaniem zmian, aby upewnić się, że rozumiesz, jakie zmiany zostaną wprowadzone.
- Zarządzanie stanem: regularnie kopii zapasowej plików stanu programu Terraform, aby uniknąć utraty danych.
Następne kroki
Wykonywanie operacji na maszynach wirtualnych VMware na platformie Azure.