From 4293df73e636a3bb9097d4cbe80ae8c194862f6b Mon Sep 17 00:00:00 2001 From: jerome Date: Mon, 18 Aug 2025 11:22:14 +0200 Subject: commit initial --- tofu/ansible/hosts | 1 + tofu/ansible/local_script | 8 ++++++++ tofu/ansible/main.tf | 37 +++++++++++++++++++++++++++++++++++++ tofu/basic/main.tf | 25 +++++++++++++++++++++++++ tofu/lots/main.tf | 30 ++++++++++++++++++++++++++++++ tofu/lots/terraform.tfvars | 3 +++ tofu/lots/variables.tf | 17 +++++++++++++++++ 7 files changed, 121 insertions(+) create mode 100644 tofu/ansible/hosts create mode 100755 tofu/ansible/local_script create mode 100644 tofu/ansible/main.tf create mode 100644 tofu/basic/main.tf create mode 100644 tofu/lots/main.tf create mode 100644 tofu/lots/terraform.tfvars create mode 100644 tofu/lots/variables.tf (limited to 'tofu') diff --git a/tofu/ansible/hosts b/tofu/ansible/hosts new file mode 100644 index 0000000..e5bdaa1 --- /dev/null +++ b/tofu/ansible/hosts @@ -0,0 +1 @@ +webserver1 ansible_host=192.168.122.213 ansible_user=ansible ansible_become=true diff --git a/tofu/ansible/local_script b/tofu/ansible/local_script new file mode 100755 index 0000000..14b6121 --- /dev/null +++ b/tofu/ansible/local_script @@ -0,0 +1,8 @@ +#!/bin/bash +ssh-keygen -f ~/.ssh/known_hosts -R $1 +# on attend que cloud-init ait fini d'installer le serveur SSH +while ! ssh-keyscan -H $1 >> ~/.ssh/known_hosts; do + sleep 1 +done +ansible -u ansible --become -i "$1," -m ping all +echo $2 ansible_host=$1 ansible_user=ansible ansible_become=true >> hosts diff --git a/tofu/ansible/main.tf b/tofu/ansible/main.tf new file mode 100644 index 0000000..0bbc448 --- /dev/null +++ b/tofu/ansible/main.tf @@ -0,0 +1,37 @@ +terraform { + required_providers { + incus = { + source = "lxc/incus" + version = "0.3.1" + } + } +} + +provider "incus" { + # Configuration options +} + +resource "incus_instance" "debian" { + name = "webserver1" + project = "lab" + image = "images:debian/12/cloud" + wait_for { + type = "ipv4" + } + provisioner "local-exec" { + command = "./local_script ${self.ipv4_address} ${self.name}" + } +} + +resource "incus_instance" "rocky" { + name = "webserver2" + project = "lab" + image = "images:rockylinux/9/cloud" + wait_for { + type = "ipv4" + } + provisioner "local-exec" { + command = "./local_script ${self.ipv4_address} ${self.name}" + } +} + diff --git a/tofu/basic/main.tf b/tofu/basic/main.tf new file mode 100644 index 0000000..7da8687 --- /dev/null +++ b/tofu/basic/main.tf @@ -0,0 +1,25 @@ +terraform { + required_providers { + incus = { + source = "lxc/incus" + version = "0.3.1" + } + } +} + +provider "incus" { + # Configuration options +} + +resource "incus_instance" "test" { + name = "test" + image = "images:ubuntu/22.04" + project = "Lab" + wait_for { + type = "ipv4" + } +} + +output "instance_ip" { + value = incus_instance.test.ipv4_address +} diff --git a/tofu/lots/main.tf b/tofu/lots/main.tf new file mode 100644 index 0000000..7917a03 --- /dev/null +++ b/tofu/lots/main.tf @@ -0,0 +1,30 @@ +terraform { + required_providers { + incus = { + source = "lxc/incus" + version = "0.3.1" + } + } +} + +provider "incus" { + # Configuration options +} + +resource "incus_instance" "instance" { + name = "${var.nom}${count.index + 1}" + project = "Lab" + image = var.image + count = var.nb + wait_for { + type = "ipv4" + } +} + +output "instance_ip" { + value = { + for instance in incus_instance.instance : + instance.name => instance.ipv4_address + } +} + diff --git a/tofu/lots/terraform.tfvars b/tofu/lots/terraform.tfvars new file mode 100644 index 0000000..3f7d342 --- /dev/null +++ b/tofu/lots/terraform.tfvars @@ -0,0 +1,3 @@ +nb = 3 +nom = "rocky" +image = "images:rockylinux/9/cloud" diff --git a/tofu/lots/variables.tf b/tofu/lots/variables.tf new file mode 100644 index 0000000..f983e48 --- /dev/null +++ b/tofu/lots/variables.tf @@ -0,0 +1,17 @@ +variable "nom" { + description = "nom de la machine" + type = string + default = "debian" +} + +variable "image" { + description = "image source" + type = string + default = "images:debian/12/cloud" +} + +variable "nb" { + description = "nombre de machines" + type = number + default = 2 +} -- cgit v1.2.3