We store our states with a gitlab backend. Someone deleted the state. We recovered the state to a json file via shapshot of our gluster backend. How do I restore the state to gitlab?
I've tried following this link with no success.
.6/ee/user/infrastructure/iac/terraform_state.html
I've also seen a post about using the 'Copy terraform init command' from the project state page on gitlab and running
terraform state push /path/to/terraform.tfstate -force
and this didnt work.
Any guidance would be greatly appreciated.
We store our states with a gitlab backend. Someone deleted the state. We recovered the state to a json file via shapshot of our gluster backend. How do I restore the state to gitlab?
I've tried following this link with no success.
https://docs.gitlab.com/17.6/ee/user/infrastructure/iac/terraform_state.html
I've also seen a post about using the 'Copy terraform init command' from the project state page on gitlab and running
terraform state push /path/to/terraform.tfstate -force
and this didnt work.
Any guidance would be greatly appreciated.
Share Improve this question asked Jan 19 at 16:27 Jason ShermanJason Sherman 11 bronze badge 3 |1 Answer
Reset to default 0create a new branch. Copy the json file to name it, terraform.tfstate to the same directory as the main.tf file.
Use the code below to initialize the project.
PROJECT_ID="*<gitlab-project-id>*"
TF_USERNAME="*<gitlab-username>*"
TF_PASSWORD="*<gitlab-personal-access-token>*"
TF_ADDRESS="https://gitlab.domain/api/v4/projects/${PROJECT_ID}/terraform/state/**old-state-name**"
terraform init \
-backend-config=address=${TF_ADDRESS} \
-backend-config=lock_address=${TF_ADDRESS}/lock \
-backend-config=unlock_address=${TF_ADDRESS}/lock \
-backend-config=username=${TF_USERNAME} \
-backend-config=password=${TF_PASSWORD} \
-backend-config=lock_method=POST \
-backend-config=unlock_method=DELETE \
-backend-config=retry_wait_min=5
At the end, it'll ask you if you want to copy the state to the new back end, type 'yes'.
terraform state push [options] PATH
" Your order looks reversedterraform state push PATH [options]
– Dorad Commented Jan 19 at 16:40