Add first module : Gitea app
This commit is contained in:
0
modules/vm/cloud-init/meta_data
Normal file
0
modules/vm/cloud-init/meta_data
Normal file
78
modules/vm/main.tf
Normal file
78
modules/vm/main.tf
Normal file
@@ -0,0 +1,78 @@
|
||||
terraform {
|
||||
required_providers {
|
||||
proxmox = {
|
||||
source = "bpg/proxmox"
|
||||
version = "0.42.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "proxmox_virtual_environment_file" "cloud_user_config" {
|
||||
content_type = "snippets"
|
||||
datastore_id = "local"
|
||||
node_name = var.node_name
|
||||
|
||||
source_raw {
|
||||
data = var.cloudinit_config
|
||||
|
||||
file_name = "${var.hostname}.${var.domain}-user.yaml"
|
||||
}
|
||||
}
|
||||
|
||||
resource "proxmox_virtual_environment_file" "cloud_meta_config" {
|
||||
content_type = "snippets"
|
||||
datastore_id = "local"
|
||||
node_name = var.node_name
|
||||
|
||||
source_raw {
|
||||
data = templatefile("${path.module}/cloud-init/meta_data",
|
||||
{
|
||||
instance_id = sha1(var.hostname)
|
||||
local_hostname = var.hostname
|
||||
}
|
||||
)
|
||||
|
||||
file_name = "${var.hostname}.${var.domain}-meta_data.yaml"
|
||||
}
|
||||
}
|
||||
|
||||
resource "proxmox_virtual_environment_vm" "vm" {
|
||||
name = var.name
|
||||
vm_id = var.vm_id
|
||||
node_name = var.node_name
|
||||
|
||||
clone {
|
||||
vm_id = var.template_id
|
||||
}
|
||||
|
||||
cpu {
|
||||
cores = var.cores
|
||||
}
|
||||
|
||||
memory {
|
||||
dedicated = var.memory
|
||||
}
|
||||
|
||||
disk {
|
||||
interface = "scsi0"
|
||||
iothread = true
|
||||
datastore_id = "local-lvm"
|
||||
size = var.disk_size
|
||||
discard = "ignore"
|
||||
}
|
||||
|
||||
agent {
|
||||
enabled = true
|
||||
}
|
||||
|
||||
network_device {
|
||||
bridge = "vmbr0"
|
||||
}
|
||||
|
||||
initialization {
|
||||
datastore_id = "local-lvm"
|
||||
interface = "ide2"
|
||||
user_data_file_id = proxmox_virtual_environment_file.cloud_user_config.id
|
||||
meta_data_file_id = proxmox_virtual_environment_file.cloud_meta_config.id
|
||||
}
|
||||
}
|
||||
7
modules/vm/outputs.tf
Normal file
7
modules/vm/outputs.tf
Normal file
@@ -0,0 +1,7 @@
|
||||
output "vm_name" {
|
||||
value = proxmox_virtual_environment_vm.vm.name
|
||||
}
|
||||
|
||||
output "vm_id" {
|
||||
value = proxmox_virtual_environment_vm.vm.vm_id
|
||||
}
|
||||
56
modules/vm/variables.tf
Normal file
56
modules/vm/variables.tf
Normal file
@@ -0,0 +1,56 @@
|
||||
variable "name" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "vm_id" {
|
||||
type = number
|
||||
}
|
||||
|
||||
variable "node_name" {
|
||||
type = string
|
||||
default = "mop"
|
||||
}
|
||||
|
||||
variable "cores" {
|
||||
type = number
|
||||
default = 2
|
||||
}
|
||||
|
||||
variable "memory" {
|
||||
type = number
|
||||
default = 2048
|
||||
}
|
||||
|
||||
variable "template_id" {
|
||||
type = number
|
||||
}
|
||||
|
||||
variable "ssh_public_key" {
|
||||
type = string
|
||||
description = "Public SSH key for cloud-init user"
|
||||
}
|
||||
|
||||
variable "hostname" {
|
||||
description = "VM hostname"
|
||||
type = string
|
||||
default = "test"
|
||||
}
|
||||
|
||||
variable "domain" {
|
||||
description = "VM domain"
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "disk_size" {
|
||||
type = number
|
||||
default = 10
|
||||
}
|
||||
|
||||
variable "proxmox_host_ip" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "cloudinit_config" {
|
||||
type = string
|
||||
}
|
||||
Reference in New Issue
Block a user