The way we do this is to use EC2 User data to run a cloud-init script after the EC2 instance has been launched.
With Terraform this user data can be templated and parameterized for different environments using Terraform's templatefile and passing in variables via parameter files.
I would suggest you also read up on AWS Auto scaling groups and launch ...
You can use when: on_failure, in your case you can create a new job for rollback when your some more tests have failed.
- cleanup build when failed
For more example: https://docs.gitlab.com/ee/ci/yaml/#when
You are not able to create multiple .gitlab-ci.yml but you can manage to have what you want.
You currently have multiple software in the same repository with the same CI/CD Pipeline or jobs for your softwares.
You can use include in order to include local files from your repository, so you would get
- local: 'my_folder/.gitlab-ci.yml'
You can ...