diff --git a/proxmox/terraform/modules/node/main.tf b/proxmox/terraform/modules/node/main.tf --- a/proxmox/terraform/modules/node/main.tf +++ b/proxmox/terraform/modules/node/main.tf @@ -89,7 +89,9 @@ "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!'", - ]) + ], + var.post_provision_steps, + ) connection { type = "ssh" diff --git a/proxmox/terraform/modules/node/variables.tf b/proxmox/terraform/modules/node/variables.tf --- a/proxmox/terraform/modules/node/variables.tf +++ b/proxmox/terraform/modules/node/variables.tf @@ -54,7 +54,7 @@ id = number ip = string gateway = string - macaddr = string + macaddr = optional(string) bridge = string })) default = [] @@ -102,7 +102,13 @@ } variable "pre_provision_steps" { - description = "List of sequential provisioning steps to apply" + description = "Sequential provisioning steps to apply *before* common provision steps" + type = list(string) + default = [] +} + +variable "post_provision_steps" { + description = "Sequential provisioning steps to apply *after* common provision steps" type = list(string) default = [] } diff --git a/proxmox/terraform/staging/rancher.tf b/proxmox/terraform/staging/rancher.tf --- a/proxmox/terraform/staging/rancher.tf +++ b/proxmox/terraform/staging/rancher.tf @@ -39,5 +39,42 @@ } output "rancher2_cluster_command" { + sensitive = true value = rancher2_cluster.staging-workers.cluster_registration_token[0].node_command } + +module "elastic-worker0" { + source = "../modules/node" + template = "debian-bullseye-11.3-zfs-2022-04-21" + config = local.config + hostname = "elastic-worker0" + description = "elastic worker running in rancher cluster" + hypervisor = "uffizi" + sockets = "1" + cores = "4" + onboot = true + memory = "4096" + balloon = "1024" + + networks = [{ + id = 0 + ip = "192.168.130.130" + gateway = local.config["gateway_ip"] + bridge = "vmbr443" + }] + + storages = [{ + storage = "proxmox" + size = "50G" + } + ] + + # Let the node registered itself to the cluster rancher + post_provision_steps = [ + rancher2_cluster.staging-workers.cluster_registration_token[0].node_command + ] +} + +output "elastic-worker0_summary" { + value = module.elastic-worker0.summary +} diff --git a/proxmox/terraform/versions.tf b/proxmox/terraform/versions.tf --- a/proxmox/terraform/versions.tf +++ b/proxmox/terraform/versions.tf @@ -1,5 +1,6 @@ terraform { required_version = ">= 0.13" + experiments = [module_variable_optional_attrs] required_providers { proxmox = { source = "telmate/proxmox" @@ -16,7 +17,7 @@ pm_tls_insecure = true pm_api_url = "https://beaubourg.internal.softwareheritage.org:8006/api2/json" # in a shell (see README): source ../setup.sh - + # Uncomment this section to activate the proxmox execution logs # pm_log_enable = true # pm_log_file = "terraform-plugin-proxmox.log"