move helper scripts in scripts dir [ci skip]
This commit is contained in:
parent
51a94faff4
commit
8da88f9f6d
18 changed files with 66 additions and 224 deletions
|
|
@ -1,153 +1,88 @@
|
|||
variable "vsphere_user" {
|
||||
default = "Administrator@viktorbarzin.lan"
|
||||
}
|
||||
variable "vsphere_password" {}
|
||||
variable "vsphere_server" {
|
||||
default = "vcenter"
|
||||
}
|
||||
variable "vm_name" {
|
||||
default = "terraform-test"
|
||||
}
|
||||
variable "template_name" { type = string }
|
||||
variable "vm_name" { default = "terraform-test" }
|
||||
variable "vm_cpus" {
|
||||
type = number
|
||||
default = 4
|
||||
}
|
||||
|
||||
variable "vm_mem" {
|
||||
variable "vm_mem_mb" {
|
||||
type = number
|
||||
default = 4096
|
||||
}
|
||||
|
||||
variable "vm_guest_id" {
|
||||
default = "ubuntu64Guest"
|
||||
default = 8192
|
||||
}
|
||||
|
||||
variable "vm_disk_size" {
|
||||
type = number
|
||||
default = 64
|
||||
}
|
||||
|
||||
variable "provisioner_command" {
|
||||
description = "Additional provisioning commands to run"
|
||||
default = "#"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "network" {
|
||||
description = "Network to attach the vm guest to"
|
||||
}
|
||||
|
||||
variable "ceph_disk_size" {
|
||||
type = number
|
||||
default = 0
|
||||
}
|
||||
|
||||
variable "cdrom_path" {
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "vsphere_datastore" {
|
||||
type = string
|
||||
default = "r730-datastore"
|
||||
}
|
||||
|
||||
variable "vsphere_resource_pool" {
|
||||
type = string
|
||||
default = "R730"
|
||||
default = "64G"
|
||||
}
|
||||
|
||||
variable "vm_mac_address" {
|
||||
type = string
|
||||
default = ""
|
||||
default = null
|
||||
}
|
||||
variable "cisnippet_name" { type = string }
|
||||
|
||||
provider "vsphere" {
|
||||
user = var.vsphere_user
|
||||
password = var.vsphere_password
|
||||
vsphere_server = var.vsphere_server
|
||||
|
||||
# If you have a self-signed cert
|
||||
allow_unverified_ssl = true
|
||||
}
|
||||
|
||||
data "vsphere_datacenter" "dc" {
|
||||
name = "Home"
|
||||
}
|
||||
|
||||
data "vsphere_datastore" "datastore" {
|
||||
name = var.vsphere_datastore
|
||||
datacenter_id = data.vsphere_datacenter.dc.id
|
||||
}
|
||||
|
||||
data "vsphere_resource_pool" "pool" {
|
||||
name = var.vsphere_resource_pool
|
||||
datacenter_id = data.vsphere_datacenter.dc.id
|
||||
}
|
||||
|
||||
data "vsphere_network" "network" {
|
||||
name = var.network
|
||||
datacenter_id = data.vsphere_datacenter.dc.id
|
||||
}
|
||||
|
||||
resource "vsphere_virtual_machine" "vm" {
|
||||
resource "proxmox_vm_qemu" "cloudinit-vm" {
|
||||
vmid = 305
|
||||
name = var.vm_name
|
||||
resource_pool_id = data.vsphere_resource_pool.pool.id
|
||||
datastore_id = data.vsphere_datastore.datastore.id
|
||||
target_node = "pve"
|
||||
agent = 0
|
||||
memory = var.vm_mem_mb
|
||||
boot = "order=scsi0" # has to be the same as the OS disk of the template
|
||||
clone = var.template_name # The name of the template
|
||||
scsihw = "virtio-scsi-single"
|
||||
vm_state = "running"
|
||||
automatic_reboot = true
|
||||
os_type = "cloud-init"
|
||||
|
||||
num_cpus = var.vm_cpus
|
||||
memory = var.vm_mem
|
||||
guest_id = var.vm_guest_id
|
||||
# Cloud-Init configuration
|
||||
ciupgrade = true
|
||||
nameserver = "1.1.1.1 8.8.8.8"
|
||||
ipconfig0 = "ip=dhcp,ip6=dhcp"
|
||||
skip_ipv6 = true
|
||||
ciuser = "root"
|
||||
sshkeys = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDHLhYDfyx237eJgOGVoJRECpUS95+7rEBS9vacsIxtx vbarzin@gmail.com"
|
||||
searchdomain = "viktorbarzin.lan"
|
||||
onboot = true # start on node boot
|
||||
qemu_os = "l26"
|
||||
cicustom = "vendor=local:snippets/${var.cisnippet_name}"
|
||||
|
||||
# If mac address is set create NIC with that MAC
|
||||
dynamic "network_interface" {
|
||||
for_each = var.vm_mac_address != "" ? [1] : []
|
||||
content {
|
||||
network_id = data.vsphere_network.network.id
|
||||
use_static_mac = true
|
||||
mac_address = var.vm_mac_address
|
||||
cpu {
|
||||
cores = var.vm_cpus
|
||||
type = "host" # emulate host cpu
|
||||
}
|
||||
|
||||
|
||||
# Most cloud-init images require a serial device for their display
|
||||
serial {
|
||||
id = 0
|
||||
}
|
||||
|
||||
disks {
|
||||
scsi {
|
||||
scsi0 {
|
||||
# We have to specify the disk from our template, else Terraform will think it's not supposed to be there
|
||||
disk {
|
||||
storage = "local-lvm"
|
||||
# The size of the disk should be at least as big as the disk in the template. If it's smaller, the disk will be recreated
|
||||
size = var.vm_disk_size
|
||||
}
|
||||
}
|
||||
}
|
||||
ide {
|
||||
# Some images require a cloud-init disk on the IDE controller, others on the SCSI or SATA controller
|
||||
ide1 {
|
||||
cloudinit {
|
||||
storage = "local-lvm"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Else create a NIC with random MAC
|
||||
dynamic "network_interface" {
|
||||
for_each = var.vm_mac_address == "" ? [1] : []
|
||||
content {
|
||||
network_id = data.vsphere_network.network.id
|
||||
}
|
||||
}
|
||||
|
||||
disk {
|
||||
label = "disk0"
|
||||
size = var.vm_disk_size
|
||||
}
|
||||
|
||||
dynamic "disk" {
|
||||
for_each = var.ceph_disk_size > 0 ? [1] : []
|
||||
content {
|
||||
label = "ceph-disk0"
|
||||
size = var.ceph_disk_size
|
||||
unit_number = 1
|
||||
}
|
||||
}
|
||||
|
||||
dynamic "cdrom" {
|
||||
for_each = var.cdrom_path != "" ? [1] : []
|
||||
content {
|
||||
datastore_id = data.vsphere_datastore.datastore.id
|
||||
path = var.cdrom_path
|
||||
}
|
||||
}
|
||||
wait_for_guest_net_timeout = 600
|
||||
|
||||
provisioner "local-exec" {
|
||||
# for_each = var.provisioner_command != "" ? [1] : []
|
||||
# content {
|
||||
command = "${var.provisioner_command} -e 'host=${vsphere_virtual_machine.vm.default_ip_address}'"
|
||||
# }
|
||||
network {
|
||||
id = 0
|
||||
bridge = "vmbr0"
|
||||
model = "e1000"
|
||||
macaddr = var.vm_mac_address
|
||||
}
|
||||
}
|
||||
|
||||
output "guest_ip" {
|
||||
value = vsphere_virtual_machine.vm.default_ip_address
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
|
||||
terraform {
|
||||
required_providers {
|
||||
vsphere = {
|
||||
source = "hashicorp/vsphere"
|
||||
version = "2.0.2"
|
||||
proxmox = {
|
||||
source = "telmate/proxmox"
|
||||
version = "3.0.2-rc04"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue