Hello for my school task i need to have this working: Assignment: Deploy the following machines on your ESXi server using Terraform:
- Debian VM with 1 vCPU and 1024MB memory (to be removed afterward).Ensure that the IP address of this machine is obtained as output.
- Debian VMs with 1 vCPU and 2048MB memory, where:
- Set an SSH key via cloud-init.
- Create a user with passwordless sudo privileges via cloud-init.
- Install the packages
curl
andntpdate
via cloud-init. - Capture the IP address of each machine in a file on your management system (WSL/Linux).
Save the code in Git.
This is my main script but i still get errors like with ssh connection, do i mis something in my script?:# Versie en providervereisten
terraform {
required_version = “>= 0.13”
required_providers {
esxi = {
source = “josenk/esxi”
}
}
}
ESXi-provider configuratie
provider “esxi” {
esxi_hostname = “XXXX”
esxi_hostport = “22”
esxi_hostssl = “443”
esxi_username = “root”
esxi_password = “Welkom01!”
}
Initiële Debian VM
resource “esxi_guest” “debian_vm_initial” {
count = 1
guest_name = “debian-vm-initial”
disk_store = “Datastore10”
memsize = 1024
numvcpus = 1
ovf_source = “https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-amd64.ova”
network_interfaces {
virtual_network = “VM Network”
}
provisioner “remote-exec” {
inline = [
“echo ${self.ip_address} > /tmp/debian_vm_initial_ip.txt”
]
connection {
type = "ssh"
host = self.ip_address
user = "student"
private_key = file("/home/student/.ssh/id_ed25519")
}
}
}
Debian VM’s met cloud-init configuratie
resource “esxi_guest” “debian_vm” {
count = 3
guest_name = “debian-vm-${count.index}”
disk_store = “Datastore10”
memsize = 2048
numvcpus = 1
ovf_source = “https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-amd64.ova”
network_interfaces {
virtual_network = “VM Network”
}
guestinfo = {
userdata = base64encode(templatefile(“${path.module}/userdata.yaml”, { index = count.index, ssh_username = “student”, ssh_public_key = “ssh-ed25519 generated student@debian” }))
}
provisioner “remote-exec” {
inline = [
“echo {self.ip_address} > /tmp/debian_vm_ip_{count.index}.txt”
]
connection {
type = "ssh"
host = self.ip_address
user = "student"
private_key = file("/home/student/.ssh/id_ed25519")
}
}
}