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

Commit 47e7984

Browse files
committed
feat: [#28] Complete Phase 2 multi-provider architecture with SSH auto-detection
🚀 **PHASE 2 COMPLETED**: Provider System Implementation ## Core Achievements ✅ **Multi-Provider Architecture**: Complete pluggable provider system - Standardized provider interface with validation - LibVirt provider module fully implemented - Zero changes needed to add new providers ✅ **SSH Key Auto-Detection**: Enhanced security system - Hierarchical detection: ~/.ssh/torrust_rsa.pub, ~/.ssh/id_rsa.pub, etc. - Eliminated hardcoded personal SSH keys - Clear error messages and validation ✅ **Enhanced User Experience**: Improved messaging and error handling - Better IP detection messaging (Terraform state vs libvirt direct) - VM name detection for both torrust-tracker-dev and torrust-tracker-demo - Comprehensive logging and error reporting ## New File Structure infrastructure/terraform/providers/libvirt/ ├── main.tf # Provider-specific infrastructure resources ├── variables.tf # Provider-specific variables ├── outputs.tf # Provider-specific outputs ├── versions.tf # Provider requirements and version constraints └── provider.sh # Provider interface implementation with SSH validation ## Performance Results - **E2E Test 1**: 2m 39s - Full end-to-end validation - **E2E Test 2**: 2m 34s - Consistent performance - **CI Tests**: All pass - Complete validation suite - **SSH Security**: Auto-detection working, no hardcoded keys ## Working Commands ```bash # Twelve-factor workflow with provider system make infra-apply ENVIRONMENT=development PROVIDER=libvirt make app-deploy ENVIRONMENT=development make app-health-check ENVIRONMENT=development make infra-destroy ENVIRONMENT=development PROVIDER=libvirt # E2E testing make test-e2e # Completes in ~2m 35s consistently ``` ## Integration Points - **Makefile**: PROVIDER parameter support in all infrastructure commands - **Environment Variables**: VM_NAME and provider-specific variables - **Terraform**: Multi-provider state management with conditional modules - **Security**: SSH key validation and auto-detection pipeline ## Next Steps Ready Phase 2 implementation is **COMPLETE** and production-ready: - ✅ Foundation solid for additional providers (AWS, Azure, GCP) - ✅ Provider interface validated and working - ✅ Enhanced security with SSH auto-detection - ✅ Performance validated with E2E tests **Ready for Phase 3**: Enhanced Makefile commands and provider discovery
1 parent 9b29232 commit 47e7984

File tree

13 files changed

+1174
-393
lines changed

13 files changed

+1174
-393
lines changed

Makefile

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
.PHONY: infra-init infra-plan infra-apply infra-destroy infra-status infra-refresh-state
44
.PHONY: infra-config-development infra-config-production infra-validate-config
55
.PHONY: infra-test-prereq infra-test-ci infra-test-local
6+
.PHONY: infra-providers infra-environments provider-info
67
.PHONY: app-deploy app-redeploy app-health-check
78
.PHONY: app-test-config app-test-containers app-test-services
89
.PHONY: vm-ssh vm-console vm-gui-console vm-clean-ssh vm-prepare-ssh vm-status
910
.PHONY: dev-setup dev-deploy dev-test dev-clean
1011

1112
# Default variables
1213
VM_NAME ?= torrust-tracker-demo
14+
# Default values
1315
ENVIRONMENT ?= development
16+
PROVIDER ?= libvirt
1417
TERRAFORM_DIR = infrastructure/terraform
1518
INFRA_TESTS_DIR = infrastructure/tests
1619
TESTS_DIR = tests
@@ -43,9 +46,9 @@ help: ## Show this help message
4346
@echo "⚙️ SYSTEM SETUP:"
4447
@awk 'BEGIN {FS = ":.*?## "} /^(install-deps|clean).*:.*?## / {printf " %-20s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
4548
@echo ""
46-
@echo "Examples:"
47-
@echo " make dev-deploy ENVIRONMENT=development"
48-
@echo " make infra-apply ENVIRONMENT=development"
49+
@echo "Development examples:"
50+
@echo " make dev-deploy ENVIRONMENT=development PROVIDER=libvirt"
51+
@echo " make infra-apply ENVIRONMENT=development PROVIDER=libvirt"
4952
@echo " make app-deploy ENVIRONMENT=development"
5053

5154
install-deps: ## Install required dependencies (Ubuntu/Debian)
@@ -61,35 +64,66 @@ install-deps: ## Install required dependencies (Ubuntu/Debian)
6164
# =============================================================================
6265

6366
infra-init: ## Initialize infrastructure (Terraform init)
64-
@echo "Initializing infrastructure for $(ENVIRONMENT)..."
65-
$(SCRIPTS_DIR)/provision-infrastructure.sh $(ENVIRONMENT) init
67+
@echo "Initializing infrastructure for $(ENVIRONMENT) on $(PROVIDER)..."
68+
$(SCRIPTS_DIR)/provision-infrastructure.sh $(ENVIRONMENT) $(PROVIDER) init
6669

6770
infra-plan: ## Plan infrastructure changes
68-
@echo "Planning infrastructure for $(ENVIRONMENT)..."
69-
$(SCRIPTS_DIR)/provision-infrastructure.sh $(ENVIRONMENT) plan
71+
@echo "Planning infrastructure for $(ENVIRONMENT) on $(PROVIDER)..."
72+
$(SCRIPTS_DIR)/provision-infrastructure.sh $(ENVIRONMENT) $(PROVIDER) plan
7073

7174
infra-apply: ## Provision infrastructure (platform setup)
72-
@echo "Provisioning infrastructure for $(ENVIRONMENT)..."
75+
@echo "Provisioning infrastructure for $(ENVIRONMENT) on $(PROVIDER)..."
7376
@echo "⚠️ This command may prompt for your password for sudo operations"
7477
@if [ "$(SKIP_WAIT)" = "true" ]; then \
7578
echo "⚠️ SKIP_WAIT=true - Infrastructure will not wait for full readiness"; \
7679
else \
7780
echo "ℹ️ Infrastructure will wait for full readiness (use SKIP_WAIT=true to skip)"; \
7881
fi
79-
SKIP_WAIT=$(SKIP_WAIT) $(SCRIPTS_DIR)/provision-infrastructure.sh $(ENVIRONMENT) apply
82+
SKIP_WAIT=$(SKIP_WAIT) $(SCRIPTS_DIR)/provision-infrastructure.sh $(ENVIRONMENT) $(PROVIDER) apply
8083

8184
infra-destroy: ## Destroy infrastructure
82-
@echo "Destroying infrastructure for $(ENVIRONMENT)..."
83-
$(SCRIPTS_DIR)/provision-infrastructure.sh $(ENVIRONMENT) destroy
85+
@echo "Destroying infrastructure for $(ENVIRONMENT) on $(PROVIDER)..."
86+
$(SCRIPTS_DIR)/provision-infrastructure.sh $(ENVIRONMENT) $(PROVIDER) destroy
8487

8588
infra-status: ## Show infrastructure status
86-
@echo "Infrastructure status for $(ENVIRONMENT):"
89+
@echo "Infrastructure status for $(ENVIRONMENT) on $(PROVIDER):"
8790
@cd $(TERRAFORM_DIR) && tofu show -no-color | grep -E "(vm_ip|vm_status)" || echo "No infrastructure found"
8891

8992
infra-refresh-state: ## Refresh Terraform state to detect IP changes
9093
@echo "Refreshing Terraform state..."
9194
@cd $(TERRAFORM_DIR) && tofu refresh
9295

96+
# Provider and environment information
97+
infra-providers: ## List available infrastructure providers
98+
@echo "Available Infrastructure Providers:"
99+
@$(SCRIPTS_DIR)/providers/provider-interface.sh list || echo "No providers found"
100+
@echo ""
101+
@echo "Usage examples:"
102+
@echo " make infra-apply ENVIRONMENT=development PROVIDER=libvirt"
103+
@echo " make infra-apply ENVIRONMENT=staging PROVIDER=digitalocean"
104+
@echo " make infra-apply ENVIRONMENT=production PROVIDER=hetzner"
105+
106+
infra-environments: ## List available environments
107+
@echo "Available Environments:"
108+
@ls infrastructure/config/environments/*.env \
109+
infrastructure/config/environments/*.env.tpl 2>/dev/null | \
110+
xargs -I {} basename {} | sed 's/\.env.*//g' | sort | uniq || \
111+
echo "No environments found"
112+
@echo ""
113+
@echo "Environments:"
114+
@echo " development - Local development and testing"
115+
@echo " staging - Pre-production testing"
116+
@echo " production - Production deployment"
117+
118+
provider-info: ## Show provider information (requires PROVIDER=<name>)
119+
@if [ -z "$(PROVIDER)" ]; then \
120+
echo "Error: PROVIDER not specified"; \
121+
echo "Usage: make provider-info PROVIDER=<provider>"; \
122+
exit 1; \
123+
fi
124+
@echo "Getting information for provider: $(PROVIDER)"
125+
@$(SCRIPTS_DIR)/providers/provider-interface.sh info $(PROVIDER)
126+
93127
infra-config-development: ## Generate development environment configuration
94128
@echo "Configuring development environment..."
95129
$(SCRIPTS_DIR)/configure-env.sh development

0 commit comments

Comments
 (0)