Skip to content
This repository was archived by the owner on Oct 10, 2025. It is now read-only.

Commit 35fedb6

Browse files
committed
feat: [#24] add provision command with cloud-init monitoring
- Add new 'provision' command to create VMs using OpenTofu and libvirt - Implement cloud-init progress monitoring via SSH password authentication - Add SSH key verification after cloud-init completion - Create comprehensive cloud-init configuration for Ubuntu 24.04 LTS - Install Docker, security tools, and system optimizations via cloud-init - Add template system for OpenTofu and cloud-init configurations - Use testing SSH key (testing_rsa) instead of personal SSH keys - Remove custom help command to use App::Cmd's superior built-in help - Add comprehensive test suite for provision command functionality - All values currently hardcoded for single local environment The provision command: 1. Copies templates to build/tofu directory 2. Initializes and applies OpenTofu configuration 3. Waits for VM IP assignment 4. Monitors cloud-init progress using password auth (torrust/torrust123) 5. Verifies SSH key authentication works correctly 6. Provides clear feedback throughout the process
1 parent b0099c3 commit 35fedb6

File tree

13 files changed

+832
-110
lines changed

13 files changed

+832
-110
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ local/
33
.carmel/
44
cpanfile.snapshot
55

6+
# Build artifacts and working directories
7+
build/
8+
69
# Editor temporary files
710
*.swp
811
*.swo

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,66 @@ Run the application:
4949
carmel exec -- ./bin/torrust-deploy help
5050
```
5151

52+
## Commands
53+
54+
### provision
55+
56+
Provision a Torrust Tracker virtual machine using OpenTofu with libvirt provider:
57+
58+
```bash
59+
carmel exec -- ./bin/torrust-deploy provision
60+
```
61+
62+
This command will:
63+
64+
1. Copy OpenTofu configuration templates from `templates/provision/` directory
65+
2. Initialize OpenTofu if needed
66+
3. Create a minimal Ubuntu 22.04 LTS VM with hardcoded configuration
67+
4. Start the VM and make it ready for use
68+
69+
#### Requirements
70+
71+
Before using the provision command, ensure you have:
72+
73+
- **OpenTofu** installed ([Download from opentofu.org](https://opentofu.org/docs/intro/install/))
74+
- **libvirt/KVM** installed and running:
75+
76+
```bash
77+
sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils
78+
sudo systemctl enable libvirtd
79+
sudo systemctl start libvirtd
80+
sudo usermod -aG libvirt $USER
81+
```
82+
83+
- **Default libvirt storage pool** configured:
84+
85+
```bash
86+
virsh pool-list --all
87+
# If 'default' pool doesn't exist, create it:
88+
sudo virsh pool-define-as default dir - - - - "/var/lib/libvirt/images"
89+
sudo virsh pool-build default
90+
sudo virsh pool-start default
91+
sudo virsh pool-autostart default
92+
```
93+
94+
#### VM Configuration
95+
96+
The VM is created with:
97+
98+
- **OS:** Ubuntu 22.04 LTS (Cloud Image)
99+
- **CPU:** 2 vCPUs
100+
- **Memory:** 2GB RAM
101+
- **Disk:** 10GB
102+
- **Network:** NAT with DHCP (192.168.122.0/24)
103+
- **User:** `torrust` (with sudo access)
104+
- **SSH:** Enabled (requires SSH key configuration in cloud-init.yml)
105+
106+
After provisioning, you can find the VM IP with:
107+
108+
```bash
109+
cd build/tofu && tofu output
110+
```
111+
52112
## Testing
53113

54114
Run the test suite:

bin/torrust-deploy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env perl # Shebang line - tells the system to use perl to execute this script
1+
#!/usr/bin/env perl
22

33
# Set up Perl environment with safety features
44
use strict; # Enable strict mode - catches common programming errors like undeclared variables

lib/TorrustDeploy/App.pm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ use v5.20;
99
# becomes a command (e.g., help.pm -> "help" command, packer.pm -> "packer" command)
1010
use App::Cmd::Setup -app;
1111

12+
sub usage_desc { "%c %o" }
13+
14+
sub global_opt_spec {
15+
return (
16+
[ "help|h", "show help" ],
17+
[ "version|v", "show version" ],
18+
);
19+
}
20+
1221
1;
1322

1423
__END__

lib/TorrustDeploy/App/Command/help.pm

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)