🚀

terraform 実行中断時のメモ

2023/07/17に公開

以下のエラーが発生。
おそらくapply実行中にtokenの期限切れが発生したことが原因と思われる。
(nat gateway の作成時に発生)

│ Error: Failed to save state
│
│ Error saving state: failed checking for existing remote state: ExpiredToken: The provided token has expired.
│       status code: 400, request id: ........
╵
╷
│ Error: Failed to persist state to backend
│
│ The error shown above has prevented Terraform from writing the updated state to the configured backend. To allow for recovery, the state has been written
│ to the file "errored.tfstate" in the current working directory.
│
│ Running "terraform apply" again at this point will create a forked state, making it harder to recover.
│
│ To retry writing this state, use the following command:
│     terraform state push errored.tfstate
│

Error: Failed to save state という文言に少しあせるが、よく読むとterraform state push errored.tfstate でstateを更新できるようなので実行。

  • token 更新後 以下実行
$ ls errored.tfstate
errored.tfstate

$ terraform state push errored.tfstate
$ terraform plan
$ terraform apply
  • 無事解決

Discussion