[QUESTION] Can i pass variables to a EC2 instance in order to modify source code inside?

Hello to all:

I’m new on learning terraform with AWS and by i understand i can create an EC2 instances and pass it some Terminal commands (via “user_data”) in order to install software, etc…

I wonder if i can i install Docker, download a repository, build an image and deploy.

But if i have a fullstack app, and i have:

Instance_1: Backend

Instance_2: Frontend

How can i catch the IP of Instance_1 (via ‘output’) and pass it to the source code of the app of the frontend stored on Instance_2 in order to make the Frontend capable of connect to the Backend on Instance_1?.

Thank you and sorry for the english