This project provisions a RHEL/Fedora-based virtual machine using Terraform, Libvirt/KVM, and cloud-init. SSH keys, hostname, password injection, and HTTP setup are handled via cloud-init.
.
├── environments
│ └── dev
│ ├── id_rsa
│ ├── id_rsa.pub
│ ├── main.tf
│ ├── providers.tf
│ ├── terraform.tfvars
│ └── variables.tf
└── modules
└── vm
├── cloud-init.yaml
├── main.tf
├── outputs.tf
├── providers.tf
└── variables.tfcd environments/dev/
terraform initSample output:
Initializing the backend... Initializing modules... - rhel_vm in ../../modules/vm Installing providers... Terraform has been successfully initialized!
sudo virsh vol-list defaultOutput:
Name Path --------------------------------------------------------------- dev-vm-cloudinit.iso /var/lib/libvirt/images/dev-vm-cloudinit.iso dev-vm.qcow2 /var/lib/libvirt/images/dev-vm.qcow2
sudo virsh domifaddr dev-vmSample output:
Name MAC address Protocol Address ---------------------------------------------------------- vnet30 52:54:00:ae:07:39 ipv4 192.168.122.226/24
[fedora@dev-vm ~]$ hostname -f
dev-vm.localdomain
[fedora@dev-vm ~]$ curl localhost
<html><body><h1>IP Address: dev-vm.localdomain</h1></body></html>-
Creates a KVM virtual machine using libvirt provider
-
Injects SSH key and sets password via cloud-init
-
Installs Apache HTTP server and serves a simple HTML page with hostname
-
Sets custom hostname (e.g.,
dev-vm.localdomain)
-
Ensure the
id_rsa.pubused is valid and readable -
The password is set using a SHA-512 hash via
openssl passwd -6 -
cloud-init.yamlis templated via Terraform’stemplate_file
.terraform/
*.tfstate
*.tfstate.*
*.tfvars
*.tfplan
*.lock.hcl
*.pem
*.key
id_rsa*
.password_hash-
dmacvicar/libvirt(v0.7.1) -
hashicorp/random -
hashicorp/null -
hashicorp/template -
hashicorp/local
-
Terraform >= 1.3
-
KVM / libvirt installed
-
SSH key pair (
id_rsa+id_rsa.pub) -
A cloud-init compatible image (e.g., Fedora Cloud Base)
