Skip to content

Commit

Permalink
chore: make module more generic (#4)
Browse files Browse the repository at this point in the history
- Remove default value for `bootable_iso` variable
- Remove variable `template_to_clone`
- Add more validation for `resource_allocation` and `skip_vm_id`, and
`vm_count` variables
- Remove validation for `storage_name` variable
  • Loading branch information
hazmei authored Jul 18, 2024
1 parent 0f8c3ae commit f8bb1cd
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 21 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,18 @@ No modules.

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_bootable_iso"></a> [bootable\_iso](#input\_bootable\_iso) | The ISO file name to boot from | `string` | `"ssd:iso/talos-nocloud-amd64.iso"` | no |
| <a name="input_bootable_iso"></a> [bootable\_iso](#input\_bootable\_iso) | The ISO file name to boot from | `string` | n/a | yes |
| <a name="input_name"></a> [name](#input\_name) | The suffix to use for the cloud-init and VM | `string` | n/a | yes |
| <a name="input_network"></a> [network](#input\_network) | The network configuration for ip cidr, hostnum, gateway, and dns nameserver | <pre>object({<br> ip_subnet = optional(string, "10.255.0.0")<br> ip_hostnum = optional(number, 200)<br> ip_prefix = optional(number, 24)<br> ip_gateway = string<br> dns_nameservers = optional(list(string), ["1.1.1.1", "8.8.8.8"])<br> })</pre> | n/a | yes |
| <a name="input_resource_allocation"></a> [resource\_allocation](#input\_resource\_allocation) | The resource amount to allocation for CPU, Memory, and Storage | <pre>object({<br> cores = optional(number, 1)<br> vcpus = optional(number, 1)<br> sockets = optional(number, 1)<br> memory = optional(number, 256)<br> storage = optional(string, 128)<br> })</pre> | <pre>{<br> "cores": 1,<br> "memory": 256,<br> "sockets": 1,<br> "storage": 128,<br> "vcpus": 1<br>}</pre> | no |
| <a name="input_skip_vm_id"></a> [skip\_vm\_id](#input\_skip\_vm\_id) | The number to increment for VM ids | `number` | `0` | no |
| <a name="input_storage_name"></a> [storage\_name](#input\_storage\_name) | The storage to deploy to | `string` | `"ssd"` | no |
| <a name="input_target_node"></a> [target\_node](#input\_target\_node) | The target node to deploy to | `string` | `"pve"` | no |
| <a name="input_template_to_clone"></a> [template\_to\_clone](#input\_template\_to\_clone) | Template name to clone for the VM | `string` | `null` | no |
| <a name="input_user_data"></a> [user\_data](#input\_user\_data) | n/a | `any` | n/a | yes |
| <a name="input_user_data"></a> [user\_data](#input\_user\_data) | The user-data config to supply for cloud-init | `string` | `""` | no |
| <a name="input_vm_count"></a> [vm\_count](#input\_vm\_count) | Number of VMs to create | `number` | `1` | no |
| <a name="input_vm_onboot"></a> [vm\_onboot](#input\_vm\_onboot) | Whether to have the VM startup after PVE node starts | `bool` | `false` | no |
| <a name="input_vm_protection"></a> [vm\_protection](#input\_vm\_protection) | Enable/disable the VM protection from being removed | `bool` | `false` | no |
| <a name="input_vm_state"></a> [vm\_state](#input\_vm\_state) | The state of the VM | `string` | `"running"` | no |
| <a name="input_vm_state"></a> [vm\_state](#input\_vm\_state) | The state of the VM after creation | `string` | `"running"` | no |

## Outputs

Expand Down
4 changes: 0 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ resource "proxmox_vm_qemu" "this" {
vmid = 5000 + var.skip_vm_id + count.index
target_node = var.target_node

# template to clone
clone = var.template_to_clone
full_clone = true

onboot = var.vm_onboot
vm_state = var.vm_state
protection = var.vm_protection
Expand Down
52 changes: 39 additions & 13 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,13 @@ variable "target_node" {
variable "storage_name" {
description = "The storage to deploy to"
type = string
default = "ssd" # or local-lvm

validation {
condition = contains(["local-lvm", "ssd"], var.storage_name)
error_message = "Valid values for var: storage_name are (local-lvm, ssd)."
}
default = "ssd"
}

variable "user_data" {}

variable "template_to_clone" {
description = "Template name to clone for the VM"
variable "user_data" {
description = "The user-data config to supply for cloud-init"
type = string
default = null
default = ""
}

variable "vm_onboot" {
Expand All @@ -35,7 +28,7 @@ variable "vm_onboot" {
}

variable "vm_state" {
description = "The state of the VM"
description = "The state of the VM after creation"
type = string
default = "running"

Expand All @@ -55,6 +48,11 @@ variable "vm_count" {
description = "Number of VMs to create"
type = number
default = 1

validation {
condition = var.vm_count > 0
error_message = "Variable vm_count cannot be less than 1."
}
}

variable "resource_allocation" {
Expand All @@ -73,6 +71,30 @@ variable "resource_allocation" {
memory = 256
storage = 128
}
validation {
condition = var.resource_allocation.cores > var.resource_allocation.vcpus
error_message = "CPU cores cannot be lesser than VCPUs."
}
validation {
condition = var.resource_allocation.cores > 0
error_message = "CPU cores cannot be less than 1"
}
validation {
condition = var.resource_allocation.vcpus > 0
error_message = "VCPUs cannot be less than 1"
}
validation {
condition = var.resource_allocation.sockets > 0
error_message = "CPU socket cannot be less than 1"
}
validation {
condition = var.resource_allocation.memory > 0
error_message = "Memory cannot be less than 1GB"
}
validation {
condition = var.resource_allocation.storage > 0
error_message = "Storage cannot be less than 1GB"
}
}

variable "network" {
Expand All @@ -89,11 +111,15 @@ variable "network" {
variable "bootable_iso" {
description = "The ISO file name to boot from"
type = string
default = "ssd:iso/talos-nocloud-amd64.iso"
}

variable "skip_vm_id" {
description = "The number to increment for VM ids"
type = number
default = 0

validation {
condition = var.skip_vm_id >= 0
error_message = "Variable skip_vm_id cannot be less than 0."
}
}

0 comments on commit f8bb1cd

Please sign in to comment.