Azure Terraform : Running remote-exec on VM via Bastion Host

Hi,

I am attempting to create a VM without a public_ip, and instead accessing that VM via a Bastion Host.

In the VM i have the following :

provisioner ““remote-exec”” {
inline = [
“touch newfile.txt”,
“touch newfile2.txt”,
]
connection {
type = “ssh”
bastion_host = azurerm_public_ip.demo.fqdn
bastion_user = “USERNAME”
bastion_password = “PASSWORD”
host = azurerm_network_interface.demo-instance.private_ip_address
user = “USERNAME”
password = “PASSWORD”
}
}

Everything is created fine, except when it starts creating the VM

I says this :
azurerm_virtual_machine.demo-instance (remote-exec): Connecting to remote host via SSH…
azurerm_virtual_machine.demo-instance (remote-exec): Host: 10.0.0.4
azurerm_virtual_machine.demo-instance (remote-exec): User: USER
azurerm_virtual_machine.demo-instance (remote-exec): Password: true
azurerm_virtual_machine.demo-instance (remote-exec): Private key: false
azurerm_virtual_machine.demo-instance (remote-exec): Certificate: false
azurerm_virtual_machine.demo-instance (remote-exec): SSH Agent: false
azurerm_virtual_machine.demo-instance (remote-exec): Checking Host Key: false

Then finally errors out with :

Error: timeout - last error: dial tcp 10.0.0.4:22: i/o timeout

I think it has to do with the NSG not being assigned correctly.

Any help with be appreciated.