diff --git a/proxmox/terraform/modules/node/main.tf b/proxmox/terraform/modules/node/main.tf index 3fd973d..b382098 100644 --- a/proxmox/terraform/modules/node/main.tf +++ b/proxmox/terraform/modules/node/main.tf @@ -1,109 +1,109 @@ resource "proxmox_vm_qemu" "node" { name = var.hostname desc = var.description vmid = var.vmid balloon = var.balloon full_clone = false # hypervisor onto which make the vm target_node = var.hypervisor # See init-template.md to see the template vm bootstrap clone = var.template boot = "c" # linux kernel 2.6 qemu_os = "l26" # generic setup sockets = var.sockets cores = var.cores numa = var.numa memory = var.memory # boot machine when hypervirsor starts onboot = true #### cloud-init setup os_type = "cloud-init" # ciuser - User name to change to use when connecting ciuser = var.config["user_admin"] ssh_user = var.config["user_admin"] # sshkeys - public ssh key to use when connecting sshkeys = var.config["user_admin_ssh_public_key"] # searchdomain - Sets DNS search domains for a container. searchdomain = var.config["domain"] # nameserver - Sets DNS server IP address for a container. nameserver = var.config["dns"] # ipconfig0 - [gw =] [,ip=] ipconfig0 = "ip=${var.networks[0]["ip"]}/24,gw=${var.networks[0]["gateway"]}" # Mostly, var.networks holds only one network declaration except for gateways # Try to lookup such value, if it fails (or is undefined), then ipconfig1 # will be empty, thus no secondary ip config ipconfig1 = try(lookup(var.networks[1], "ip"), "") != "" ? "ip=${var.networks[1]["ip"]}/24" : "" #### dynamic disk { for_each = var.storages content { id = disk.value["id"] storage = disk.value["storage"] size = disk.value["size"] type = "virtio" # storage_type: https://pve.proxmox.com/wiki/Storage storage_type = lookup(disk.value, "storage_type", "cephfs") } } dynamic network { for_each = var.networks content { id = lookup(network.value, "id", 0) macaddr = lookup(network.value, "macaddr", "") bridge = lookup(network.value, "bridge", "vmbr443") model = "virtio" } } #### provisioning: (creation time only) connect through ssh # Let puppet do its install provisioner "remote-exec" { inline = concat( var.pre_provision_steps, [ # First install facts... "mkdir -p /etc/facter/facts.d", - "echo deployment=${var.facter_deployment} > /etc/facter/facts.d/deployment.txt", - "echo subnet=${var.facter_subnet} > /etc/facter/facts.d/subnet.txt", + "echo deployment=${var.config["facter_deployment"]} > /etc/facter/facts.d/deployment.txt", + "echo subnet=${var.config["facter_subnet"]} > /etc/facter/facts.d/subnet.txt", "sed -i 's/127.0.1.1/${lookup(var.networks[0], "ip")}/g' /etc/hosts", # so puppet agent installs the node's role "puppet agent --server ${var.config["puppet_master"]} --environment=${var.config["puppet_environment"]} --waitforcert 60 --test || echo 'Node provisionned!'", ]) connection { type = "ssh" user = "root" host = lookup(var.networks[0], "ip") private_key = file(var.config["user_admin_ssh_private_key_path"]) } } lifecycle { ignore_changes = [ bootdisk, scsihw, target_node, clone ] } } diff --git a/proxmox/terraform/modules/node/variables.tf b/proxmox/terraform/modules/node/variables.tf index 3fda89f..58bbcec 100644 --- a/proxmox/terraform/modules/node/variables.tf +++ b/proxmox/terraform/modules/node/variables.tf @@ -1,108 +1,96 @@ variable "hostname" { description = "Node's hostname" type = string } -variable "facter_subnet" { - description = "Subnet custom fact (e.g sesi_rocquencourt_staging, ...)" - type = string - default = "sesi_rocquencourt_staging" -} - -variable "facter_deployment" { - description = "Deployment custom fact (e.g staging, production)" - type = string - default = "staging" -} - variable "description" { description = "Node's description" type = string } variable "hypervisor" { description = "Hypervisor to install the vm to (choice: orsay, hypervisor3, beaubourg, branly)" type = string } variable "template" { description = "Template created by packer to use (template-debian-10, debian-buster-...)" type = string default = "debian-buster-2020-11-06" } variable "sockets" { description = "Number of sockets" type = string default = "1" } variable "cores" { description = "Number of cores" type = string default = "1" } variable "memory" { description = "Memory in Mb" type = string default = "1024" } variable "networks" { description = "Default networks configuration (id, ip, gateway, macaddr, bridge)" type = list(object({ id = number ip = string gateway = string macaddr = string bridge = string })) default = [] } variable "vmid" { description = "virtual machine id" type = number default = 0 } variable "balloon" { description = "ballooning option" type = number default = 0 } variable "numa" { type = bool default = false } variable "storages" { description = "Default disks configuration (id, storage, size, storage_type)" type = list(object({ id = number storage = string size = string storage_type = string })) default = [{ id = 0 storage = "proxmox" size = "32G" storage_type = "cephfs" }] } variable "config" { description = "Local config to avoid duplication from the main module" type = map(string) } variable "pre_provision_steps" { description = "List of sequential provisioning steps to apply" type = list(string) default = [] } diff --git a/proxmox/terraform/production/production.tf b/proxmox/terraform/production/production.tf index bd23b54..38a9447 100644 --- a/proxmox/terraform/production/production.tf +++ b/proxmox/terraform/production/production.tf @@ -1,33 +1,35 @@ locals { config = { dns = var.dns domain = "internal.softwareheritage.org" puppet_environment = "production" + facter_deployment = "production" + facter_subnet = "sesi_rocquencourt" puppet_master = var.puppet_master gateway_ip = "192.168.100.1" user_admin = var.user_admin user_admin_ssh_public_key = var.user_admin_ssh_public_key user_admin_ssh_private_key_path = var.user_admin_ssh_private_key_path } } module "kelvingrove" { source = "../modules/node" config = local.config hostname = "kelvingrove" description = "Keycloak server" hypervisor = "hypervisor3" vmid = 123 cores = "4" memory = "8192" numa = true balloon = 0 networks = [{ id = 0 ip = "192.168.100.106" gateway = local.config["gateway_ip"] macaddr = "72:55:5E:58:01:0B" bridge = "vmbr0" }] } diff --git a/proxmox/terraform/staging/staging.tf b/proxmox/terraform/staging/staging.tf index 6107433..4f39340 100644 --- a/proxmox/terraform/staging/staging.tf +++ b/proxmox/terraform/staging/staging.tf @@ -1,370 +1,372 @@ # Keyword use: # - provider: Define the provider(s) # - data: Retrieve data information to be used within the file # - resource: Define resource and create/update # Default configuration passed along module calls # (There is no other way to avoid duplication) locals { config = { dns = var.dns domain = var.domain puppet_environment = var.puppet_environment + facter_deployment = "staging" + facter_subnet = "sesi_rocquencourt_staging" puppet_master = var.puppet_master gateway_ip = var.gateway_ip user_admin = var.user_admin user_admin_ssh_public_key = var.user_admin_ssh_public_key user_admin_ssh_private_key_path = var.user_admin_ssh_private_key_path } } module "scheduler0" { source = "../modules/node" config = local.config vmid = 116 hostname = "scheduler0" description = "Scheduler api services" hypervisor = "beaubourg" cores = "4" memory = "8192" balloon = 1024 networks = [{ id = 0 ip = "192.168.130.50" gateway = local.config["gateway_ip"] macaddr = "92:02:7E:D0:B9:36" bridge = "vmbr443" }] } output "scheduler0_summary" { value = module.scheduler0.summary } module "worker0" { source = "../modules/node" config = local.config vmid = 117 hostname = "worker0" description = "Loader/lister service node" hypervisor = "beaubourg" cores = "4" memory = "12288" balloon = 1024 networks = [{ id = 0 ip = "192.168.130.100" gateway = local.config["gateway_ip"] macaddr = "72:D9:03:46:B1:47" bridge = "vmbr443" }] } output "worker0_summary" { value = module.worker0.summary } module "worker1" { source = "../modules/node" config = local.config vmid = 118 hostname = "worker1" description = "Loader/lister service node" hypervisor = "beaubourg" cores = "4" memory = "12288" balloon = 1024 networks = [{ id = 0 ip = "192.168.130.101" gateway = local.config["gateway_ip"] macaddr = "D6:A9:6F:02:E3:66" bridge = "vmbr443" }] } output "worker1_summary" { value = module.worker1.summary } module "worker2" { source = "../modules/node" config = local.config vmid = 112 hostname = "worker2" description = "Loader/lister service node" hypervisor = "branly" cores = "4" memory = "12288" balloon = 1024 networks = [{ id = 0 ip = "192.168.130.102" gateway = local.config["gateway_ip"] macaddr = "AA:57:27:51:75:18" bridge = "vmbr443" }] } output "worker2_summary" { value = module.worker2.summary } module "webapp" { source = "../modules/node" config = local.config vmid = 119 hostname = "webapp" description = "Archive/Webapp service node" hypervisor = "branly" cores = "4" memory = "16384" balloon = 1024 networks = [{ id = 0 ip = "192.168.130.30" gateway = local.config["gateway_ip"] macaddr = "1A:00:39:95:D4:5F" bridge = "vmbr443" }] } output "webapp_summary" { value = module.webapp.summary } module "deposit" { source = "../modules/node" config = local.config vmid = 120 hostname = "deposit" description = "Deposit service node" hypervisor = "beaubourg" cores = "4" memory = "8192" balloon = 1024 networks = [{ id = 0 ip = "192.168.130.31" gateway = local.config["gateway_ip"] macaddr = "9E:81:DD:58:15:3B" bridge = "vmbr443" }] } output "deposit_summary" { value = module.deposit.summary } module "vault" { source = "../modules/node" config = local.config vmid = 121 hostname = "vault" description = "Vault services node" hypervisor = "beaubourg" cores = "4" memory = "8192" balloon = 1024 networks = [{ id = 0 ip = "192.168.130.60" gateway = local.config["gateway_ip"] macaddr = "16:15:1C:79:CB:DB" bridge = "vmbr443" }] } output "vault_summary" { value = module.vault.summary } module "journal0" { source = "../modules/node" config = local.config vmid = 122 hostname = "journal0" description = "Journal services node" hypervisor = "beaubourg" cores = "4" memory = "20000" balloon = 1024 networks = [{ id = 0 ip = "192.168.130.70" gateway = local.config["gateway_ip"] macaddr = "1E:98:C2:66:BF:33" bridge = "vmbr443" }] storages = [{ id = 0 storage = "proxmox" size = "32G" storage_type = "cephfs" }, { id = 1 storage = "proxmox" size = "500G" storage_type = "cephfs" }] } output "journal0_summary" { value = module.journal0.summary } module "rp0" { source = "../modules/node" config = local.config hypervisor = "branly" vmid = 129 hostname = "rp0" description = "Node to host the reverse proxy" cores = "2" memory = "2048" balloon = 1024 networks = [{ id = 0 ip = "192.168.130.20" gateway = local.config["gateway_ip"] macaddr = "4A:80:47:5D:DF:73" bridge = "vmbr443" }] # facter_subnet = "sesi_rocquencourt_staging" # factor_deployment = "staging" } output "rp0_summary" { value = module.rp0.summary } module "search-esnode0" { source = "../modules/node" config = local.config hypervisor = "branly" vmid = 130 hostname = "search-esnode0" description = "Node to host the elasticsearch instance" cores = "4" memory = "32768" balloon = 9216 networks = [{ id = 0 ip = "192.168.130.80" gateway = local.config["gateway_ip"] macaddr = "96:74:49:BD:B5:08" bridge = "vmbr443" }] storages = [{ id = 0 storage = "proxmox" size = "32G" storage_type = "cephfs" }, { id = 1 storage = "proxmox" size = "200G" storage_type = "cephfs" }] } output "search-esnode0_summary" { value = module.search-esnode0.summary } module "search0" { source = "../modules/node" config = local.config hypervisor = "branly" vmid = 131 hostname = "search0" description = "Node to host the swh-search rpc backend service" cores = "2" memory = "4096" balloon = 1024 networks = [{ id = 0 ip = "192.168.130.90" gateway = local.config["gateway_ip"] macaddr = "EE:FA:76:55:CF:99" bridge = "vmbr443" }] } output "search0_summary" { value = module.search0.summary } module "clearly-defined" { source = "../modules/node" config = local.config hypervisor = "branly" vmid = 132 hostname = "clearly-defined" description = "Node to host development for clearly defined" cores = "2" memory = "8192" balloon = 1024 networks = [{ id = 0 ip = "192.168.130.200" gateway = local.config["gateway_ip"] macaddr = "B6:C6:2E:D3:60:B2" bridge = "vmbr443" }] storages = [{ id = 0 storage = "proxmox" size = "32G" storage_type = "cephfs" }, { id = 1 storage = "proxmox" size = "100G" storage_type = "cephfs" }] } output "clearly-defined_summary" { value = module.clearly-defined.summary } module "objstorage0" { source = "../modules/node" config = local.config hypervisor = "pompidou" vmid = 102 hostname = "objstorage0" description = "Node to host a read-only objstorage for mirrors" cores = "2" memory = "4096" balloon = 1024 networks = [{ id = 0 ip = "192.168.130.110" gateway = local.config["gateway_ip"] macaddr = "5E:28:EA:7D:50:0D" bridge = "vmbr443" }] } output "objstorage0_summary" { value = module.objstorage0.summary }