#cloud-config
# Debian 12 Autoinstall Configuration

autoinstall:
  version: 1

  # Locale and keyboard
  locale: en_US.UTF-8
  keyboard:
    layout: us
    variant: ''

  # CRITICAL: Network configuration during installation
  # This provides DHCP networking for the installation process
  # Cloud-init will be configured to NOT manage networking post-install
  network:
    version: 2
    ethernets:
      ens18:
        dhcp4: true
        dhcp6: false
      eth0:
        dhcp4: true
        dhcp6: false
      enp6s18:
        dhcp4: true
        dhcp6: false

  # Storage configuration
  storage:
    layout:
      name: direct
      match:
        size: largest
    swap:
      size: 1G  # 1GB swap partition

  # User configuration for Packer SSH access
  identity:
    hostname: packer-build
    username: packer
    password: '$6$rounds=4096$packer$QJl3rXXXN5L3T5qOKQRqW5q3qR5pMN3L8T5qOKQRqW5q3qR5pMN3L8T5qOKQRqW5q3qR5pMN3L8T5qOKQRqW.'

  # SSH configuration
  ssh:
    install-server: true
    allow-pw: true
    authorized-keys: []

  # Package configuration
  packages:
    - qemu-guest-agent
    - cloud-init
    - sudo
    - openssh-server
    - curl
    - vim
    - net-tools

  # APT configuration
  apt:
    disable_components: []
    geoip: true
    preserve_sources_list: false
    primary:
      - arches: [amd64]
        uri: http://deb.debian.org/debian
    security:
      - arches: [amd64]
        uri: http://security.debian.org/debian-security

  user-data:
    disable_root: false
    timezone: UTC

  # Late commands
  late-commands:
    - echo 'packer ALL=(ALL) NOPASSWD:ALL' > /target/etc/sudoers.d/packer
    - chmod 440 /target/etc/sudoers.d/packer
    - sed -i 's/^#*PasswordAuthentication.*/PasswordAuthentication yes/' /target/etc/ssh/sshd_config
    - sed -i 's/^#*PermitRootLogin.*/PermitRootLogin yes/' /target/etc/ssh/sshd_config
    - curtin in-target --target=/target -- systemctl enable qemu-guest-agent
    - curtin in-target --target=/target -- systemctl enable cloud-init
    - curtin in-target --target=/target -- systemctl enable cloud-init-local
    - curtin in-target --target=/target -- systemctl enable cloud-config
    - curtin in-target --target=/target -- systemctl enable cloud-final
