最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

restore terraform state from backup json file - Stack Overflow

programmeradmin3浏览0评论

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
  • From terraform docs: "Usage: terraform state push [options] PATH" Your order looks reversed terraform state push PATH [options] – Dorad Commented Jan 19 at 16:40
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Bot Commented Jan 19 at 21:37
  • the resolution to this was to make a branch of the project and add the restored terraform state. Then run the init cmd which will see the state file know ask if you want to push the state file back to gitlab. (it thinks its a local state and the code is still backend http) – Jason Sherman Commented Jan 25 at 13:01
Add a comment  | 

1 Answer 1

Reset to default 0

create 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'.

发布评论

评论列表(0)

  1. 暂无评论