Skip to content

Commit a2e0554

Browse files
committed
docs: [#10] add troubleshooting for VM IP detection issue
- Document the 'No IP assigned yet' issue in Terraform outputs - Explain root cause: stale Terraform state vs actual VM DHCP lease - Add comprehensive troubleshooting steps with solutions - Include prevention tips and alternative methods - Add new 'make refresh-state' command for easy state synchronization - Update both quick-start and detailed setup documentation - Improve command tables and cross-references This addresses the common confusion when make status shows no IP while virsh domifaddr shows the VM has a valid IP address.
1 parent 4c0edc0 commit a2e0554

File tree

3 files changed

+83
-9
lines changed

3 files changed

+83
-9
lines changed

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Makefile for Torrust Tracker Local Testing Infrastructure
2-
.PHONY: help init plan apply destroy test clean status ssh install-deps console vm-console lint lint-yaml lint-shell lint-markdown
2+
.PHONY: help init plan apply destroy test clean status refresh-state ssh install-deps console vm-console lint lint-yaml lint-shell lint-markdown
33

44
# Default variables
55
VM_NAME ?= torrust-tracker-demo
@@ -79,6 +79,12 @@ status: ## Show current infrastructure status
7979
@echo "Infrastructure status:"
8080
cd $(TERRAFORM_DIR) && tofu show
8181

82+
refresh-state: ## Refresh Terraform state to detect IP changes
83+
@echo "Refreshing Terraform state..."
84+
cd $(TERRAFORM_DIR) && tofu refresh
85+
@echo "Updated outputs:"
86+
cd $(TERRAFORM_DIR) && tofu output
87+
8288
ssh: ## SSH into the VM
8389
@echo "Connecting to VM..."
8490
@VM_IP=$$(virsh domifaddr $(VM_NAME) | grep ipv4 | awk '{print $$4}' | cut -d'/' -f1); \

infrastructure/docs/local-testing-setup.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ tofu refresh
310310
- Verify firewall rules
311311
312312
6. **VM deployment timeout (can't get IP address)**
313+
313314
- **Symptoms**: VM starts but times out waiting for DHCP lease
314315
- **Cause**: Cloud-init setup takes time (package installation, system
315316
configuration, reboot)
@@ -318,4 +319,57 @@ tofu refresh
318319
- **Check**: Use `virsh console torrust-tracker-demo` or
319320
`virt-viewer spice://127.0.0.1:5900` to monitor boot progress
320321
322+
7. **Terraform/OpenTofu shows "No IP assigned yet" but VM has IP**
323+
324+
- **Symptoms**: `make status` shows:
325+
326+
```text
327+
connection_info = "VM created, waiting for IP address..."
328+
vm_ip = "No IP assigned yet"
329+
```
330+
331+
But `virsh domifaddr torrust-tracker-demo` shows an IP address.
332+
333+
- **Root Cause**: Terraform libvirt provider state is not synchronized with
334+
the actual VM network state. This happens because:
335+
336+
- DHCP lease assignment timing varies
337+
- Terraform state becomes stale after cloud-init completes
338+
- The provider doesn't automatically refresh network interface information
339+
340+
- **Solution**: Refresh the Terraform state to synchronize with libvirt:
341+
342+
```bash
343+
# Method 1: Refresh Terraform state
344+
cd infrastructure/terraform
345+
tofu refresh
346+
347+
# Method 2: Use the make command (if available)
348+
make refresh-state
349+
350+
# Verify the fix
351+
tofu output
352+
```
353+
354+
- **Prevention**: The IP detection issue can be minimized by:
355+
356+
- Waiting 2-3 minutes after `make apply` before checking IP
357+
- Using `virsh domifaddr VM_NAME` to get IP directly from libvirt
358+
- Adding automatic refresh to the Makefile status command
359+
360+
- **Alternative**: Get the IP directly from libvirt without Terraform:
361+
362+
```bash
363+
# Get IP address directly
364+
virsh domifaddr torrust-tracker-demo
365+
366+
# Or use in scripts
367+
VM_IP=$(virsh domifaddr torrust-tracker-demo | grep ipv4 | awk '{print $4}' | cut -d'/' -f1)
368+
echo "VM IP: $VM_IP"
369+
```
370+
371+
- **Why This Happens**: The libvirt provider checks `network_interface[0].addresses`
372+
which is populated asynchronously. The VM gets its IP from DHCP, but Terraform's
373+
cached state doesn't reflect this until explicitly refreshed.
374+
321375
### Logs and Debugging

infrastructure/docs/quick-start.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,15 @@ make destroy
134134

135135
## 📋 Available Commands
136136

137-
| Command | Description |
138-
| -------------- | --------------------------- |
139-
| `make help` | Show all available commands |
140-
| `make test` | Run complete test suite |
141-
| `make apply` | Deploy VM |
142-
| `make ssh` | Connect to VM |
143-
| `make destroy` | Remove VM |
144-
| `make status` | Show infrastructure status |
137+
| Command | Description |
138+
| -------------------- | -------------------------------------------- |
139+
| `make help` | Show all available commands |
140+
| `make test` | Run complete test suite |
141+
| `make apply` | Deploy VM |
142+
| `make ssh` | Connect to VM |
143+
| `make destroy` | Remove VM |
144+
| `make status` | Show infrastructure status |
145+
| `make refresh-state` | Refresh Terraform state to detect IP changes |
145146

146147
## 🔧 Troubleshooting
147148

@@ -151,6 +152,19 @@ make destroy
151152
2. **VM won't start**: Check with `sudo kvm-ok` that virtualization is enabled
152153
3. **SSH connection fails**: VM might still be booting, wait 2-3 minutes
153154
4. **libvirt file ownership errors**: Run `make fix-libvirt` to fix permissions
155+
5. **"No IP assigned yet" issue**: If `make status` shows no IP but VM is running:
156+
157+
```bash
158+
# Check if VM actually has an IP
159+
virsh domifaddr torrust-tracker-demo
160+
161+
# If IP is shown, refresh Terraform state
162+
make refresh-state
163+
```
164+
165+
**Why this happens**: Terraform's state can become stale after cloud-init completes.
166+
The VM gets its IP from DHCP, but Terraform doesn't automatically detect this change.
167+
See [detailed troubleshooting](local-testing-setup.md#troubleshooting) for more info.
154168

155169
### Getting Help
156170

0 commit comments

Comments
 (0)