Terraform vSphere虚拟机-无法使用静态ipv4地址进行克隆

时间:2019-05-03 21:53:50

标签: virtual-machine vmware terraform vsphere

在使用Terraform v0.11.13和provider.vsphere v1.9.1(使用静态ipv4地址)在vSphere 6.5中配置VM时遇到问题。克隆模板后,它将为DHCP配置VM。 vSphere模板也配置了静态IP。但是我注意到,克隆之后将其重新设置为DHCP。这适用于linux_options。

我已经为模板设置了静态IP以匹配最终的VM IP。我删除了VM_count,以为它希望有多个VM,因此它使用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"  
}  

这是VM模块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"  

显示静态IP的Linux计划:

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"  

0 个答案:

没有答案