summaryrefslogtreecommitdiff
path: root/tofu
diff options
context:
space:
mode:
Diffstat (limited to 'tofu')
-rw-r--r--tofu/ansible/hosts1
-rwxr-xr-xtofu/ansible/local_script8
-rw-r--r--tofu/ansible/main.tf37
-rw-r--r--tofu/basic/main.tf25
-rw-r--r--tofu/lots/main.tf30
-rw-r--r--tofu/lots/terraform.tfvars3
-rw-r--r--tofu/lots/variables.tf17
7 files changed, 121 insertions, 0 deletions
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
+}