Compare commits
No commits in common. "65b95c56a12d7a155c29fcb9f39a5adc7dcf8422" and "d12748cb966086291f1b781e543afbc2e9c87580" have entirely different histories.
65b95c56a1
...
d12748cb96
|
@ -1,28 +0,0 @@
|
|||
// Dependencies management
|
||||
resource "null_resource" "depends_on" {
|
||||
triggers = {
|
||||
depends_on = join("", var.depends)
|
||||
}
|
||||
}
|
||||
|
||||
resource "dns_a_record_set" "a_records" {
|
||||
for_each = var.dns_a_records
|
||||
|
||||
zone = var.dns_domain
|
||||
name = each.key
|
||||
ttl = 300
|
||||
|
||||
addresses = each.value
|
||||
depends_on = [ null_resource.depends_on ]
|
||||
}
|
||||
|
||||
resource "dns_cname_record" "cname_records" {
|
||||
for_each = var.dns_cname_records
|
||||
|
||||
zone = var.dns_domain
|
||||
name = each.key
|
||||
cname = each.value
|
||||
ttl = 300
|
||||
|
||||
depends_on = [ null_resource.depends_on ]
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
variable "dns_domain" {
|
||||
description = "DNS Domain name (FQDN)"
|
||||
type = string
|
||||
default = "cadoles.com."
|
||||
}
|
||||
|
||||
variable "dns_a_records" {
|
||||
description = "List of dns A records to create"
|
||||
type = map
|
||||
default = {}
|
||||
}
|
||||
|
||||
variable "dns_cname_records" {
|
||||
description = "List of CNAME entires"
|
||||
type = map
|
||||
default = {}
|
||||
}
|
||||
|
||||
variable "depends" {
|
||||
description = "List of output_variables for dependences management"
|
||||
type = list
|
||||
default = []
|
||||
}
|
|
@ -1,109 +0,0 @@
|
|||
// Dependencies management
|
||||
resource "null_resource" "depends_on" {
|
||||
triggers = {
|
||||
depends_on = join("", var.depends)
|
||||
}
|
||||
}
|
||||
|
||||
// OpenNebula disk image !
|
||||
resource "opennebula_image" "system" {
|
||||
name = var.system_image_name
|
||||
description = "System disk image"
|
||||
datastore_id = var.one_prod_ds
|
||||
persistent = false
|
||||
//lock = "MANAGE"
|
||||
path = var.system_image_source
|
||||
dev_prefix = "vd"
|
||||
driver = "qcow2"
|
||||
format = "qcow2"
|
||||
permissions = var.imagemode
|
||||
group = var.group
|
||||
}
|
||||
|
||||
resource "opennebula_image" "data" {
|
||||
name = var.data_image_name
|
||||
description = "Data disk image"
|
||||
datastore_id = var.one_prod_ds
|
||||
persistent = true
|
||||
//lock = "MANAGE"
|
||||
path = var.data_image_source
|
||||
dev_prefix = "vd"
|
||||
driver = "qcow2"
|
||||
format = "qcow2"
|
||||
permissions = "660"
|
||||
group = "production"
|
||||
}
|
||||
|
||||
// OpenNebula (VM) Template definition
|
||||
resource "opennebula_template" "vm_template" {
|
||||
name = var.vm_shortname
|
||||
cpu = var.cpu
|
||||
vcpu = var.vcpu
|
||||
memory = var.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.id
|
||||
}
|
||||
disk {
|
||||
image_id = opennebula_image.data.id
|
||||
}
|
||||
|
||||
//labels = var.tag_labels
|
||||
|
||||
dynamic "nic" {
|
||||
for_each = var.network_interfaces
|
||||
|
||||
content {
|
||||
network_id = nic.value.network_id
|
||||
model = "virtio"
|
||||
ip = nic.value.ip
|
||||
}
|
||||
}
|
||||
permissions = "600"
|
||||
group = var.group
|
||||
depends_on = [ opennebula_image.system,
|
||||
opennebula_image.data ]
|
||||
}
|
||||
|
||||
// OpenNebula Virtual Machine
|
||||
resource "opennebula_virtual_machine" "vm" {
|
||||
name = var.vm_fqdn
|
||||
group = var.group
|
||||
timeout = 10
|
||||
template_id = opennebula_template.vm_template.id
|
||||
depends_on = [ opennebula_template.vm_template,
|
||||
null_resource.depends_on ]
|
||||
}
|
||||
|
||||
resource "dns_a_record_set" "vm_dns_a_record" {
|
||||
count = var.dns_a_record == "yes" ? 1 : 0
|
||||
|
||||
zone = var.vm_domain
|
||||
name = var.vm_shortname
|
||||
ttl = 300
|
||||
|
||||
addresses = [ var.network_interfaces[0].ip ]
|
||||
depends_on = [ opennebula_virtual_machine.vm ]
|
||||
}
|
||||
|
||||
resource "dns_cname_record" "vm_dns_cname_record" {
|
||||
for_each = var.dns_cname_record
|
||||
|
||||
zone = var.vm_domain
|
||||
name = each.value
|
||||
cname = "${var.vm_fqdn}."
|
||||
ttl = 300
|
||||
|
||||
depends_on = [ opennebula_virtual_machine.vm ]
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
output "virtual_machine_shortname" {
|
||||
value = opennebula_virtual_machine.vm.name
|
||||
}
|
||||
|
||||
output "virtual_machine_nic0_mac" {
|
||||
value = opennebula_virtual_machine.vm.nic[0].mac
|
||||
}
|
||||
|
||||
output "network_interfaces" {
|
||||
value = var.network_interfaces
|
||||
}
|
|
@ -1,104 +0,0 @@
|
|||
variable "one_user" {
|
||||
description = "OpenNebula user"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "one_prod_ds" {
|
||||
description = "ID du Datastore de production"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "vm_fqdn" {
|
||||
description = "Virtual Machine FQDN Name"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "vm_shortname" {
|
||||
description = "Virtual machine short name"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "vm_domain" {
|
||||
description = "Full qualified dns domain name"
|
||||
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
|
||||
}
|
||||
|
||||
variable "data_image_source" {
|
||||
description = "Virtual Machine data disk image source"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "tag_labels" {
|
||||
description = "Labels"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "network_interfaces" {
|
||||
description = "Network interfaces"
|
||||
type = list
|
||||
}
|
||||
|
||||
variable "cpu" {
|
||||
description = "VM CPU"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "vcpu" {
|
||||
description = "VM vCPU"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "ram" {
|
||||
description = "VM RAM"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "depends" {
|
||||
description = "List of output_variables for dependences management"
|
||||
type = list
|
||||
default = []
|
||||
}
|
||||
|
||||
variable "dns_a_record" {
|
||||
description = "Create a dns A record (yes/no)"
|
||||
type = string
|
||||
default = "no"
|
||||
}
|
||||
|
||||
variable "dns_cname_record" {
|
||||
description = "List of CNAME for A entry"
|
||||
type = map(string)
|
||||
default = {}
|
||||
}
|
||||
|
||||
variable "group" {
|
||||
description = "Group (owner group)"
|
||||
type = string
|
||||
default = "production"
|
||||
}
|
||||
|
||||
variable "graphics" {
|
||||
description = "Graphics declaration"
|
||||
type = map(string)
|
||||
default = {
|
||||
keymap = "fr"
|
||||
listen = "0.0.0.0"
|
||||
type = "VNC"
|
||||
}
|
||||
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
terraform {
|
||||
required_providers {
|
||||
dns = {
|
||||
source = "hashicorp/dns"
|
||||
}
|
||||
null = {
|
||||
source = "hashicorp/null"
|
||||
}
|
||||
opennebula = {
|
||||
source = "terraform-providers/opennebula"
|
||||
}
|
||||
}
|
||||
required_version = ">= 0.13"
|
||||
}
|
Loading…
Reference in New Issue