fabrica/terraform/main.tf

90 lines
1.8 KiB
HCL

provider "opennebula" {
endpoint = var.one_endpoint
username = var.one_user
password = var.one_pass
}
provider "dns" {
update {
server = var.dns_server
port = "53530"
key_name = var.dns_key_name
key_algorithm = var.dns_key_algo
key_secret = var.dns_key_secret
retries = 10
timeout = 300
}
}
// Production
/*
* Virtual networks
*/
resource "opennebula_virtual_network" "vnet"{
for_each = var.virtual_networks
name = each.key
vlan_id = each.value.vlan_id
permissions = "660"
bridge = var.one_vswitch
type = "ovswitch"
mtu = 1500
ar {
ar_type = each.value.adress_range.ar_type
size = each.value.adress_range.size
ip4 = each.value.adress_range.ip4
}
dns = each.value.dns
gateway = each.value.gateway
clusters = each.value.clusters
}
/*
* VIRTUAL MACHINES
*/
// Production
module "vms" {
source = "./modules/virtualMachine"
one_user = var.one_user
one_prod_ds = var.one_prod_ds
for_each = var.virtual_machines
vm_shortname = each.key
vm_fqdn = each.value.fqdn
vm_domain = var.dns_domain
dns_a_record = each.value.create_dns_a_record
cpu = each.value.cpu
vcpu = each.value.vcpu
ram = each.value.memory
vnets = opennebula_virtual_network.vnet
network_interfaces = each.value.network_interfaces
tag_labels = each.value.labels
system_image_name = each.value.disks.system.name
data_image_name = ""
system_image_source = each.value.disks.system.source
data_image_source = ""
depends = [
opennebula_virtual_network.vnet[each.value.depends[0]].id
]
}
/* Additionnal DNS Entry
module "ber_asso_fr" {
source = "./modules/cadolesDNS"
dns_domain = "cadoles.com."
dns_a_records = var.dns_a_records
dns_cname_records = var.dns_cname_records
depends = [ module.dns.virtual_machine_shortname ]
}
*/