Added support for bridge network interfaces for libvirt.

This commit is contained in:
Curtis Wilson
2021-12-13 20:26:00 -05:00
parent 01a5e56d91
commit 3bb1cb4a95
13 changed files with 282 additions and 72 deletions
+1 -1
View File
@@ -33,7 +33,7 @@ resource "aws_default_security_group" "sg" {
}
tags = {
Name = "${var.name-prefix}-ssh-from-admins--sg"
Name = "${var.name-prefix}-ssh-from-admins-sg"
}
}
+4
View File
@@ -1,3 +1,7 @@
output "ips" {
value = aws_instance.nodes.*.public_ip
}
output "names" {
value = aws_instance.nodes.*.tags.Name
}
+4 -3
View File
@@ -1,9 +1,10 @@
data "template_file" "user-datas" {
template = file("${var.cloud-init-template}")
vars = {
admin-passwd = "${var.root-admin-passwd}"
admin-pub-key = "${var.root-admin-pub-key}"
hostname = "${var.hostname-prefix}-${count.index}"
admin-passwd = "${var.root-admin-passwd}"
admin-pub-key = "${var.root-admin-pub-key}"
hostname = "${var.hostname-prefix}-${count.index}"
install-qemu-agent = var.install-qemu-agent
}
count = var.num
}
@@ -8,6 +8,12 @@ variable "hostname-prefix" {
description = "This prefix wil be applied as a prefix for the hostnames."
}
variable "install-qemu-agent" {
default = false
description = "This flag determines whether or not qemu-agent is installed."
type = bool
}
variable "num" {
description = "The number of user-datas to create with these parameters."
}
+12 -5
View File
@@ -9,13 +9,20 @@ terraform {
}
resource "libvirt_volume" "node-images" {
name = "${var.name-prefix}-${count.index}"
name = "${var.name-prefix}-base"
pool = var.pool-name
source = var.base-image
count = var.num-nodes
format = "qcow2"
}
resource "libvirt_volume" "node-images-resized" {
name = "${var.name-prefix}-${count.index}-resized"
pool = var.pool-name
base_volume_id = libvirt_volume.node-images.id
count = var.num-nodes
size = var.node-disk-size
}
data "template_file" "network-config" {
template = file("${path.module}/network_config.cfg")
}
@@ -37,9 +44,9 @@ resource "libvirt_domain" "nodes" {
cloudinit = element(libvirt_cloudinit_disk.node-inits.*.id, count.index)
network_interface {
network_name = "default"
network_name = var.network-name
hostname = "${var.name-prefix}-${count.index}"
wait_for_lease = true
# wait_for_lease = true
}
# IMPORTANT: this is a known bug on cloud images, since they expect a console
@@ -58,7 +65,7 @@ resource "libvirt_domain" "nodes" {
}
disk {
volume_id = element(libvirt_volume.node-images.*.id, count.index)
volume_id = element(libvirt_volume.node-images-resized.*.id, count.index)
}
graphics {
+5 -3
View File
@@ -1,4 +1,6 @@
output "ips" {
value = libvirt_domain.nodes.*.network_interface.0.addresses.0
}
# This only works on the default network. They will not work using the bridged
# network.
# output "ips" {
# value = libvirt_domain.nodes.*.network_interface.0.addresses.0
# }
@@ -12,6 +12,16 @@ variable "name-prefix" {
description = "This will be a prefix for all resource names, ie. domains will be created suck as \"k8s-node-2\"."
}
variable "network-name" {
default = "default"
description = "The name of a pre-existing virtual-network."
}
variable "node-disk-size" {
default = 4294967296
description = "The size of the disk to be used for libvirt nodes. (in bytes)"
}
variable "node-memory" {
default = "2048"
description = "The amount of memory to be used for all the nodes."