Skip to content

Commit

Permalink
Add DNS for student machines, fix solutions_patch
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkcjelli committed Jul 15, 2022
1 parent b29e963 commit 8aba89c
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 13 deletions.
9 changes: 5 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module "student_workspace" {
machine_type = var.machine_type
course_type = var.course_type
trainer = var.trainer
dns_domain = var.dns_domain
sec_groups = [openstack_networking_secgroup_v2.sec.name]
solutions_url = var.solutions_url
solutions_patch = fileexists("${path.module}/solutions.patch") ? filebase64("${path.module}/solutions.patch") : ""
Expand All @@ -44,10 +45,10 @@ module "wetty_server" {

resource "null_resource" "cluster" {
triggers = {
ips = "${module.student_workspace.ips_checksum}"
keys = "${module.student_workspace.keys_checksum}"
passwords = join(",",flatten(module.wetty_server.*.student_passwords_hash))
}
ips = "${module.student_workspace.ips_checksum}"
keys = "${module.student_workspace.keys_checksum}"
passwords = join(",", flatten(module.wetty_server.*.student_passwords_hash))
}

provisioner "local-exec" {
command = "./scripts/create_package.sh"
Expand Down
6 changes: 5 additions & 1 deletion modules/student_workspace/data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ data "openstack_networking_network_v2" "public" {
}

data "openstack_images_image_v2" "ubuntu" {
name = "ubuntu-20.04-x86_64"
name = "ubuntu-20.04-x86_64"
most_recent = true
visibility = "public"
}

data "openstack_dns_zone_v2" "terraform" {
name = var.dns_domain
}
17 changes: 14 additions & 3 deletions modules/student_workspace/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ resource "openstack_compute_instance_v2" "instance" {
user_data = templatefile(
"${path.module}/cloudinit.yaml",
{
DEFAULT_USER = "student"
SSH_PUB_KEY = trimspace(tls_private_key.ssh_key[split("-", each.value)[0]].public_key_openssh)
SOLUTIONS_URL = var.solutions_url
DEFAULT_USER = "student"
SSH_PUB_KEY = trimspace(tls_private_key.ssh_key[split("-", each.value)[0]].public_key_openssh)
SOLUTIONS_URL = var.solutions_url
SOLUTIONS_PATCH = var.solutions_patch
}
)
Expand Down Expand Up @@ -88,3 +88,14 @@ resource "local_file" "public_ips" {
content = format("%s\n", join("\n", [for i in values(openstack_networking_floatingip_v2.instance).* : format("%s: %s", i.description, i.address) if contains(i.tags, each.value)]))
filename = "${path.cwd}/ips/${each.value}.txt"
}

resource "openstack_dns_recordset_v2" "instance" {
for_each = openstack_compute_instance_v2.instance
zone_id = data.openstack_dns_zone_v2.terraform.id
# name must be <= 64 chars, otherwise certbot will fail
name = "${each.value.name}.${data.openstack_dns_zone_v2.terraform.name}"
ttl = 60
type = "A"
records = [openstack_networking_floatingip_v2.instance[each.value.name].address]
description = "DNS entry for ${var.course_type} by ${var.trainer}"
}
4 changes: 2 additions & 2 deletions modules/student_workspace/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ output "keys_checksum" {

output "instance_info" {
value = {
for name, instance in openstack_compute_instance_v2.instance:
for name, instance in openstack_compute_instance_v2.instance :
name => ({
"ip" = instance.access_ip_v4,
"ip" = instance.access_ip_v4,
"student" = split("-", name)[0],
"ssh_key" = tls_private_key.ssh_key[split("-", name)[0]].private_key_pem
})
Expand Down
9 changes: 7 additions & 2 deletions modules/student_workspace/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@ variable "sec_groups" {
}

variable "solutions_url" {
type = string
type = string
default = ""
}

variable "solutions_patch" {
type = string
type = string
default = ""
}

variable "dns_domain" {
type = string
default = ""
}
2 changes: 1 addition & 1 deletion modules/wetty_server/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ output "wetty_server_address" {
}

output "student_passwords_hash" {
value = [ for entry in random_password.student_password: sha256(entry.result) ]
value = [for entry in random_password.student_password : sha256(entry.result)]
}
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,10 @@ variable "solutions_url" {
description = "URL to download and unpack solutions from LF"
type = string
default = ""
}

variable "solutions_patch" {
description = "URL to download and unpack solutions from LF"
type = string
default = ""
}

0 comments on commit 8aba89c

Please sign in to comment.