gpt4 book ai didi

virtual-machine - 在 vsphere 中使用 terraform 创建 VM 会在自定义 VM 时出错

转载 作者:行者123 更新时间:2023-12-04 17:26:23 26 4
gpt4 key购买 nike

provider "vsphere" {
vsphere_server = "myserver"
user = "myuser"
password = "mypass"
allow_unverified_ssl = true
version = "v1.21.0"
}

data "vsphere_datacenter" "dc" {
name = "pcloud-datacenter"
}

data "vsphere_datastore_cluster" "datastore_cluster" {
name = "pc-storage"
datacenter_id = data.vsphere_datacenter.dc.id
}

data "vsphere_compute_cluster" "compute_cluster" {
name = "pcloud-cluster"
datacenter_id = data.vsphere_datacenter.dc.id
}

data "vsphere_network" "network" {
name = "u32c01p26-1514"
datacenter_id = data.vsphere_datacenter.dc.id
}


data "vsphere_virtual_machine" "vm_template" {
name = "first-terraform-vm"
datacenter_id = data.vsphere_datacenter.dc.id
}


resource "vsphere_virtual_machine" "vm" {
count = 1
name = "first-terraform-vm-1"
resource_pool_id = data.vsphere_compute_cluster.compute_cluster.resource_pool_id
datastore_cluster_id = data.vsphere_datastore_cluster.datastore_cluster.id

num_cpus = 2
memory = 1024

wait_for_guest_ip_timeout = 2
wait_for_guest_net_timeout = 0

guest_id = data.vsphere_virtual_machine.vm_template.guest_id

scsi_type = data.vsphere_virtual_machine.vm_template.scsi_type

network_interface {
network_id = data.vsphere_network.network.id
adapter_type = data.vsphere_virtual_machine.vm_template.network_interface_types[0]
}

disk {
name = "disk0.vmdk"
size = data.vsphere_virtual_machine.vm_template.disks.0.size
eagerly_scrub = data.vsphere_virtual_machine.vm_template.disks.0.eagerly_scrub
thin_provisioned = data.vsphere_virtual_machine.vm_template.disks.0.thin_provisioned
}

folder = "virtual-machines"

clone {
template_uuid = data.vsphere_virtual_machine.vm_template.id

customize {
linux_options {
host_name = "first-terraform-vm-1"
domain = "localhost.localdomain"
}
network_interface {
ipv4_address = "10.10.14.100"
ipv4_netmask = 24
}
ipv4_gateway = "10.10.14.1"
}
}
}

命令 terraform 脚本抛出以下错误

Error: 
Virtual machine customization failed on "/pcloud-datacenter/vm/virtual-machines/first-terraform-vm-1":

An error occurred while customizing VM first-terraform-vm-1. For details reference the log file <No Log> in the guest OS.

The virtual machine has not been deleted to assist with troubleshooting. If
corrective steps are taken without modifying the "customize" block of the
resource configuration, the resource will need to be tainted before trying
again. For more information on how to do this, see the following page:
https://www.terraform.io/docs/commands/taint.html


on create_vm.tf line 34, in resource "vsphere_virtual_machine" "vm":
34: resource "vsphere_virtual_machine" "vm" {


有些生成的虚拟机“first-terraform-vm-1”没有在网络设置中 checkin 连接框。当我检查我的模板“first-terraform-vm”时,它已 checkin 网络连接框。

我在 github 上看到类似的帖子 https://github.com/hashicorp/terraform-provider-vsphere/issues/951但不确定为什么这个问题仍然浮出水面?

Vsphere 版本:6.7地形 v0.12.28provider.vsphere v1.21.0

我的模板有问题吗?或者我错过了什么?有人可以帮忙吗?最近 2 天一直坚持这个。

最佳答案

问题似乎出在我使用的模板上。 linux 模板应该安装并运行网络管理器。看起来 terraform 使用网络管理器为新创建的虚拟机分配 IP 地址。

关于virtual-machine - 在 vsphere 中使用 terraform 创建 VM 会在自定义 VM 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62981343/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com