I need to create 2 VM using Terraform on different subnets, only 1 will have Public IP (VM1), the other one just private ip (VM2). I need to connect to the one with public IP via SSH only (so far so good) but from this one I need to be able to SSH into the other one, this is where I'm stuck. I'm able to connect to VM1 and then ping VM2 but not able to SSH.
I'm passing my .pub key to both VMs using below block, but after connect to the VM1 I'm not able to ssh into VM2 because, of course, the private key does not exist on VM1 and seems there is no way (at least I havent found how) to pass it to VM1 during the creating.
Thanks for the help.
resource "tls_private_key" "js-ssh-key" {
algorithm = "RSA"
rsa_bits = 4096
}
admin_ssh_key {
username = "azureuser"
public_key = file ("~/.ssh/id_rsa.pub")
}