Compare commits
17 Commits
v0.0.4
...
e2e930045c
Author | SHA1 | Date | |
---|---|---|---|
e2e930045c | |||
f5412c3138 | |||
7043a580ca | |||
9dfd085877 | |||
985fd624ce | |||
e785cf9df0 | |||
05711c4bbd | |||
5059720757 | |||
b209942b3d | |||
f821f97b9e | |||
e42ce275c1 | |||
6a9181d1b4 | |||
e07fd1c49d | |||
f2864ecc84 | |||
55a9334df3 | |||
97624cb42d | |||
e8140d8b3f |
@ -1,3 +1,9 @@
|
|||||||
# terracadoles
|
# terracadoles
|
||||||
|
|
||||||
Cadoles Terraform modules
|
Cadoles Terraform modules
|
||||||
|
|
||||||
|
## Modules
|
||||||
|
|
||||||
|
* virtualMachine
|
||||||
|
* dns
|
||||||
|
* nebula
|
120
modules/nebula/main.tf
Normal file
120
modules/nebula/main.tf
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
variable "vms" {
|
||||||
|
type = map
|
||||||
|
description = "Virtual Machines description"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "image_format" {
|
||||||
|
default = "qcow2"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "dev_prefix" {
|
||||||
|
default = "sd"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "permissions" {
|
||||||
|
default = "600"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "graphics" {
|
||||||
|
default = {
|
||||||
|
keymap = "fr"
|
||||||
|
listen = "0.0.0.0"
|
||||||
|
type = "VNC"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "one_prod_ds" {
|
||||||
|
default = "101"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "one_sys_datastore" {
|
||||||
|
default = "100"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// system image
|
||||||
|
resource "opennebula_image" "system" {
|
||||||
|
for_each = var.vms
|
||||||
|
|
||||||
|
name = "system-${each.key}.${each.value.domain}"
|
||||||
|
description = "System disk for ${each.key}"
|
||||||
|
datastore_id = var.one_prod_ds
|
||||||
|
path = "https://vulcain.cadoles.com/empty_20G"
|
||||||
|
persistent = each.value.system_image_persistent
|
||||||
|
format = var.image_format
|
||||||
|
dev_prefix = var.dev_prefix
|
||||||
|
permissions = var.permissions
|
||||||
|
}
|
||||||
|
|
||||||
|
/* data image not needed now
|
||||||
|
resource "opennebula_image" "data" {
|
||||||
|
for_each = var.vms
|
||||||
|
|
||||||
|
name = "data-${each.key}.${each.value.domain}"
|
||||||
|
path = "https://vulcain.cadoles.com/empty_40G"
|
||||||
|
datastore_id = var.one_prod_ds
|
||||||
|
description = "data disk for ${each.key}"
|
||||||
|
persistent = each.value.data_image_persistent
|
||||||
|
format = var.image_format
|
||||||
|
dev_prefix = var.dev_prefix
|
||||||
|
permissions = var.permissions
|
||||||
|
}*/
|
||||||
|
|
||||||
|
resource "opennebula_template" "vm_template" {
|
||||||
|
for_each = var.vms
|
||||||
|
|
||||||
|
name = "${each.key}.${each.value.domain}"
|
||||||
|
cpu = each.value.cpu
|
||||||
|
vcpu = each.value.vcpu
|
||||||
|
memory = each.value.ram
|
||||||
|
graphics {
|
||||||
|
keymap = var.graphics.keymap
|
||||||
|
listen = var.graphics.listen
|
||||||
|
type = var.graphics.type
|
||||||
|
}
|
||||||
|
context = {
|
||||||
|
SET_HOSTNAME = "$NAME"
|
||||||
|
DNS_HOSTNAME = "YES"
|
||||||
|
NETWORK = "YES"
|
||||||
|
SSH_PUBLIC_KEY = "$USER[SSH_PUBLIC_KEY]"
|
||||||
|
USERNAME = "root"
|
||||||
|
}
|
||||||
|
disk {
|
||||||
|
image_id = opennebula_image.system[each.key].id
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Not needed now
|
||||||
|
disk {
|
||||||
|
image_id = opennebula_image.data[each.key].id
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
sched_ds_requirements = ( each.value.sysdatastore != "" ? each.value.sysdatastore : var.one_sys_datastore )
|
||||||
|
|
||||||
|
os {
|
||||||
|
arch = "x86_64"
|
||||||
|
boot = "disk0,nic0"
|
||||||
|
}
|
||||||
|
//labels = var.tag_labels
|
||||||
|
|
||||||
|
dynamic "nic" {
|
||||||
|
for_each = each.value.network_interfaces
|
||||||
|
|
||||||
|
content {
|
||||||
|
network_id = nic.value.network_id
|
||||||
|
model = "virtio"
|
||||||
|
mac = nic.value.mac
|
||||||
|
}
|
||||||
|
}
|
||||||
|
permissions = var.permissions
|
||||||
|
depends_on = [ opennebula_image.system,
|
||||||
|
opennebula_image.data ]
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "opennebula_virtual_machine" "vm" {
|
||||||
|
for_each = var.vms
|
||||||
|
name = "${each.key}.${each.value.domain}"
|
||||||
|
template_id = opennebula_template.vm_template[each.key].id
|
||||||
|
depends_on = [ opennebula_template.vm_template ]
|
||||||
|
}
|
11
modules/nebula/output.tf
Normal file
11
modules/nebula/output.tf
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
output "shortnames" {
|
||||||
|
value = keys(var.vms)
|
||||||
|
}
|
||||||
|
|
||||||
|
output "first_macs" {
|
||||||
|
value = opennebula_virtual_machine.vm //FIXME .template_nic[0].computed_mac
|
||||||
|
}
|
||||||
|
|
||||||
|
output "virtual_machines" {
|
||||||
|
value = opennebula_virtual_machine.vm //template_nic[0].computed_mac)
|
||||||
|
}
|
9
modules/nebula/version.tf
Normal file
9
modules/nebula/version.tf
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
terraform {
|
||||||
|
required_providers {
|
||||||
|
opennebula = {
|
||||||
|
source = "OpenNebula/opennebula"
|
||||||
|
version = "~> 1.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
7
modules/virtualMachine/locals.tf
Normal file
7
modules/virtualMachine/locals.tf
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
locals {
|
||||||
|
fqdn = "${var.vm_shortname}.${var.vm_domain}"
|
||||||
|
system_image_name = "system.${local.fqdn}"
|
||||||
|
system_image_source = var.system_image_source
|
||||||
|
data_image_name = "data.${local.fqdn}"
|
||||||
|
group = "${var.group}"
|
||||||
|
}
|
@ -1,3 +1,7 @@
|
|||||||
|
resource "opennebula_group" "main" {
|
||||||
|
name = var.group
|
||||||
|
}
|
||||||
|
|
||||||
// OpenNebula disk image !
|
// OpenNebula disk image !
|
||||||
resource "opennebula_image" "system" {
|
resource "opennebula_image" "system" {
|
||||||
name = local.system_image_name
|
name = local.system_image_name
|
||||||
@ -24,7 +28,7 @@ resource "opennebula_image" "data" {
|
|||||||
driver = "qcow2"
|
driver = "qcow2"
|
||||||
format = "qcow2"
|
format = "qcow2"
|
||||||
permissions = "660"
|
permissions = "660"
|
||||||
group = "production"
|
group = var.group
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenNebula (VM) Template definition
|
// OpenNebula (VM) Template definition
|
||||||
@ -52,6 +56,10 @@ resource "opennebula_template" "vm_template" {
|
|||||||
image_id = opennebula_image.data.id
|
image_id = opennebula_image.data.id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
os {
|
||||||
|
arch = "x86_64"
|
||||||
|
boot = "disk0,nic0"
|
||||||
|
}
|
||||||
//labels = var.tag_labels
|
//labels = var.tag_labels
|
||||||
|
|
||||||
dynamic "nic" {
|
dynamic "nic" {
|
||||||
|
@ -3,7 +3,7 @@ output "shortname" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
output "fqdn" {
|
output "fqdn" {
|
||||||
value = var.vm_fqdn
|
value = local.fqdn
|
||||||
}
|
}
|
||||||
|
|
||||||
output "first_nic_mac" {
|
output "first_nic_mac" {
|
||||||
|
@ -8,11 +8,6 @@ variable "one_prod_ds" {
|
|||||||
type = string
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "vm_fqdn" {
|
|
||||||
description = "Virtual Machine FQDN Name"
|
|
||||||
type = string
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "vm_shortname" {
|
variable "vm_shortname" {
|
||||||
description = "Virtual machine short name"
|
description = "Virtual machine short name"
|
||||||
type = string
|
type = string
|
||||||
@ -23,24 +18,12 @@ variable "vm_domain" {
|
|||||||
type = string
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "system_image_name" {
|
|
||||||
description = "System image disk name"
|
|
||||||
type = string
|
|
||||||
default = "${var.vm_shortname}.system"
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "system_image_source" {
|
variable "system_image_source" {
|
||||||
description = "Virtual Machine system image source"
|
description = "Virtual Machine system image source"
|
||||||
type = string
|
type = string
|
||||||
default = "https://marketplace.opennebula.io//appliance/251b0578-6c47-4ba4-b184-dc6e873201a2/download/0"
|
default = "https://marketplace.opennebula.io//appliance/251b0578-6c47-4ba4-b184-dc6e873201a2/download/0"
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "data_image_name" {
|
|
||||||
description = "Data image disk name"
|
|
||||||
type = string
|
|
||||||
default = "${var.vm_shortname}.data"
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "data_image_source" {
|
variable "data_image_source" {
|
||||||
description = "Virtual Machine data disk image source"
|
description = "Virtual Machine data disk image source"
|
||||||
type = string
|
type = string
|
||||||
@ -60,16 +43,19 @@ variable "network_interfaces" {
|
|||||||
variable "cpu" {
|
variable "cpu" {
|
||||||
description = "VM CPU"
|
description = "VM CPU"
|
||||||
type = string
|
type = string
|
||||||
|
default = "0.2"
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "vcpu" {
|
variable "vcpu" {
|
||||||
description = "VM vCPU"
|
description = "VM vCPU"
|
||||||
type = string
|
type = string
|
||||||
|
default = "2"
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "ram" {
|
variable "ram" {
|
||||||
description = "VM RAM"
|
description = "VM RAM"
|
||||||
type = string
|
type = string
|
||||||
|
default = "512"
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "depends" {
|
variable "depends" {
|
||||||
@ -109,5 +95,5 @@ variable "graphics" {
|
|||||||
variable "imagemode" {
|
variable "imagemode" {
|
||||||
description = "Disk image mode"
|
description = "Disk image mode"
|
||||||
type = string
|
type = string
|
||||||
default = "0600"
|
default = "600"
|
||||||
}
|
}
|
Reference in New Issue
Block a user