Terraform re-deploy environment doesn't work with CI/CD templates

Problem

When using the Terraform CI/CD templates the deploy job creates an environment for the deployment - this is super nice, because we get a neat deployment overview of an environment:

image

Each deploy has an associated button on the right to either re-deploy or rollback. When clicking these buttons basically the deploy job of the associated pipeline is re-tried.

The problem with that and Terraform (and in particular the CI/CD templates) is that the deploy job usually relies on a Terraform plan artifact which is built in a previous job. Thus, when trying to rollback to an older deployment Terraform (rightly) complains that the "saved plan is stale", because that job artifact is not re-generated:

image

I'd argue that this feature is generally broken for Terraform deployments, unless the plan and apply phases are in the same pipeline job, which is rather unusual.

Is still a known limitation or is there a way to define what job(s) are being run for a rollback? Or a config to disable rollbacks for certain environments / jobs?

EDIT: the environment can also not be stopped properly - I would expect a terraform destroy to be run when stopping the environment. May the entire environment integration with Terraform isn't really a supported use-case as of today.

Proposal

Update the documentation https://docs.gitlab.com/ee/ci/environments/#environment-rollback that the rollback feature for terraform pipeline might not work as expected. Instead, users should go to pipeline page and execute the plan and apply jobs.

Edited by Shinya Maeda