Answers: <p>Currently Terraform can <strong>NOT</strong> delete statefiles stored in remote backends. The feature request for this is <a href="https://github.com/hashicorp/terraform/issues/34172" rel="nofollow noreferrer">34172</a>.</p>
  <p>Now what you have to do is run</p>
  <ul>
  <li><code>gitlab terraform destroy</code> to have terraform remove all assets in the state file,</li>
  <li>Either use the Gitlab REST API with Curl, or the GraphAPI to accomplish the deletion of the statefile. This process is documented on Gitlab.com <a href="https://docs.gitlab.com/ee/user/infrastructure/iac/terraform_state.html#remove-a-state-file-by-using-the-api" rel="nofollow noreferrer">https://docs.gitlab.com/ee/user/infrastructure/iac/terraform_state.html#remove-a-state-file-by-using-the-api</a></li>
  </ul>
  
Answers: CC BY-SA 4.0
Answers: 2023-10-31T20:42:19.817Z
Answers: 2023-10-31T20:42:19.817Z
Answers: Evan Carroll
Body: <p>Currently I have a detached pipeline which uses the Terraform with the remote Gitlab backend.</p>
  <p>How can I after the pipeline has run delete <strong>BOTH</strong> the assets created and the statefile?</p>
  
Tags: <terraform><gitlab>
Title: How can I delete Terraform assets and statefiles created in a pipeline using the remote GitLab backend?
UserDisplayName: Evan Carroll
ThreadText: # How can I delete Terraform assets and statefiles created in a pipeline using the remote GitLab backend?
  
  (Asked by: username_0 on 2023-10-31)
  
  Currently I have a detached pipeline which uses the Terraform with the remote Gitlab backend.
  
  How can I after the pipeline has run delete **BOTH** the assets created and the statefile?
  
  **Tags:** terraform, gitlab
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2023-10-31. Score: 0 | Accepted answer
  
  Currently Terraform can **NOT** delete statefiles stored in remote backends. The feature request for this is [34172](https://github.com/hashicorp/terraform/issues/34172).
  
  Now what you have to do is run
  
  * `gitlab terraform destroy` to have terraform remove all assets in the state file,
  * Either use the Gitlab REST API with Curl, or the GraphAPI to accomplish the deletion of the statefile. This process is documented on Gitlab.com <https://docs.gitlab.com/ee/user/infrastructure/iac/terraform_state.html#remove-a-state-file-by-using-the-api>
  
  
  ---
  
  