# Proxmox Windows Cloud Image Tool

Tool untuk membuat Proxmox VM template dari Windows cloud images (qcow2 format).

## Features

- ✅ Upload Windows cloud image (qcow2) ke Proxmox
- ✅ Create VM dengan konfigurasi Windows (UEFI, TPM 2.0, Secure Boot)
- ✅ Convert VM ke template
- ✅ Support QEMU Guest Agent
- ✅ Support firewall configuration
- ✅ Support VLAN tagging
- ✅ Auto-find available VM ID
- ✅ Batch processing multiple configs
- ✅ List available storage

## Requirements

- Go 1.19+
- SSH access ke Proxmox host
- Windows cloud image dalam format qcow2

## Cara Buat Windows Cloud Image

Gunakan [cloudbase/windows-imaging-tools](https://github.com/cloudbase/windows-imaging-tools):

```powershell
# Clone repo
git clone https://github.com/cloudbase/windows-imaging-tools.git
cd windows-imaging-tools

# Import module
Import-Module .\WinImageBuilder.psm1

# Download Windows ISO (contoh: Windows Server 2022)
# Buat cloud image
$ConfigFilePath = ".\Examples\config.ini"
New-WindowsCloudImage -ConfigFilePath $ConfigFilePath

# Output: windows-server-2022.qcow2
```

## Installation

### Linux:

```bash
cd windows-tools
go build -o proxmox-windows
sudo cp proxmox-windows /usr/local/bin/
```

### Windows (PowerShell):

```powershell
cd windows-tools
go build -o proxmox-windows.exe
# Add to PATH atau jalankan langsung
```

## Usage

### CLI Flags:

```bash
proxmox-windows \
  -image-path /path/to/windows-server-2022.qcow2 \
  -vm-name windows-server-2022-template \
  -vm-id 0 \
  -storage local-lvm \
  -memory 4096 \
  -cores 2 \
  -bridge vmbr0 \
  -proxmox-host 192.168.1.100 \
  -proxmox-user root@pam \
  -guest-agent \
  -firewall
```

### Config File (Recommended):

```bash
proxmox-windows -config config.yaml
```

**config.yaml:**
```yaml
image_path: "/path/to/windows-server-2022.qcow2"
vm_name: "windows-server-2022-template"
vm_id: 0  # 0 = auto-find
storage: "local-lvm"
memory: 4096
cores: 2
sockets: 1
bridge: "vmbr0"
vlan_tag: 0
proxmox_host: "192.168.1.100"
proxmox_user: "root@pam"
guest_agent: true
firewall: true

firewall_rules:
  - type: out
    action: drop
    dest: "10.0.0.0/8"
    comment: "Block internal network"
  - type: in
    action: accept
    protocol: tcp
    dport: "3389"
    comment: "Allow RDP"
  - type: in
    action: accept
    protocol: tcp
    dport: "5985-5986"
    comment: "Allow WinRM"
```

### Batch Processing:

```bash
proxmox-windows -batch batch.txt
```

**batch.txt:**
```
configs/windows-server-2022.yaml
configs/windows-11.yaml
configs/windows-server-2019.yaml
```

### List Available Storage:

```bash
proxmox-windows -list-storage -proxmox-host 192.168.1.100
# atau
proxmox-windows -ls -proxmox-host 192.168.1.100
```

## VM Configuration

Tool ini akan membuat VM dengan konfigurasi:

- **BIOS**: OVMF (UEFI)
- **Machine Type**: q35
- **EFI Disk**: 1GB dengan pre-enrolled keys (Secure Boot)
- **TPM**: v2.0 (required untuk Windows 11)
- **SCSI Controller**: VirtIO SCSI
- **Network**: VirtIO
- **Boot Order**: scsi0
- **Guest Agent**: Enabled (optional)

## Firewall Rules

Format firewall rules sama dengan Linux tools:

```yaml
firewall_rules:
  - type: in|out
    action: accept|drop|reject
    protocol: tcp|udp|icmp
    dport: "port atau port-range"
    sport: "port atau port-range"
    source: "IP/CIDR"
    dest: "IP/CIDR"
    comment: "Description"
```

**Contoh:**
```yaml
firewall_rules:
  # Allow RDP
  - type: in
    action: accept
    protocol: tcp
    dport: "3389"
    comment: "Allow RDP"
  
  # Allow WinRM
  - type: in
    action: accept
    protocol: tcp
    dport: "5985-5986"
    comment: "Allow WinRM"
  
  # Block outgoing to internal network
  - type: out
    action: drop
    dest: "10.0.0.0/8"
    comment: "Block internal network"
  
  # Allow DNS
  - type: out
    action: accept
    protocol: udp
    dport: "53"
    comment: "Allow DNS"
```

## Clone Template

Setelah template dibuat:

```bash
# Clone template
qm clone 10000 101 --name windows-server-01

# Start VM
qm start 101

# Access via RDP
# IP akan di-assign via DHCP (jika cloud-init configured)
```

## Troubleshooting

### 1. SSH Connection Failed
```bash
# Test SSH connection
ssh root@192.168.1.100

# Check SSH key
ssh-keygen -R 192.168.1.100
```

### 2. Storage Not Found
```bash
# List available storage
proxmox-windows -ls -proxmox-host 192.168.1.100

# Atau manual
ssh root@192.168.1.100 'pvesm status'
```

### 3. Upload Failed
- Check network connection
- Check disk space di Proxmox host
- Tool akan retry 3x otomatis

### 4. VM Creation Failed
```bash
# Check Proxmox logs
ssh root@192.168.1.100 'tail -f /var/log/pve/tasks/active'
```

## Notes

- Windows cloud images harus dalam format **qcow2**
- VM akan dibuat dengan **UEFI + TPM 2.0** (required untuk Windows 11)
- Guest Agent harus di-install di Windows image untuk full functionality
- Firewall rules di-apply di Proxmox level, bukan di Windows
- Template bisa di-clone unlimited times

## License

MIT
