diff --git a/create_lab.sh b/create_lab.sh deleted file mode 100755 index 42d181771c11debe6651cc850594b443a7aa9f08..0000000000000000000000000000000000000000 --- a/create_lab.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash - -echo "|------------------------|" -echo "| INITIALISATION DU LABO |" -echo "|------------------------|" - -if [ ! -f ".env" ]; then - echo "Créez un fichier .env de la forme suivante :" - echo "SCW_ACCESS_KEY=" - echo "SCW_SECRET_KEY=" - echo "TF_VAR_PROJECT_ID=" - echo "TF_VAR_INSTANCES_COUNT=2" - exit 1 -fi - -export $(cat .env | xargs) -# Move to Terraform directory -cd ./terraform -# Initialize a Terraform working directory -terraform init -# Generate and show the execution plan -terraform plan -# Build the infrastructure -terraform apply -# Echo Terraform outputs -terraform output -# Move to default directory -cd .. - -echo "|--------------|" -echo "| LABO DÉMARRÉ |" -echo "|--------------|" - -echo "Se connecter sur les IPs, avec le port 80 pour webtop, et 8080 pour code-server." -echo "Le mot de passe des instances est yfB4W23G." diff --git a/delete_lab.sh b/delete_lab.sh deleted file mode 100755 index 47aaecf4d10489acb191b15b1b8aade0372d01bc..0000000000000000000000000000000000000000 --- a/delete_lab.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -export $(cat .env | xargs) -terraform destroy diff --git a/terraform/cloud-init.yml b/terraform/cloud-init.yml index ab41958e953d2b7b9a27c7d07d557aaf6d07d092..edc4ce5db3025cd0d9cde2d7ebe64719c71cb008 100644 --- a/terraform/cloud-init.yml +++ b/terraform/cloud-init.yml @@ -1,18 +1,31 @@ #cloud-config +# System update package_update: true package_upgrade: true +# Install Packages packages: - curl - jq - git runcmd: +# Check env variables access + - "echo $USER_PASSWORD > test.txt" +# Install Rust - "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y" - "source \"$HOME/.cargo/env\"" +# Install Docker + - "curl -fsSL https://get.docker.com -o get-docker.sh | sh" +# Install atrium + - "git clone https://github.com/nicolaspernoud/atrium.git" +# Run Webtop Container + - "docker stop webtop" + - "docker rm webtop" + - "docker run -d --name=webtop --security-opt seccomp=unconfined -e PUID=0 -e PGID=0 -e TZ=Europe/Paris -e SUBFOLDER=/ -e KEYBOARD=fr-fr-azerty -e AUTO_LOGIN=false -p 80:3000 -v /root/webtop_data/:/config -v /var/run/docker.sock:/var/run/docker.sock --shm-size=8gb --cap-add=NET_ADMIN --privileged --restart unless-stopped --sysctl net.ipv6.conf.all.disable_ipv6=0 lscr.io/linuxserver/webtop:ubuntu-xfce" +# Install Code Server - "curl -fsSL https://code-server.dev/install.sh | sh" - "mkdir -p /root/.config/code-server/" - "echo 'bind-addr: 0.0.0.0:8080\nauth: password\npassword: yfB4W23G\ncert: false\n' > /root/.config/code-server/config.yaml" - "systemctl enable --now code-server@$USER" - diff --git a/terraform/main.tf b/terraform/main.tf index 20540c53feb046e0cbc362677f4286c583278902..30429af85c3fe7572a09cd23136be657145f13bc 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -83,6 +83,7 @@ resource "scaleway_instance_server" "user_instance_server" { security_group_id = scaleway_instance_security_group.www.id user_data = { + USER_PASSWORD = var.USER_PASSWORD cloud-init = file("cloud-init.yml") } @@ -90,38 +91,4 @@ resource "scaleway_instance_server" "user_instance_server" { scaleway_account_ssh_key.ssh_key, scaleway_instance_security_group.www ] -} - -#resource "null_resource" "provisioner" { -# count = var.INSTANCES_COUNT -# depends_on = [ -# scaleway_instance_server.user_instance_server -# ] -# -# connection { -# host = element(scaleway_instance_ip.public_ip.*.address, count.index) -# type = "ssh" -# user = "root" -# private_key = var.SCW_SSH_PRIVATE_KEY -# timeout = "2m" -# } -# -# // Install Rust -# provisioner "remote-exec" { -# inline = [ -# "apt-get update -y'", -# "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y'", -# "source \"$HOME/.cargo/env\"", -# ] -# } -# -# // Install Code-server -# provisioner "remote-exec" { -# inline = [ -# "curl -fsSL https://code-server.dev/install.sh | sh", -# "mkdir -p /root/.config/code-server/", -# "echo 'bind-addr: 0.0.0.0:8080\nauth: password\npassword: yfB4W23G\ncert: false\n' > /root/.config/code-server/config.yaml", -# "systemctl enable --now code-server@$USER" -# ] -# } -#} \ No newline at end of file +} \ No newline at end of file diff --git a/terraform/variables-gitlab.tf b/terraform/variables-gitlab.tf index 5648602b9abf3899469de3818f4b354e31a3c51f..5ef03b6966fb393d7e6602cfae7dfbb4443bfd21 100644 --- a/terraform/variables-gitlab.tf +++ b/terraform/variables-gitlab.tf @@ -30,6 +30,12 @@ variable "SCW_SSH_PRIVATE_KEY" { description = "SSH private key from Gitlab agent for remote-exec" } +variable "USER_PASSWORD" { + type = string + sensitive = true + description = "User password for accessing services" +} + variable "INSTANCES_COUNT" { type = number description = "Number of instances to create"