Making Terraform output available for use in later GitLab CI pipelines

Hi there! I’m new to using GitLab CI – CI in general, really – and I’ve looked through the documentation for how to do this and I’m struggling to come up with an answer.

Describe your question in as much detail as possible:

I have some infrastructure that I deploy using Terraform. I’d like to have a GitLab CI pipeline which validates the infrastructure and applies it. This is pretty straightforward to do and I found many examples of how to do it.

The next part of my pipeline involves building and deploying my application, which is in a separate repository. To reduce duplication I’d like to make some of the Terraform output I’ve set up available to this next part. For example, the database name, EC2 IP addresses for auto-scaling groups, etc. How can I make this happen? I wasn’t able to find anything in the documentation about it, and most of the external tutorials I found don’t seem to cover multi-project pipelines with Terraform, unless I missed something obvious.

How do I set this up properly? Am I even approaching this problem in the right way? Thanks in advance!