Виртуальная машина Terraform vsphere - невозможно клонировать со статическим IPv4-адресом - PullRequest
0 голосов
/ 04 мая 2019

У меня проблемы с подготовкой виртуальной машины в vSphere 6.5 с использованием Terraform v0.11.13 и provider.vsphere v1.9.1 с использованием статического адреса ipv4.Когда шаблон клонируется, он настраивает виртуальную машину для DHCP.Шаблон vsphere также настроен на статический ip.Но я заметил, что после клона он возвращается к DHCP.Это работает с linux_options.

Я установил статический IP-адрес для шаблона, чтобы он соответствовал конечному IP-адресу виртуальной машины.Я удалил VM_count, думая, что он ожидает несколько виртуальных машин, поэтому он использует DHCP.

Это модуль vars.tf:

variable "vsphere_user" {  
  type        = "string"  
  description = "The terraform vsphere service account."  
  default     = "vsphereUser@acme.com"  
}  

variable "vsphere_password" {  
  type        = "string"  
  description = "The terraform vsphere service account password."  
  default     = ""  
}  

variable "vsphere_server" {  
  type        = "string"  
  description = "The vsphere virtual center server."  
  default     = "vcenter.acme.com"  
}  

variable "vsphere_guest_id" {  
  type        = "string"  
  description = "The vsphere guest id to assign Windows servers."  
  default     = "windows9Server64Guest"  
}  

variable "datacenter" {  
  type        = "string"  
  description = "The datacenter to deploy the virtual machines to."  
  default     = "HCI"  
}  

variable "datastore" {  
  type        = "string"  
  description = "The datastore to deploy the virtual machines to."  
  default     = "DS-01"   
}  

variable "linux_template" {  
  type = "string"  
  description = "The default linux template"  
  default = "CENT-7.5-50GB"  
}  

variable "windows_template" {  
  type = "string"  
  description = "The default windows template"  
  default = "Packer-Win2016-HCI-20190424"  
}  

variable "network" {  
  type        = "string"  
  description = "The vshpere network to assign to the VM."  
  default     = "VLAN_99"  
}  

variable "cluster" {  
  type        = "string"  
  description = "The vsphere cluster to assign."  
  default     = "General-VMs"  
}  

variable "vm_root_password" {  
  type        = "string"  
  description = "The initial Linux server  root password set prior to puppet inline provisioning."  
  default     = "xxxxx"  
}  

variable "vm_default_password" {  
  type        = "string"  
  description = "The initial Windows server root password set prior to the SCCM provisioning."  
  default     = "xxxxx"  
}  

variable "vm_domain_name" {  
  type        = "string"  
  description = "The domain name to assign to the VM."  
  default     = "acme.com"  
}  

variable "vm_time_zone_linux" {  
  type        = "string"  
  description = "The time zone to assign to the VM."  
  default     = "America/New_York"  
}  

variable "vm_time_zone_windows" {  
  type        = "string"  
  description = "The time zone to assign to the VM."  
  default     = "35"  
}  

variable "vm_name" {  
  type        = "string"  
  description = "The name to use for vsphere virtual machines created with this module."  
  default     = ""  
}  

variable "vm_host_name" {  
  type        = "string"  
  description = "The hostname to provision the server with."  
  default     = ""  
}  

variable "vm_ip_address" {  
  type        = "string"  
  description = "The IP address to assing to the VM."  
  default     = ""  
}  

variable "vm_netmask" {  
  type        = "string"  
  description = "The netmask to assign to the VM."  
  default     = "24"  
}  

variable "vm_ip_gateway" {  
  type        = "string"  
  description = "The gateway  address to assing to the VM."  
  default     = ""  
}  

variable "vm_num_cpus" {  
  type        = "string"  
  description = "The number of CPU to allocate the VM."  
  default     = "2"  
}  

variable "vm_memory" {  
  type        = "string"  
  description = "The amount of RAM to allocate the VM."  
  default     = "4096"  
}  

variable "vm_count" {  
  description = "The number of virtual machines to create."  
  default     = "1"  
}  

variable "folder" {  
  description = "The folder to place the VM in vSphere."  
  default     = "Servers/3Test"  
}  

variable "vm_cpu_hotadd" {  
  description = "Allows CPU to be added realtime."  
  default     = "true"  
}  

variable "vm_memory_hotadd" {  
  description = "Allows memory to be added realtime."  
  default     = "true"  
}  

variable "vm_disk0_size" {  
  description = "The size of disk 0."  
  default     = "50"  
}  

variable "vm_disk1_size" {  
  description = "The size of disk 1."  
  default     = "10"  
}  

variable "vm_notes" {  
  description = "Description of VM."  
  default     = "terraform"  
}  

Это корневой файл vars.tf: (они очень похожи, все еще работают над тем, какие папки нужны)

variable "vsphere_user" {  
  type        = "string"  
  description = "The terraform vsphere service account."  
  default     = "vsphereUser@acme.com"  
}  

variable "vsphere_password" {  
  type        = "string"  
  description = "The terraform vsphere service account password."  
  default     = ""  
}  

variable "vsphere_server" {  
  type        = "string"  
  description = "The vsphere virtual center server."  
  default     = "vcenter.acme.com"  
}  

variable "vsphere_guest_id" {  
  type        = "string"  
  description = "The vsphere guest id to assign Windows servers."  
  default     = "windows9Server64Guest"  
}  

variable "datacenter" {  
  type        = "string"  
  description = "The datacenter to deploy the virtual machines to."  
  default     = "HCI"  
}  

variable "datastore" {  
  type        = "string"  
  description = "The datastore to deploy the virtual machines to."  
  default     = "DS-01"   
}  

variable "linux_template" {  
  type = "string"  
  description = "The default linux template"  
  default = "CENT-7.6-50GB"  
}  

variable "network" {  
  type        = "string"  
  description = "The vshpere network to assign to the VM."  
  default     = "VLAN_99"  
}  

variable "cluster" {  
  type        = "string"  
  description = "The vsphere cluster to assign."  
  default     = "General-VMs"  
}  

variable "vm_root_password" {  
  type        = "string"  
  description = "The intial Linux server  root password set prior to puppet inline provisioning."  
  default     = "xxxxx"  
}  

variable "vm_default_password" {  
  type        = "string"  
  description = "The intial Windows server root password set prior to the SCCM provisioning."  
  default     = "xxxxx"  
}  

variable "vm_domain_name" {  
  type        = "string"  
  description = "The domain name to assign to the VM."  
  default     = "acme.com"  
}  

variable "vm_time_zone_linux" {  
  type        = "string"  
  description = "The time zone to assign to the VM."  
  default     = "America/New_York"  
}  

variable "vm_time_zone_windows" {  
  type        = "string"  
  description = "The time zone to assign to the VM."  
  default     = "35"  
}  

variable "vm_name" {  
  type        = "string"  
  description = "The name to use for vsphere virtual machines created with this module."  
  default     = ""  
}  

variable "vm_host_name" {  
  type        = "string"  
  description = "The hostname to provision the server with."  
  default     = ""  
}  

variable "vm_ip_address" {  
  type        = "string"  
  description = "The IP address to assing to the VM."  
  default     = ""  
}  

variable "vm_netmask" {  
  type        = "string"  
  description = "The netmask to assign to the VM."  
  default     = "24"  
}  

variable "vm_ip_gateway" {  
  type        = "string"  
  description = "The gateway  address to assing to the VM."  
  default     = ""  
}  

variable "vm_num_cpus" {  
  type        = "string"  
  description = "The number of CPU to allocate the VM."  
  default     = "2"  
}  

variable "vm_memory" {  
  type        = "string"  
  description = "The amount of RAM to allocate the VM."  
  default     = "4096"  
}  

variable "vm_count" {  
  description = "The number of virtual machines to create."  
  default     = "1"  
}  

variable "folder" {  
  description = "The folder to place the VM in vSphere."  
  default     = "Servers/1Prod"  
}  

variable "vm_cpu_hotadd" {  
  description = "Allows CPU to be added realtime."  
  default     = "true"  
}  

variable "vm_memory_hotadd" {  
  description = "Allows memory to be added realtime."  
  default     = "true"  
}  

variable "vm_notes" {  
  type        = "string"  
  description = "Description of VM."  
  default     = "terraform"  
}  

Это модуль виртуальных машин tf:

module "testv11" {  
  source           = "git::ssh://git@gitlab/iac/terraform- modules.git//windows-base?ref=windows-base-prod-v1.0.2"  
  vm_name          = "TESTV11"  
  vm_host_name     = "testv11"  
  vm_ip_address    = "10.255.187.45"  
  vm_ip_gateway    = "10.255.187.1"  
  network          = "VLAN_99"  
  vm_disk0_size    = "50"  
  vm_disk1_size    = "10"  
  folder            = "Servers/1Prod"  
}  

В плане terraform я ожидаю увидеть статический IP-адрес.


План Windows не показывает статический IP:

clone.#:                                                 "" => "1"  
  clone.0.customize.#:                                     "" => "1"  
  clone.0.customize.0.network_interface.#:                 "" => "1"  
  clone.0.customize.0.timeout:                             "" => "10"  
  clone.0.customize.0.windows_options.#:                   "" => "1"  
  clone.0.customize.0.windows_options.0.admin_password:    "<sensitive>" => "<sensitive>"  
  clone.0.customize.0.windows_options.0.auto_logon_count:  "" => "1"  
  clone.0.customize.0.windows_options.0.computer_name:     "" => "testv11"  
  clone.0.customize.0.windows_options.0.full_name:         "" =>
 "Administrator"  
  clone.0.customize.0.windows_options.0.organization_name: "" => "Managed by Terraform"  
  clone.0.customize.0.windows_options.0.time_zone:         "" => "35"  
  clone.0.customize.0.windows_options.0.workgroup:         "" => "workgroup"  
  clone.0.template_uuid:                                   "" => "422912a4-a156-2e28-10a8-2684d835c834"  
  clone.0.timeout:                                         "" => "30"  

План Linux с постоянным IP:

clone.#:                                              "" => "1"  
  clone.0.customize.#:                                  "" => "1"  
  clone.0.customize.0.ipv4_gateway:                     "" => "10.255.187.1"  
  clone.0.customize.0.linux_options.#:                  "" => "1"  
  clone.0.customize.0.linux_options.0.domain:           "" => "acme.com"  
  clone.0.customize.0.linux_options.0.host_name:        "" => "linuxv01"  
  clone.0.customize.0.linux_options.0.hw_clock_utc:     "" => "true"  
  clone.0.customize.0.linux_options.0.time_zone:        "" => "America/New_York"  
  clone.0.customize.0.network_interface.#:              "" => "1"  
  clone.0.customize.0.network_interface.0.ipv4_address: "" => "10.255.187.38"  
  clone.0.customize.0.network_interface.0.ipv4_netmask: "" => "24"  
  clone.0.customize.0.timeout:                          "" => "10"  
  clone.0.template_uuid:                                "" => "4229c06d-522d-88d5-c158-a53fca0a96cb"  
  clone.0.timeout:                                      "" => "30"  
...