User Tools

Site Tools


terraform_libvirt

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

terraform_libvirt [2025/07/26 17:09] – - Imported by DokuWiki Advanced Plugin wikiadmterraform_libvirt [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1
Line 1: Line 1:
-====== Terraform KVM ====== 
-===== Install Terraform ===== 
-<file bash> 
-$ wget https://releases.hashicorp.com/terraform/1.3.2/terraform_1.3.2_linux_amd64.zip 
-$ sudo unzip terraform_1.3.2_linux_amd64.zip -d /usr/local/bin/ 
-</file> 
  
-===== Install provider ===== 
-<file bash> 
-$ mkdir ~/.terraform.d/plugins && cd ~/.terraform.d/plugins 
-$ wget https://github.com/dmacvicar/terraform-provider-libvirt/releases/download/v0.6.14/terraform-provider-libvirt_0.6.14_linux_amd64.zip 
-$ unzip terraform-provider-libvirt_0.6.14_linux_amd64.zip 
-$ rm terraform-provider-libvirt_0.6.14_linux_amd64.zip 
-</file> 
- 
-<file bash> 
-$ mkdir ~/monprojet && cd ~/monprojet 
-$ terraform init 
-</file> 
- 
-<file bash> 
-$ terraform init 
-</file> 
- 
-<file bash> 
- 
-</file> 
- 
-Exemplos 
-<file tf main.tf> 
-$ cat main.tf 
-terraform { 
-  required_providers { 
-    libvirt = { 
-      source  = "dmacvicar/libvirt" 
-    } 
-  } 
-} 
- 
-provider "libvirt" { 
-  uri = "qemu:///system" 
-} 
- 
-resource "libvirt_volume" "os_image_ubuntu" { 
-  name   = "os_image_ubuntu" 
-  pool   = "default" 
-  source = "./bionic-server-cloudimg-amd64.img" 
-  format = "qcow2" 
-} 
- 
-resource "libvirt_volume" "disk_ubuntu_resized" { 
-  name           = "disk" 
-  base_volume_id = libvirt_volume.os_image_ubuntu.id 
-  pool           = "default" 
-  size           = 34359738368 # 1073741824*32 ou 1024*1024*1024*32 
-} 
- 
-data "template_file" "user_data" { 
-  template = file("${path.module}/cloud_init.cfg") 
-} 
- 
-# Use CloudInit to add our ssh-key to the instance 
-resource "libvirt_cloudinit_disk" "cloudinit_ubuntu_resized" { 
-  name = "cloudinit_ubuntu_resized.iso" 
-  user_data = data.template_file.user_data.rendered 
-  pool = "default" 
-} 
- 
-resource "libvirt_domain" "ubuntu-terraform" { 
-  name = "ubuntu-terraform" 
-  memory = "2048" 
-  vcpu = 2 
- 
-  cpu { 
-    mode = "host-passthrough" 
-  } 
- 
-  cloudinit = libvirt_cloudinit_disk.cloudinit_ubuntu_resized.id 
- 
-  network_interface { 
-    network_name = "default" 
-    wait_for_lease = true 
-  } 
- 
-  console { 
-    type = "pty" 
-    target_port = "0" 
-    target_type = "serial" 
-  } 
- 
-  console { 
-    type = "pty" 
-    target_type = "virtio" 
-    target_port = "1" 
-  } 
- 
-  disk { 
-    volume_id = libvirt_volume.disk_ubuntu_resized.id 
-  } 
- 
-  graphics { 
-    type = "spice" 
-    listen_type = "address" 
-    autoport = true 
-  } 
-} 
- 
-output "ip" { 
-  value = libvirt_domain.ubuntu-terraform.network_interface[0].addresses[0] 
-} 
-</file> 
- 
-===== Cloud init ===== 
-<file bash> 
-$ mkpasswd --method=SHA-512 
-Password: 
-$6$R4tXC5apTx$f4WVAylB/SZ/0ppE7Zp4lurvzAhcm.BaU3xJKaoESu7cv13sR7RYVkjVQwxtvA9/vUggWu/a9N0L9EP1lg/Ez1 
-</file> 
- 
-<file cfg cloud_init.cfg> 
-$ cat cloud_init.cfg 
-#cloud-config 
-users: 
-  - name: suporte 
-    gecos: "Suporte JuntoTelecom" 
-    sudo: ALL=(ALL) NOPASSWD:ALL 
-    home: /home/suporte 
-    shell: /bin/bash 
-    lock_passwd: false 
-    ssh-authorized-keys: 
-      - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDNYC9NDiLb8IZK/v3PeMsgT40o4QLpGzKaz36C4S8JAt/HmzaDDyR6PiGNkHOiMWKtowwIwpdhlV7zpjxBOf8AAq4OhfYfkidKnvGo5M6DRjcxkhPjgsfICAApks4JTa+ATLXaZhEJ2DV8olrD6gxCUYwqTMtLNdgprg3i9wllOWGzM9ygGodXo4JpZI4YvgpbCgmNP+eYwpJzxcdMU6SRTrtdMN0fcmxUDSHp/EhYUWWREF6WCjIP7AUGIP9MILx3M4emfR5FOOJIBeSJRmu1I/xjnSO8f5oFQd514v06Uw6k5UrIhbCkWsHbO4nZLQb3Gx3asxyrYCgeI9tusSiB suporte@mba-vm-03 
-ssh_pwauth: true 
-chpasswd: 
-  list: | 
-     suporte: $6$R4tXC5apTx$f4WVAylB/SZ/0ppE7Zp4lurvzAhcm.BaU3xJKaoESu7cv13sR7RYVkjVQwxtvA9/vUggWu/a9N0L9EP1lg/Ez1 
-  expire: False 
-</file> 
- 
- 
-===== Multiple virtual machine ===== 
-<file bash main.tf> 
-$ cat main.tf 
-terraform { 
-  required_providers { 
-    libvirt = { 
-      source = "dmacvicar/libvirt" 
-    } 
-  } 
-} 
- 
-provider "libvirt" { 
-  uri = "qemu:///system" 
-  #alias = "server2" 
-  #uri   = "qemu+ssh://root@192.168.100.10/system" 
-} 
-</file> 
- 
-<file bash providers.tf> 
-$ cat providers.tf 
-resource "libvirt_volume" "os_image_ubuntu" { 
-  name = "os_image_ubuntu" 
-  pool = "default" 
-  #source = "https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img" 
-  source = "./bionic-server-cloudimg-amd64.img" 
-  format = "qcow2" 
-} 
- 
-resource "libvirt_volume" "volume" { 
-  name           = "volume-${count.index}" 
-  base_volume_id = libvirt_volume.os_image_ubuntu.id 
-  pool           = "default" 
-  size           = 34359738368 
-  count          = 2 
-} 
- 
-data "template_file" "user_data" { 
-  template = file("${path.module}/cloud_init.cfg") 
-} 
- 
-resource "libvirt_cloudinit_disk" "cloudinit_ubuntu_resized" { 
-  name      = "cloudinit_ubuntu_resized.iso" 
-  user_data = data.template_file.user_data.rendered 
-  pool      = "default" 
-} 
- 
-resource "libvirt_domain" "ubuntu" { 
-  name   = "ubuntu-${count.index}" 
-  memory = "2048" 
-  vcpu   = 2 
- 
-  cpu { 
-    mode = "host-passthrough" 
-  } 
- 
-  cloudinit = libvirt_cloudinit_disk.cloudinit_ubuntu_resized.id 
- 
-  network_interface { 
-    network_name   = "default" 
-    wait_for_lease = true 
-  } 
- 
-  count = 2 
- 
-  console { 
-    type        = "pty" 
-    target_port = "0" 
-    target_type = "serial" 
-  } 
- 
-  console { 
-    type        = "pty" 
-    target_type = "virtio" 
-    target_port = "1" 
-  } 
- 
-  disk { 
-    volume_id = element(libvirt_volume.volume.*.id, count.index) 
-  } 
- 
-  graphics { 
-    type        = "spice" 
-    listen_type = "address" 
-    autoport    = true 
-  } 
-} 
- 
-output "ip" { 
-  value = libvirt_domain.ubuntu.*.network_interface.0.addresses 
-} 
-</file> 
- 
-<file bash cloud_init.cfg> 
-$ cat cloud_init.cfg 
-#cloud-config 
-users: 
-  - name: suporte 
-    gecos: "Suporte JuntoTelecom" 
-    sudo: ALL=(ALL) NOPASSWD:ALL 
-    home: /home/suporte 
-    shell: /bin/bash 
-    lock_passwd: false 
-    ssh-authorized-keys: 
-      - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDNYC9NDiLb8IZK/v3PeMsgT40o4QLpGzKaz36C4S8JAt/HmzaDDyR6PiGNkHOiMWKtowwIwpdhlV7zpjxBOf8AAq4OhfYfkidKnvGo5M6DRjcxkhPjgsfICAApks4JTa+ATLXaZhEJ2DV8olrD6gxCUYwqTMtLNdgprg3i9wllOWGzM9ygGodXo4JpZI4YvgpbCgmNP+eYwpJzxcdMU6SRTrtdMN0fcmxUDSHp/EhYUWWREF6WCjIP7AUGIP9MILx3M4emfR5FOOJIBeSJRmu1I/xjnSO8f5oFQd514v06Uw6k5UrIhbCkWsHbO4nZLQb3Gx3asxyrYCgeI9tusSiB suporte@mba-vm-03 
-ssh_pwauth: true 
-chpasswd: 
-  list: | 
-     suporte: $6$R4tXC5apTx$f4WVAylB/SZ/0ppE7Zp4lurvzAhcm.BaU3xJKaoESu7cv13sR7RYVkjVQwxtvA9/vUggWu/a9N0L9EP1lg/Ez1 
-  expire: False 
-</file> 
-===== Referências ===== 
- 
-  - [[https://cloudinit.readthedocs.io/en/latest/topics/examples.html|Cloud config examples]] 
-  - [[https://registry.terraform.io/providers/dmacvicar/libvirt/latest/docs|Libvirt Provider]] 
-  - [[https://computingforgeeks.com/how-to-provision-vms-on-kvm-with-terraform/|How To Provision VMs on KVM with Terraform]] 
-  - [[https://cloud-images.ubuntu.com/|Ubuntu Cloud Images]] 
-  - [[http://cloud.debian.org/images/cloud/|Debian Official Cloud Images]] 
-  - [[https://cloud.centos.org/centos/|CentOS Cloud images]] 
-  - [[https://convertlive.com/pt/u/converter/gigabytes/em/bytes|Gigabytes em Bytes]] 
-  - [[https://github.com/dmacvicar/terraform-provider-libvirt/releases|Terraform provider for libvirt]] 
terraform_libvirt.1753560544.txt.gz · Last modified: by wikiadm