Terraform state provider reports a 500 error when the lineage or version does not match
When pushing state to GitLab's terraform state provider, if the lineage or version mismatch, the server will report a 500 error.
$ terraform state push -lock=false -force "instrumentor_int_test-onboard.tfstate"
2021/10/28 10:38:27 [DEBUG] POST https://gitlab.com/api/v4/projects/27996746/terraform/state/instrumentor_int_test-onboard (status: 500): retrying in 1s (2 left)
2021/10/28 10:38:28 [DEBUG] POST https://gitlab.com/api/v4/projects/27996746/terraform/state/instrumentor_int_test-onboard (status: 500): retrying in 2s (1 left)
Failed to persist state: Failed to upload state: POST https://gitlab.com/api/v4/projects/27996746/terraform/state/instrumentor_int_test-onboard giving up after 3 attempts
When reviewing the error in ELK, the error is
PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_terraform_state_versions_on_state_id_and_version"
DETAIL: Key (terraform_state_id, version)=(681369, 2) already exists.
This is not a server error, it should be treated as a client error (400) to ensure that the infrastructure team are not alerted and that the client understands that the problem is on their side.
Verification
The following query should not return any results: https://log.gprd.gitlab.net/goto/51aed8cd125a8a60b5f5af26bae9cbf8
Edited by Andrew Newdigate