Changeset View
Changeset View
Standalone View
Standalone View
proxmox/terraform/modules/node/main.tf
resource "proxmox_vm_qemu" "node" { | resource "proxmox_vm_qemu" "node" { | ||||
name = "${var.hostname}" | name = "${var.hostname}" | ||||
desc = "${var.description}" | desc = "${var.description}" | ||||
# hypervisor onto which make the vm | # hypervisor onto which make the vm | ||||
target_node = "${var.hypervisor}" | target_node = "${var.hypervisor}" | ||||
# See init-template.md to see the template vm bootstrap | # See init-template.md to see the template vm bootstrap | ||||
clone = "${var.template}" | clone = "${var.template}" | ||||
# linux kernel 2.6 | # linux kernel 2.6 | ||||
qemu_os = "l26" | qemu_os = "l26" | ||||
# generic setup | # generic setup | ||||
sockets = "${var.sockets}" | sockets = "${var.sockets}" | ||||
cores = "${var.cores}" | cores = "${var.cores}" | ||||
memory = "${var.memory}" | memory = "${var.memory}" | ||||
# boot machine when hypervirsor starts | # boot machine when hypervirsor starts | ||||
onboot = true | onboot = true | ||||
# cloud-init setup | #### cloud-init setup | ||||
os_type = "cloud-init" | os_type = "cloud-init" | ||||
# ciuser - User name to change ssh keys and password for instead of the | # ciuser - User name to change to use when connecting | ||||
# image’s configured default user. | ciuser = "${var.config["user_admin"]}" | ||||
ciuser = "${var.user_admin}" | ssh_user = "${var.config["user_admin"]}" | ||||
ssh_user = "${var.user_admin}" | # sshkeys - public ssh key to use when connecting | ||||
# sshkeys - public ssh keys, one per line | sshkeys = "${var.config["user_admin_ssh_public_key"]}" | ||||
sshkeys = "${var.user_admin_ssh_public_key}" | |||||
# searchdomain - Sets DNS search domains for a container. | # searchdomain - Sets DNS search domains for a container. | ||||
searchdomain = "${var.domain}" | searchdomain = "${var.config["domain"]}" | ||||
# nameserver - Sets DNS server IP address for a container. | # nameserver - Sets DNS server IP address for a container. | ||||
nameserver = "${var.dns}" | nameserver = "${var.config["dns"]}" | ||||
# ipconfig0 - [gw =] [,ip=<IPv4Format/CIDR>] | # ipconfig0 - [gw =] [,ip=<IPv4Format/CIDR>] | ||||
ipconfig0 = "ip=${var.network["ip"]}/24,gw=${var.gateway_ip}" | ipconfig0 = "ip=${var.network["ip"]}/24,gw=${var.config["gateway_ip"]}" | ||||
#### | |||||
disk { | disk { | ||||
id = 0 | id = 0 | ||||
type = "virtio" | type = "virtio" | ||||
storage = "${var.storage["location"]}" | storage = "${var.storage["location"]}" | ||||
storage_type = "ssd" | storage_type = "ssd" | ||||
size = "${var.storage["size"]}" | size = "${var.storage["size"]}" | ||||
} | } | ||||
network { | network { | ||||
id = 0 | id = 0 | ||||
model = "virtio" | model = "virtio" | ||||
bridge = "vmbr0" | bridge = "vmbr0" | ||||
macaddr = "${lookup(var.network, "macaddr", "")}" | macaddr = "${lookup(var.network, "macaddr", "")}" | ||||
} | } | ||||
# Delegate to puppet at the end of the provisioning the software setup | #### provisioning: (creation time only) connect through ssh | ||||
# Let puppet do its install | |||||
provisioner "remote-exec" { | provisioner "remote-exec" { | ||||
inline = [ | inline = [ | ||||
"sed -i 's/127.0.1.1/${var.network["ip"]}/g' /etc/hosts", | "sed -i 's/127.0.1.1/${var.network["ip"]}/g' /etc/hosts", | ||||
"puppet agent --server ${var.puppet_master} --environment=${var.puppet_environment} --waitforcert 60 --test || echo 'Node provisionned!'", | "puppet agent --server ${var.config["puppet_master"]} --environment=${var.config["puppet_environment"]} --waitforcert 60 --test || echo 'Node provisionned!'", | ||||
] | ] | ||||
} | } | ||||
} | } |