Création d'une VM Linux Avec Terraform
-
- Paramétrage de PROXMOX (création d'une clé d'API)
- Installation de TERRAFORM sur une DEBIAN (Créer un container de management)
- Suivre la documentation officielle https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli
- Vérifier l'installation de TERRAFORM:
root@MGT-FRONT-01:~# terraform -v Terraform v1.5.2 on linux_amd64
- Premier déploiement de machine
- Créer un dossier de travail:
mkdir VM_CREATION && cd VM_CREATION - On va créer un fichier provider.tf ce fichier va référencer les module que nous utiliserons pour la création des VM.
# Creation du fichier provider.tf nano provider.tfContenu du fichier:
terraform { required_providers { proxmox = { source = "telmate/proxmox" #version = "2.9.11" } } } provider "proxmox" { # url de Proxmox pm_api_url = "https://192.168.1.179:8006/api2/json" # api token id is in the form of: <username>@pam!<tokenId> pm_api_token_id = "terraform@pve!fbf5f330-09b3-4282-b949-0303a1328ab8" pm_tls_insecure = true pm_parallel = 2 pm_user="root@pam" pm_password="Espoir15" } - On créer le fichier web.tf:
nano web.tfContenu du fichier:
resource "proxmox_vm_qemu" "web-server-1" { count = 1 name = "web-front-01" target_node = "pve-front-01" vmid = "0" clone = "Ubuntu22-Template" full_clone = "true" agent = 1 os_type = "cloud-init" cores = 1 sockets = 1 cpu = "kvm64" oncreate = true memory = 1024 scsihw = "virtio-scsi-pci" bootdisk = "scsi0" disk { slot = 0 size = "8G" type = "scsi" storage = "local-lvm" iothread = 0 } network { model = "virtio" bridge = "vmbr1" } lifecycle { ignore_changes = [ network, ] } ipconfig0 = "ip=172.16.250.3/24,gw=172.16.250.1" #Si vous avez des clés SSH vous pouvez les mettre ici sshkeys = <<EOF ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIeq/iHCth8j1aKG/DMq0rd3bveLgqksAkwBOhYgAFG1 kvega@fr-lap10398 EOF }source du provider terraform
https://registry.terraform.io/providers/Telmate/proxmox/2.6.3/docsPROVIDER-TERRAFORM- Initialisation du dossier:
root@MGT-FRONT-01:~# terraform init Initializing the backend... Initializing provider plugins... - Finding latest version of telmate/proxmox... - Installing telmate/proxmox v2.9.14... - Installed telmate/proxmox v2.9.14 (self-signed, key ID A9EBBE091B35AFCE) Partner and community providers are signed by their developers. If you'd like to know more about provider signing, you can read about it here: https://www.terraform.io/docs/cli/plugins/signing.html Terraform has created a lock file .terraform.lock.hcl to record the provider selections it made above. Include this file in your version control repository so that Terraform can guarantee to make the same selections by default when you run "terraform init" in the future. Terraform has been successfully initialized! You may now begin working with Terraform. Try running "terraform plan" to see any changes that are required for your infrastructure. All Terraform commands should now work. If you ever set or change modules or backend configuration for Terraform, rerun this command to reinitialize your working directory. If you forget, other commands will detect it and remind you to do so if necessary. - Planification du déploiement (Montre ce qui va être déployé):
terraform plan -
On déploie réellement:
terraform applyOn valide les modifications:
Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve. Enter a value: yesLa VM a été créée:
- Initialisation du dossier:
- Créer un dossier de travail:
- Paramétrage de PROXMOX (création d'une clé d'API)



