Unable to launch playbook on my temporary Packer instance

Hello all,

I recently discovered Packer from Hashicorp and I tried to use it for my needs.

Here is my situation.
I’m currently deploying a 3-tier infrastructure on AWS using terraform. I specify that my code is deployed from an EC2 machine outside my 3-tier infrastructure (this one is called terraform-master).

I need to create an AMI and I’m trying to use Packer to configure it. The configuration of this AMI is dependent on other AWS resources such as database ids. To do this, the temporary instance created by Packer must be deployed in the same subnet as my final EC2 (i.e. in a private subnet accessible via a bastion placed in a public subnet).
The connection to the temporary instance from Packer works correctly, I can use a shell provisioner without any problem, the configuration is done correctly.
I’d like to change my approach and use an ansible playbook to configure my instance rather than a shell script.

My problem is that my playbook seems to run on my terraform master machine and not on my temporary instance.I don’t understand how to configure my packer or my playbook so that the playbook launches on the temporary instance via my bastion.

I’ve tried using ansible-local provisioning, which works fine. However, for file transfer purposes (I’d like to retrieve a specific file present on the temporary instance in order to have it on terraform-master) I think it’s imperative to use the ansible playbook running from my terraform-master to my temporary instance rather than installing ansible on the instance, copying the ansible playbook and the variable file, and running it.

I hope I’ve made myself clear. If you have any ideas on how to solve this problem, I’d love to hear from you.

Thanks in advance