diff --git a/sysadmin/grid5000/cassandra/terraform/.gitignore b/sysadmin/grid5000/cassandra/terraform/.gitignore new file mode 100644 index 0000000..88329db --- /dev/null +++ b/sysadmin/grid5000/cassandra/terraform/.gitignore @@ -0,0 +1,2 @@ +.terraform +terraform.tfstate diff --git a/sysadmin/grid5000/cassandra/terraform/Readme.md b/sysadmin/grid5000/cassandra/terraform/Readme.md new file mode 100644 index 0000000..16f9368 --- /dev/null +++ b/sysadmin/grid5000/cassandra/terraform/Readme.md @@ -0,0 +1,121 @@ +Grid5000 terraform provisioning +=============================== + +Prerequisite +------------ + +Tools +##### + +terraform >= 13.0 + +Credentials +########### + +* grid5000 credentials +``` +cat < ~/.grid5000.yml +uri: https://api.grid5000.fr +username: username +password: password +EOF +``` +Theses credentials will be used to interact with the grid5000 api to create the jobs + +* Private/public key files (id_rsa) in the `~/.ssh` directory + +The public key will be installed on the nodes + +Run +--- + +* Initialize terraform modules (first time only) +``` +terraform init +``` + +* Test the plan + +It only check the status of the declared resources compared to the grid5000 status. +It's a read only operation, no actions on grid5000 will be perform. + +``` +terraform plan +``` + +* Execute the plan + +``` +terraform apply +``` + +This action creates the job, provisions the nodes according the `main.tf` file content and install the specified linux distribution on it. + +This command will log the reserved node name in output. +For example for a 1 node reservation: + +``` +grid5000_job.cassandra: Creating... +grid5000_job.cassandra: Still creating... [10s elapsed] +grid5000_job.cassandra: Creation complete after 11s [id=1814813] +grid5000_deployment.my_deployment: Creating... +grid5000_deployment.my_deployment: Still creating... [10s elapsed] +grid5000_deployment.my_deployment: Still creating... [20s elapsed] +grid5000_deployment.my_deployment: Still creating... [30s elapsed] +grid5000_deployment.my_deployment: Still creating... [40s elapsed] +grid5000_deployment.my_deployment: Still creating... [50s elapsed] +grid5000_deployment.my_deployment: Still creating... [1m0s elapsed] +grid5000_deployment.my_deployment: Still creating... [1m10s elapsed] +grid5000_deployment.my_deployment: Still creating... [1m20s elapsed] +grid5000_deployment.my_deployment: Still creating... [1m30s elapsed] +grid5000_deployment.my_deployment: Still creating... [1m40s elapsed] +grid5000_deployment.my_deployment: Still creating... [1m50s elapsed] +grid5000_deployment.my_deployment: Still creating... [2m0s elapsed] +grid5000_deployment.my_deployment: Still creating... [2m10s elapsed] +grid5000_deployment.my_deployment: Creation complete after 2m12s [id=D-0bb76036-1512-429f-be99-620afa328b26] + +Apply complete! Resources: 2 added, 0 changed, 0 destroyed. + +Outputs: + +nodes = [ + "chifflet-6.lille.grid5000.fr", +] +``` +It's now possible to connect to the nodes: +``` +$ ssh -A access.grid5000.fr +$ ssh -A root@chifflet-6.lille.grid5000.fr +Linux chifflet-6.lille.grid5000.fr 4.19.0-16-amd64 #1 SMP Debian 4.19.181-1 (2021-03-19) x86_64 +Debian10-x64-base-2021060212 + (Image based on Debian Buster for AMD64/EM64T) + Maintained by support-staff + +Doc: https://www.grid5000.fr/w/Getting_Started#Deploying_nodes_with_Kadeploy + +root@chifflet-6:~# +``` + +Cleanup +------- + +To destroy the resources before the end of the job: + +``` +terraform destroy +``` + +If the job is stopped, simply remove the `terraform.tfstate` file: +``` +rm terraform.tfstate +``` + +## TODO + +[ ] variablization of the script +[ ] Ansible provisionning of the nodes +[ ] disk initialization +[ ] support different cluster topologies (nodes / disks / ...) +[ ] cassandra installation +[ ] swh-storage installation +[ ] ... diff --git a/sysadmin/grid5000/cassandra/terraform/main.tf b/sysadmin/grid5000/cassandra/terraform/main.tf new file mode 100644 index 0000000..1022512 --- /dev/null +++ b/sysadmin/grid5000/cassandra/terraform/main.tf @@ -0,0 +1,23 @@ +provider "grid5000" { + # Uses Restfully credentials + restfully_file = pathexpand("~/.grid5000.yml") +} + +resource "grid5000_job" "cassandra" { + name = "terraform" + site = "lille" + command = "sleep 1h" + resources = "{\"cluster\"='chifflet'}/nodes=2,walltime=0:10:00" + types = ["deploy"] +} + +resource "grid5000_deployment" "my_deployment" { + site = grid5000_job.cassandra.site + environment = "debian10-x64-base" + nodes = grid5000_job.cassandra.assigned_nodes + key = file("~/.ssh/id_rsa.pub") +} + +output "nodes" { + value = grid5000_job.cassandra.assigned_nodes +} diff --git a/sysadmin/grid5000/cassandra/terraform/terraform.tf b/sysadmin/grid5000/cassandra/terraform/terraform.tf new file mode 100644 index 0000000..f5df61d --- /dev/null +++ b/sysadmin/grid5000/cassandra/terraform/terraform.tf @@ -0,0 +1,8 @@ +terraform { + required_providers { + grid5000 = { + source = "pmorillon/grid5000" + version = "0.0.7" + } + } +}