Установка KVM + Terraform для Ubuntu 20.04

# проверяем права
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
   echo "This script must be run as root" 
   exit 1
fi
# проверяем обновления
apt update -y
#проверка VMX
vmx=$(cat /proc/cpuinfo |grep vmx| wc -l)
if [ "$vmx" != "0" ]
then
    echo 'Start installing'
else
    echo 'You system not supported VMX';
    exit 0
fi
# ставим пакеты KVM
apt install qemu qemu-kvm libvirt-daemon libvirt-clients bridge-utils virt-manager libvirt-dev -y

# ставим пакеты terraform
apt install wget unzip curl git gnupg2 software-properties-common -y
curl -fsSL https://apt.releases.hashicorp.com/gpg | apt-key add -
apt-add-repository "deb [arch=$(dpkg --print-architecture)] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
apt install terraform -y

# ставим плагин terraform для провайдера libvirt
wget https://github.com/dmacvicar/terraform-provider-libvirt/releases/download/v0.6.3/terraform-provider-libvirt-0.6.3+git.1604843676.67f4f2aa.Ubuntu_20.04.amd64.tar.gz
tar xf terraform-provider-libvirt-0.6.3+git.1604843676.67f4f2aa.Ubuntu_20.04.amd64.tar.gz
install -d ~/.local/share/terraform/plugins/registry.terraform.io/dmacvicar/libvirt/0.6.3/linux_amd64
install terraform-provider-libvirt ~/.local/share/terraform/plugins/registry.terraform.io/dmacvicar/libvirt/0.6.3/linux_amd64/
rm terraform-provider-libvirt terraform-provider-libvirt-*.amd64.tar.gz
# добавляем фаил провайдера libvirt.tf
mkdir -p ~/terraform/project && cd $_
cat <<EOF > libvirt.tf
terraform {
  required_providers {
    # see https://registry.terraform.io/providers/hashicorp/random
    random = {
      source = "hashicorp/random"
      version = "3.1.0"
    }
    # see https://registry.terraform.io/providers/hashicorp/template
    template = {
      source = "hashicorp/template"
      version = "2.2.0"
    }
    # see https://github.com/dmacvicar/terraform-provider-libvirt
    libvirt = {
      source = "dmacvicar/libvirt"
      version = "0.6.3"
    }
  }
}

provider "libvirt" {
  uri = "qemu:///system"
}

# определяем переменные для домена  
resource "libvirt_domain" "test" {
  name   = "test"
  memory = "1024"
  vcpu   = 1

  network_interface {
    network_name = "default"
  }

  console {
    type = "pty"
    target_type = "serial"
    target_port = "0"
  }

  graphics {
    type = "spice"
    listen_type = "address"
    autoport = true
  }
}
EOF
# установка провайдера
terraform init
# применение провайдера
terraform apply -auto-approve