Only run CI job if triggered from upstream

I have two projects, API and Terraform. When the API project is built, I have it trigger Terraform to deploy our API using the Terraform script. The problem is that when I push code directly to Terraform, gitlab CI is running and then failing as it does not have the build context from the upstream API task. Is there a way to prevent the builds of Terraform when I push code to the Terraform repo, but allow the API to trigger Terraform?