Skip to content

Commit 0c9d081

Browse files
committed
docs: [#integration-tests] add OpenTofu state refresh step to prevent IP detection issues
- Add Step 2.4 'Refresh OpenTofu State' in main workflow to prevent 'No IP assigned yet' issues - Update workflow summary to include state refresh step - Add lesson learned about OpenTofu state synchronization - This prevents the common issue where libvirt provider state becomes stale after cloud-init - Resolves the exact issue encountered during integration testing session
1 parent 59bdd15 commit 0c9d081

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

docs/guides/integration-testing-guide.md

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,26 @@ virsh list --all
338338
1 torrust-tracker-demo running
339339
```
340340

341+
### 2.4 Refresh OpenTofu State (Important!)
342+
343+
⚠️ **CRITICAL STEP**: After VM deployment, OpenTofu's state may not immediately
344+
reflect the VM's IP address assigned by DHCP. This is a known issue where the
345+
libvirt provider state becomes stale after cloud-init completes.
346+
347+
```bash
348+
# [PROJECT_ROOT] Refresh OpenTofu state to detect IP assignment
349+
time make refresh-state
350+
```
351+
352+
**Expected Output**:
353+
354+
- OpenTofu state refreshed successfully
355+
- VM IP address properly detected
356+
- **Time**: ~3 seconds
357+
358+
**What This Fixes**: Ensures OpenTofu knows the VM's actual IP address, preventing
359+
"No IP assigned yet" issues in subsequent commands.
360+
341361
---
342362

343363
## Step 3: Wait for Cloud-Init Completion (Critical!)
@@ -936,10 +956,11 @@ This guide provides a complete integration testing workflow that:
936956

937957
1. **Creates fresh infrastructure** in ~3-5 minutes
938958
2. **Generates configuration files** from templates (~2 seconds)
939-
3. **Waits for cloud-init** to complete (~2-3 minutes)
940-
4. **Runs comprehensive tests** covering all services (~3-5 minutes)
941-
5. **Verifies end-to-end functionality** of the Torrust Tracker
942-
6. **Cleans up resources** when complete
959+
3. **Refreshes OpenTofu state** to detect VM IP (~3 seconds)
960+
4. **Waits for cloud-init** to complete (~2-3 minutes)
961+
5. **Runs comprehensive tests** covering all services (~3-5 minutes)
962+
6. **Verifies end-to-end functionality** of the Torrust Tracker
963+
7. **Cleans up resources** when complete
943964

944965
**Total Time**: ~8-12 minutes for complete cycle
945966

@@ -958,18 +979,22 @@ During the development of this guide, we identified several critical issues:
958979
3. **SSH Key Configuration**: SSH key setup is **mandatory**. The `make setup-ssh-key`
959980
step must be completed before deployment.
960981

961-
4. **Non-Default SSH Keys**: If using custom SSH keys (like `torrust_rsa`
982+
4. **OpenTofu State Refresh**: After VM deployment, the OpenTofu state may not
983+
immediately reflect the VM's IP address. The `make refresh-state` step (Section 2.4)
984+
prevents "No IP assigned yet" issues in subsequent commands.
985+
986+
5. **Non-Default SSH Keys**: If using custom SSH keys (like `torrust_rsa`
962987
instead of `id_rsa`), you must:
963988

964989
- Configure the public key in `infrastructure/terraform/local.tfvars`
965990
- Set up SSH client configuration or use `-i` flag explicitly
966991

967-
5. **Docker Compose Compatibility**: Cloud-init now installs Docker Compose V2
992+
6. **Docker Compose Compatibility**: Cloud-init now installs Docker Compose V2
968993
plugin for better compatibility with modern compose.yaml files. Integration
969994
tests automatically detect and use the appropriate command (`docker compose`
970995
or `docker-compose`).
971996

972-
6. **Cloud-Init Timing**: Cloud-init performs many operations including:
997+
7. **Cloud-Init Timing**: Cloud-init performs many operations including:
973998

974999
- Package downloads and installations
9751000
- System configuration
@@ -980,7 +1005,7 @@ During the development of this guide, we identified several critical issues:
9801005
during cloud-init, preventing connectivity blocks that caused completion
9811006
delays. Actual completion time is typically 2-3 minutes.
9821007

983-
7. **Debugging Techniques**: Use `virsh console` and cloud-init logs to debug
1008+
8. **Debugging Techniques**: Use `virsh console` and cloud-init logs to debug
9841009
issues when SSH fails.
9851010

9861011
### Success Factors

0 commit comments

Comments
 (0)