“Terraform-provider-proxmox”的版本间的差异
跳到导航
跳到搜索
(→改进) |
|||
第37行: | 第37行: | ||
</pre> | </pre> | ||
+ | |||
+ | |||
+ | =terraform= | ||
+ | <pre> | ||
+ | #cat main.tf | ||
+ | terraform { | ||
+ | required_providers { | ||
+ | proxmox = { | ||
+ | source = "Telmate/proxmox" | ||
+ | version = "2.9.11" | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | provider "proxmox" { | ||
+ | pm_tls_insecure = true | ||
+ | pm_api_url = "https://192.168.10.8:8006/api2/json" | ||
+ | pm_api_token_id = "terraform-evan@pve!terraform-token" | ||
+ | pm_api_token_secret = "48ad9bae-98ad-49f5-a6d3-ac08f8000000" | ||
+ | } | ||
+ | resource "proxmox_vm_qemu" "proxmox-ubuntu" { | ||
+ | # 创建数量填写这里 | ||
+ | count = 4 | ||
+ | #name = "ubuntu-2004-${count.index + 1}" | ||
+ | name = "ubuntu-2004-${count.index + 1}" | ||
+ | desc = "Ubuntu develop environment" | ||
+ | |||
+ | # 节点名 | ||
+ | target_node = "pve" | ||
+ | |||
+ | # cloud-init template | ||
+ | clone = "ubuntu-2004-cloudinit-template" | ||
+ | |||
+ | # 关机 guest agent | ||
+ | agent = 0 | ||
+ | os_type = "ubuntu" | ||
+ | onboot = true | ||
+ | # CPU | ||
+ | cores = 2 | ||
+ | sockets = 2 | ||
+ | cpu = "host" | ||
+ | # 内存M | ||
+ | memory = 4384 | ||
+ | scsihw = "virtio-scsi-pci" | ||
+ | bootdisk = "scsi0" | ||
+ | |||
+ | # 硬盘设置,因计算的方式 101580M 代替 100G | ||
+ | disk { | ||
+ | slot = 0 | ||
+ | size = "28G" | ||
+ | type = "scsi" | ||
+ | storage = "local-lvm" | ||
+ | iothread = 1 | ||
+ | } | ||
+ | |||
+ | # 网络 | ||
+ | network { | ||
+ | model = "virtio" | ||
+ | bridge = "vmbr0" | ||
+ | } | ||
+ | |||
+ | lifecycle { | ||
+ | ignore_changes = [ | ||
+ | network, | ||
+ | ] | ||
+ | } | ||
+ | # 记住这里要使用IP CIDR。因为只创建一个虚拟机,虚拟机的 IP 是 192.168.1.41。如果要创建多个虚拟机的话,IP 将会是 .91、.92、.93 。 | ||
+ | #ipconfig0 = "ip=192.168.10.4${count.index + 1}/24,gw=192.168.10.1" | ||
+ | ipconfig0 = "ip=192.168.10.3${count.index + 1}/24,gw=192.168.10.1" | ||
+ | |||
+ | # 用户名和 SSH key | ||
+ | ciuser = "evan" | ||
+ | sshkeys = <<EOF | ||
+ | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDTR3R8Bx1stridoYMpGU1S8DTDnptWqrTCOMhrVlQH0I9ll/3ZAcD53JdzRXVLe1NqE6q5iTFO+HY5qxWfM0+gerJQlb1e5cb1+lUFhRVglpwYlxNSVXaJFeiCLswcnGcmqR1RnGAGhcf7ncslz/BLuxFndgLqhU04zj9ISJWYh+36vttqg9tP6a40MhmeWVPOuIGNlDDVVUyjxIepn83xr0PJyILLXTBH+OiQxxxguig67twUBsh/FW1Wdvuw33PjkgXmKLDVaKS2S0CtC9dPOrp0afS/fsKrIu16o/VtfSrNrTmsTCmE95Ug25yOS+WuVaU19Gauez2mj lx | ||
+ | EOF | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | </pre> | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
=改进= | =改进= |
2023年3月11日 (六) 08:46的版本
terraform 和proxmox的笔记终于有空放上wiki了
pre
Proxmox VE,terraform 已安装
创建Ubuntu(Cloud-Init) Template
#执行下面的命令创建一个虚拟机 #这里 9000 只是一个ID 你只要写个你的 proxmox还没用的ID就行了 qm create 9000 --name "ubuntu-2004-cloudinit-template" --memory 1024 --cores 1 --net0 virtio,bridge=vmbr0 qm importdisk 9000 ubuntu-20.04-server-cloudimg-amd64.img local-lvm qm set 9000 --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-9000-disk-0 qm set 9000 --boot c --bootdisk scsi0 qm set 9000 --ide2 local-lvm:cloudinit qm set 9000 --serial0 socket --vga serial0 qm set 9000 --agent enabled=1 #将刚创建好的虚拟机转换成模板 qm template 9000
API token
pveum user add terraform-evan@pve #我这里权限给得比较大 pveum aclmod / -user terraform-evan@pve -role Administrator pveum user token add terraform-evan@pve terraform-token --privsep=0 ──────────────┬──────────────────────────────────────┐ │ key │ value │ ╞══════════════╪══════════════════════════════════════╡ │ full-tokenid │ terraform-evan@pve!terraform-token │ ├──────────────┼──────────────────────────────────────┤ │ info │ {"privsep":"0"} │ ├──────────────┼──────────────────────────────────────┤ │ value │ 48ad9bae-98ad-49f5-a6d3-ac08f8700000 │ └──────────────┴──────────────────────────────────────┘
terraform
#cat main.tf terraform { required_providers { proxmox = { source = "Telmate/proxmox" version = "2.9.11" } } } provider "proxmox" { pm_tls_insecure = true pm_api_url = "https://192.168.10.8:8006/api2/json" pm_api_token_id = "terraform-evan@pve!terraform-token" pm_api_token_secret = "48ad9bae-98ad-49f5-a6d3-ac08f8000000" } resource "proxmox_vm_qemu" "proxmox-ubuntu" { # 创建数量填写这里 count = 4 #name = "ubuntu-2004-${count.index + 1}" name = "ubuntu-2004-${count.index + 1}" desc = "Ubuntu develop environment" # 节点名 target_node = "pve" # cloud-init template clone = "ubuntu-2004-cloudinit-template" # 关机 guest agent agent = 0 os_type = "ubuntu" onboot = true # CPU cores = 2 sockets = 2 cpu = "host" # 内存M memory = 4384 scsihw = "virtio-scsi-pci" bootdisk = "scsi0" # 硬盘设置,因计算的方式 101580M 代替 100G disk { slot = 0 size = "28G" type = "scsi" storage = "local-lvm" iothread = 1 } # 网络 network { model = "virtio" bridge = "vmbr0" } lifecycle { ignore_changes = [ network, ] } # 记住这里要使用IP CIDR。因为只创建一个虚拟机,虚拟机的 IP 是 192.168.1.41。如果要创建多个虚拟机的话,IP 将会是 .91、.92、.93 。 #ipconfig0 = "ip=192.168.10.4${count.index + 1}/24,gw=192.168.10.1" ipconfig0 = "ip=192.168.10.3${count.index + 1}/24,gw=192.168.10.1" # 用户名和 SSH key ciuser = "evan" sshkeys = <<EOF ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDTR3R8Bx1stridoYMpGU1S8DTDnptWqrTCOMhrVlQH0I9ll/3ZAcD53JdzRXVLe1NqE6q5iTFO+HY5qxWfM0+gerJQlb1e5cb1+lUFhRVglpwYlxNSVXaJFeiCLswcnGcmqR1RnGAGhcf7ncslz/BLuxFndgLqhU04zj9ISJWYh+36vttqg9tP6a40MhmeWVPOuIGNlDDVVUyjxIepn83xr0PJyILLXTBH+OiQxxxguig67twUBsh/FW1Wdvuw33PjkgXmKLDVaKS2S0CtC9dPOrp0afS/fsKrIu16o/VtfSrNrTmsTCmE95Ug25yOS+WuVaU19Gauez2mj lx EOF }
改进
使用 qm 创建 Ubuntu Cloud-Init Template,有可能要找个全 terraform的