For Ubuntu we can use cloud-init. After generate iso we can mount from terraform.
- Make iso
sudo apt-get install genisoimage
cat meta-data
local-hostname: tpl-ubuntu
instance-id: vmname
cat user-data
#cloud-config
users:
- name: techuser
groups: sudo
sudo: ['ALL=(ALL) NOPASSWD:ALL']
ssh_authorized_keys:
- ssh-ed25519 AAAAC3Nz....
shell: /bin/bash
write_files:
- path: /etc/ssh/sshd_config.d/60-cloudimg-settings.conf
content: |
PasswordAuthentication yes
packages:
- mc
runcmd:
- [ systemctl, status, ssh ]
final_message: Machine configured
cat network-config
network:
version: 2
ethernets:
enp0s17:
dhcp4: no
addresses: [192.168.1.10/24]
gateway4: 192.168.1.100
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
genisoimage -input-charset utf-8 -output seed-01.iso -volid cidata -joliet -rock user-data meta-data network-config
#chage ip to 192.168.1.11 in network-config file and make next iso
genisoimage -input-charset utf-8 -output seed-02.iso -volid cidata -joliet -rock user-data meta-data network-config
- Edit main.tf
resource "virtualbox_vm" "vmname" {
count = 2
name = format("vmname-%02d", count.index + 1)
image = "https://app.vagrantup.com/ubuntu/boxes/jammy64/versions/20240315.1.0/providers/virtualbox.box"
cpus = 2
memory = "2.0gib"
network_adapter {
type = "bridged"
host_interface = "Realtek Gaming 2.5GbE Family Controller"
}
optical_disks = [
format("d:\\tmp\\seed-%02d.iso", count.index + 1)
]
}
output "IPAddr_vmname1" {
value = element(virtualbox_vm.vmname.*.network_adapter.0.ipv4_address, 1)
}
output "IPAddr_vmname2" {
value = element(virtualbox_vm.vmname.*.network_adapter.0.ipv4_address, 2)
}
P.s. Add to https://github.com/3forges/packman/blob/master/terraform/README.md. If you want :)
For Ubuntu we can use cloud-init. After generate iso we can mount from terraform.
P.s. Add to https://github.com/3forges/packman/blob/master/terraform/README.md. If you want :)