我是terraform的新手,我正试图通过terraform在KVM上自动部署一台机器(带有qcow2映像(。我找到了这个tf文件:
provider "libvirt" {
uri = "qemu:///system"
}
#provider "libvirt" {
# alias = "server2"
# uri = "qemu+ssh://root@192.168.100.10/system"
#}
resource "libvirt_volume" "centos7-qcow2" {
name = "centos7.qcow2"
pool = "default"
source = "https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud.qcow2"
#source = "./CentOS-7-x86_64-GenericCloud.qcow2"
format = "qcow2"
}
# Define KVM domain to create
resource "libvirt_domain" "db1" {
name = "db1"
memory = "1024"
vcpu = 1
network_interface {
network_name = "default"
}
disk {
volume_id = "${libvirt_volume.centos7-qcow2.id}"
}
console {
type = "pty"
target_type = "serial"
target_port = "0"
}
graphics {
type = "spice"
listen_type = "address"
autoport = true
}
}
我的问题是:
- (源代码(我的qcow文件的路径必须在我的计算机上本地
- 我有一个KVM机器的ip,我通过它的ip远程连接它。我应该把这个ip放在这个tf文件的哪里
- 当我手动操作时,我运行";virt经理";,我需要在这里写吗
非常感谢。
- 编号。它也可以是https
- 您的意思是要创建虚拟机的KVM主机吗?然后,您需要在该主机上配置远程kvm访问,并在provider块的uri部分中编写其ip
uri = "qemu+ssh://username@IP_OF_HOST/system"
- 当你使用地形时,你不需要virt管理器。您应该使用地形资源来管理VM
https://registry.terraform.io/providers/dmacvicar/libvirt/latest/docs
https://github.com/dmacvicar/terraform-provider-libvirt/tree/main/examples/v0.13