Compare commits
41 Commits
Author | SHA1 | Date |
---|---|---|
Philippe Caseiro | 4aba5c317d | |
Philippe Caseiro | 1ab2c571a6 | |
Philippe Caseiro | 643c8e7547 | |
pcaseiro | b565e85350 | |
Philippe Caseiro | 2b39ee3e29 | |
Philippe Caseiro | a49d95b450 | |
Philippe Caseiro | 74d13e5f4c | |
Philippe Caseiro | b9d7f4e414 | |
Philippe Caseiro | b1de088d87 | |
Philippe Caseiro | d02e96d4f1 | |
Philippe Caseiro | 58441c69b6 | |
Philippe Caseiro | 814ef36bb7 | |
Philippe Caseiro | 9c077553d8 | |
Philippe Caseiro | 77eec91bf1 | |
Philippe Caseiro | a8c3955121 | |
Philippe Caseiro | 0acf9bfc87 | |
Philippe Caseiro | 18365fdf80 | |
Philippe Caseiro | 75babdbff8 | |
Philippe Caseiro | 85bb5d597d | |
Philippe Caseiro | d02ec11cb9 | |
Philippe Caseiro | b214694cec | |
Philippe Caseiro | e2e930045c | |
Philippe Caseiro | f5412c3138 | |
Philippe Caseiro | 7043a580ca | |
Philippe Caseiro | 9dfd085877 | |
Philippe Caseiro | 985fd624ce | |
Philippe Caseiro | e785cf9df0 | |
Philippe Caseiro | 05711c4bbd | |
Philippe Caseiro | 5059720757 | |
Philippe Caseiro | b209942b3d | |
Philippe Caseiro | f821f97b9e | |
Philippe Caseiro | e42ce275c1 | |
Philippe Caseiro | 6a9181d1b4 | |
Philippe Caseiro | e07fd1c49d | |
Philippe Caseiro | f2864ecc84 | |
Philippe Caseiro | 55a9334df3 | |
Philippe Caseiro | 97624cb42d | |
Philippe Caseiro | e8140d8b3f | |
Philippe Caseiro | 9f05f09e5d | |
Philippe Caseiro | 4a676480fb | |
Philippe Caseiro | 911486e0e0 |
|
@ -1,3 +1,10 @@
|
|||
# terracadoles
|
||||
|
||||
Cadoles Terraform modules
|
||||
Cadoles Terraform modules
|
||||
|
||||
## Modules
|
||||
|
||||
* virtualMachine
|
||||
* dns
|
||||
* nebula
|
||||
* vmware
|
|
@ -0,0 +1,163 @@
|
|||
variable "vms" {
|
||||
type = map(object(
|
||||
{
|
||||
domain = string
|
||||
cpu = number
|
||||
vcpu = number
|
||||
ram = number
|
||||
system_image_persistent = bool
|
||||
data_disks = list(object({
|
||||
name = string
|
||||
size = string
|
||||
persistent = bool
|
||||
}))
|
||||
network_interfaces = list(object({
|
||||
network_id = string
|
||||
ip = string
|
||||
mac = string
|
||||
}))
|
||||
sysdatastore = string
|
||||
}
|
||||
))
|
||||
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_image_ds" {
|
||||
default = "101"
|
||||
}
|
||||
|
||||
variable "one_sys_datastore" {
|
||||
default = "100"
|
||||
}
|
||||
|
||||
locals {
|
||||
data_disks = flatten([
|
||||
for vm_key, vm in var.vms : [
|
||||
for disk in vm.data_disks : {
|
||||
vm_key = "${vm_key}.${vm.domain}"
|
||||
name = disk.name
|
||||
size = disk.size
|
||||
persist = disk.persistent
|
||||
}
|
||||
]
|
||||
])
|
||||
}
|
||||
|
||||
// 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_image_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 = {
|
||||
for ds in local.data_disks : "${ds.vm_key}.${ds.name}" => ds
|
||||
}
|
||||
|
||||
name = "${each.value.vm_key}-data-${each.value.name}"
|
||||
path = "https://vulcain.cadoles.com/empty_${each.value.size}"
|
||||
datastore_id = var.one_image_ds
|
||||
description = "Data disk of ${each.value.size} for ${each.value.vm_key}"
|
||||
persistent = each.value.persist
|
||||
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
|
||||
}
|
||||
|
||||
dynamic "disk" {
|
||||
for_each = {
|
||||
for ds in local.data_disks : "${ds.vm_key}.${ds.name}" => ds if "${each.key}.${each.value.domain}" == ds.vm_key
|
||||
}
|
||||
iterator = current_disk
|
||||
content {
|
||||
image_id = opennebula_image.data[current_disk.key].id
|
||||
}
|
||||
}
|
||||
|
||||
//sched_ds_requirements = ( each.value.sysdatastore != "" ? "ID=\"${each.value.sysdatastore}\"" : "ID=\"${var.one_sys_datastore}\"" )
|
||||
sched_ds_requirements = ( each.value.sysdatastore != "" ? "ID=\"${each.value.sysdatastore}\"" : "" )
|
||||
|
||||
os {
|
||||
arch = "x86_64"
|
||||
boot = "disk0,nic0"
|
||||
}
|
||||
|
||||
dynamic "nic" {
|
||||
for_each = each.value.network_interfaces
|
||||
|
||||
content {
|
||||
network_id = nic.value.network_id
|
||||
model = "virtio"
|
||||
mac = ( nic.value.mac != "" ? nic.value.mac : "" )
|
||||
ip = ( nic.value.ip != "" ? nic.value.ip : "" )
|
||||
}
|
||||
}
|
||||
permissions = var.permissions
|
||||
depends_on = [ opennebula_image.system ]
|
||||
|
||||
/* Not needed now
|
||||
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 ]
|
||||
}
|
|
@ -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)
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
terraform {
|
||||
required_providers {
|
||||
opennebula = {
|
||||
source = "OpenNebula/opennebula"
|
||||
version = "~> 1.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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,13 +1,10 @@
|
|||
// Dependencies management
|
||||
resource "null_resource" "depends_on" {
|
||||
triggers = {
|
||||
depends_on = join("", var.depends)
|
||||
}
|
||||
resource "opennebula_group" "main" {
|
||||
name = var.group
|
||||
}
|
||||
|
||||
// OpenNebula disk image !
|
||||
resource "opennebula_image" "system" {
|
||||
name = var.system_image_name
|
||||
name = local.system_image_name
|
||||
description = "System disk image"
|
||||
datastore_id = var.one_prod_ds
|
||||
persistent = false
|
||||
|
@ -21,7 +18,7 @@ resource "opennebula_image" "system" {
|
|||
}
|
||||
|
||||
resource "opennebula_image" "data" {
|
||||
name = var.data_image_name
|
||||
name = local.data_image_name
|
||||
description = "Data disk image"
|
||||
datastore_id = var.one_prod_ds
|
||||
persistent = true
|
||||
|
@ -31,7 +28,7 @@ resource "opennebula_image" "data" {
|
|||
driver = "qcow2"
|
||||
format = "qcow2"
|
||||
permissions = "660"
|
||||
group = "production"
|
||||
group = var.group
|
||||
}
|
||||
|
||||
// OpenNebula (VM) Template definition
|
||||
|
@ -59,6 +56,10 @@ resource "opennebula_template" "vm_template" {
|
|||
image_id = opennebula_image.data.id
|
||||
}
|
||||
|
||||
os {
|
||||
arch = "x86_64"
|
||||
boot = "disk0,nic0"
|
||||
}
|
||||
//labels = var.tag_labels
|
||||
|
||||
dynamic "nic" {
|
||||
|
@ -78,12 +79,10 @@ resource "opennebula_template" "vm_template" {
|
|||
|
||||
// OpenNebula Virtual Machine
|
||||
resource "opennebula_virtual_machine" "vm" {
|
||||
name = var.vm_fqdn
|
||||
name = local.fqdn
|
||||
group = var.group
|
||||
timeout = 10
|
||||
template_id = opennebula_template.vm_template.id
|
||||
depends_on = [ opennebula_template.vm_template,
|
||||
null_resource.depends_on ]
|
||||
depends_on = [ opennebula_template.vm_template ]
|
||||
}
|
||||
|
||||
resource "dns_a_record_set" "vm_dns_a_record" {
|
||||
|
@ -102,7 +101,7 @@ resource "dns_cname_record" "vm_dns_cname_record" {
|
|||
|
||||
zone = var.vm_domain
|
||||
name = each.value
|
||||
cname = "${var.vm_fqdn}."
|
||||
cname = "${local.fqdn}."
|
||||
ttl = 300
|
||||
|
||||
depends_on = [ opennebula_virtual_machine.vm ]
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
output "virtual_machine_shortname" {
|
||||
output "shortname" {
|
||||
value = opennebula_virtual_machine.vm.name
|
||||
}
|
||||
|
||||
output "virtual_machine_nic0_mac" {
|
||||
value = opennebula_virtual_machine.vm.nic[0].mac
|
||||
output "fqdn" {
|
||||
value = local.fqdn
|
||||
}
|
||||
|
||||
output "first_nic_mac" {
|
||||
value = opennebula_virtual_machine.vm.template_nic[0].computed_mac
|
||||
}
|
||||
|
||||
output "network_interfaces" {
|
||||
|
|
|
@ -8,11 +8,6 @@ variable "one_prod_ds" {
|
|||
type = string
|
||||
}
|
||||
|
||||
variable "vm_fqdn" {
|
||||
description = "Virtual Machine FQDN Name"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "vm_shortname" {
|
||||
description = "Virtual machine short name"
|
||||
type = string
|
||||
|
@ -23,24 +18,16 @@ variable "vm_domain" {
|
|||
type = string
|
||||
}
|
||||
|
||||
variable "system_image_name" {
|
||||
description = "System image disk name"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "system_image_source" {
|
||||
description = "Virtual Machine system image source"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "data_image_name" {
|
||||
description = "Data image disk name"
|
||||
type = string
|
||||
default = "https://marketplace.opennebula.io//appliance/251b0578-6c47-4ba4-b184-dc6e873201a2/download/0"
|
||||
}
|
||||
|
||||
variable "data_image_source" {
|
||||
description = "Virtual Machine data disk image source"
|
||||
type = string
|
||||
default = "https://marketplace.opennebula.io//appliance/251b0578-6c47-4ba4-b184-dc6e873201a2/download/0"
|
||||
}
|
||||
|
||||
variable "tag_labels" {
|
||||
|
@ -56,16 +43,19 @@ variable "network_interfaces" {
|
|||
variable "cpu" {
|
||||
description = "VM CPU"
|
||||
type = string
|
||||
default = "0.2"
|
||||
}
|
||||
|
||||
variable "vcpu" {
|
||||
description = "VM vCPU"
|
||||
type = string
|
||||
default = "2"
|
||||
}
|
||||
|
||||
variable "ram" {
|
||||
description = "VM RAM"
|
||||
type = string
|
||||
default = "512"
|
||||
}
|
||||
|
||||
variable "depends" {
|
||||
|
@ -100,5 +90,10 @@ variable "graphics" {
|
|||
listen = "0.0.0.0"
|
||||
type = "VNC"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
variable "imagemode" {
|
||||
description = "Disk image mode"
|
||||
type = string
|
||||
default = "600"
|
||||
}
|
|
@ -7,7 +7,8 @@ terraform {
|
|||
source = "hashicorp/null"
|
||||
}
|
||||
opennebula = {
|
||||
source = "terraform-providers/opennebula"
|
||||
source = "OpenNebula/opennebula"
|
||||
version = "~> 1.0"
|
||||
}
|
||||
}
|
||||
required_version = ">= 0.13"
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
data "vsphere_datacenter" "datacenter" {
|
||||
name = var.cluster.datacenter_name
|
||||
}
|
||||
|
||||
data "vsphere_datastore" "datastore" {
|
||||
name = var.cluster.datastore_name
|
||||
datacenter_id = data.vsphere_datacenter.datacenter.id
|
||||
}
|
||||
|
||||
data "vsphere_resource_pool" "pool" {
|
||||
name = var.cluster.resource_pool_name
|
||||
datacenter_id = data.vsphere_datacenter.datacenter.id
|
||||
}
|
||||
|
||||
data "vsphere_host" "host" {
|
||||
name = "10.253.10.50"
|
||||
datacenter_id = data.vsphere_datacenter.datacenter.id
|
||||
}
|
||||
|
||||
data "vsphere_network" "network" {
|
||||
for_each = var.cluster.vnets
|
||||
|
||||
name = each.value.name
|
||||
datacenter_id = data.vsphere_datacenter.datacenter.id
|
||||
}
|
||||
|
||||
resource "vsphere_virtual_machine" "vm" {
|
||||
for_each = var.vms
|
||||
name = "${each.key}.${each.value.domain}"
|
||||
resource_pool_id = data.vsphere_resource_pool.pool.id
|
||||
datastore_id = data.vsphere_datastore.datastore.id
|
||||
folder = each.value.folder
|
||||
num_cpus = each.value.cpu
|
||||
memory = each.value.ram
|
||||
guest_id = each.value.guest_id
|
||||
firmware = each.value.firmware
|
||||
|
||||
dynamic "network_interface" {
|
||||
for_each = each.value.network_interfaces
|
||||
//for_each = { for idx, value in each.value.network_interfaces : idx => value }
|
||||
//for_each = { for idx, vnet in data.vsphere_network.network : idx => vnet }
|
||||
content {
|
||||
network_id = data.vsphere_network.network[network_interface.value.id].id
|
||||
use_static_mac = true
|
||||
mac_address = network_interface.value.mac
|
||||
}
|
||||
}
|
||||
|
||||
dynamic "disk" {
|
||||
for_each = each.value.disks
|
||||
content {
|
||||
label = disk.key
|
||||
size = disk.value.size
|
||||
thin_provisioned = disk.value.thin_provisioned
|
||||
unit_number = disk.value.unit_number
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "vsphere_virtual_machine" "ova" {
|
||||
for_each = var.ovfs
|
||||
name = "${each.key}.${each.value.domain}"
|
||||
resource_pool_id = data.vsphere_resource_pool.pool.id
|
||||
datastore_id = data.vsphere_datastore.datastore.id
|
||||
host_system_id = data.vsphere_host.host.id
|
||||
folder = var.cluster.folder
|
||||
|
||||
wait_for_guest_net_timeout = 0
|
||||
wait_for_guest_ip_timeout = 0
|
||||
|
||||
dynamic "network_interface" {
|
||||
for_each = each.value.network_map
|
||||
content {
|
||||
network_id = data.vsphere_network.network[network_interface.value].id
|
||||
}
|
||||
}
|
||||
|
||||
ovf_deploy {
|
||||
allow_unverified_ssl_cert = each.value.allow_unverified_ssl_cert
|
||||
remote_ovf_url = each.value.remote_ovf_url
|
||||
disk_provisioning = each.value.disk_provisioning
|
||||
ip_protocol = each.value.ip_protocol
|
||||
ip_allocation_policy = each.value.ip_allocation_policy
|
||||
ovf_network_map = {
|
||||
"Network 1" = data.vsphere_network.network[each.value.network_map[0]].id
|
||||
}
|
||||
}
|
||||
vapp {
|
||||
properties = each.value.vapp_properties
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
output "shortnames" {
|
||||
value = keys(var.vms)
|
||||
}
|
||||
|
||||
//output "virtual_machines" {
|
||||
// value = vsphere.virtual_machine.vm //template_nic[0].computed_mac)
|
||||
//}
|
|
@ -0,0 +1,55 @@
|
|||
variable "vms" {
|
||||
type = map(object(
|
||||
{
|
||||
domain = string
|
||||
cpu = number
|
||||
ram = number
|
||||
guest_id = string
|
||||
firmware = string
|
||||
disks = map(object({
|
||||
size = string
|
||||
thin_provisioned = bool
|
||||
unit_number = number
|
||||
}))
|
||||
network_interfaces = list(object(
|
||||
{
|
||||
id = string
|
||||
mac = string
|
||||
}
|
||||
))
|
||||
folder = string
|
||||
}
|
||||
))
|
||||
description = "Virtual Machines description"
|
||||
}
|
||||
|
||||
variable "cluster" {
|
||||
type = object({
|
||||
datacenter_name = string
|
||||
datastore_name = string
|
||||
resource_pool_name = string
|
||||
folder = string
|
||||
vnets = map(object({
|
||||
name = string
|
||||
}))
|
||||
}
|
||||
)
|
||||
description = "vSphere cluster definition"
|
||||
}
|
||||
|
||||
variable "ovfs" {
|
||||
type = map(object(
|
||||
{
|
||||
domain = string
|
||||
allow_unverified_ssl_cert = bool
|
||||
remote_ovf_url = string
|
||||
disk_provisioning = string
|
||||
ip_protocol = string
|
||||
ip_allocation_policy = string
|
||||
network_map = list(string)
|
||||
vapp_properties = object({})
|
||||
}
|
||||
))
|
||||
description = "Virtual Machines description"
|
||||
default = {}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
terraform {
|
||||
required_providers {
|
||||
vsphere = {
|
||||
source = "hashicorp/vsphere"
|
||||
version = "~> 2.5.1"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue