2
1

More than 1 year has passed since last update.

tfstateファイルが更新されない

Posted at

結論

backendを追加したからでした。

backend.tf

terraform {
  backend "s3" {
      bucket = "buket-name"
      key = "pass/to/terraform.tfstate"
      region = "ap-northeast-1"
  }
}

これを追加することでtfstateファイルがs3に保存されるようになります。
私の想定していた動きとしてはローカルのtfstateにも保存されs3にも保存される
という動きを想定していたのですがs3に保存されるのみでした。

terraform init時

backendを追記すると以下のように聞いてくれています。

terraforminit.sh

$ terraform init

Initializing the backend...
╷
│ Error: Backend configuration changed
│ 
│ A change in the backend configuration has been detected, which may require migrating existing state.
│ 
│ If you wish to attempt automatic migration of the state, use "terraform init -migrate-state".
│ If you wish to store the current configuration with no changes to the state, use "terraform init
│ -reconfigure".

backendを変更する場合は-migrate-state
変更せず保存する場合は-reconfigure
を付けて実行します。

-migrate-stateを付けてterraform initを実行し変更すると
ローカルに保存していたtfstateファイルが
s3に保存されるようになったりと保存場所、参照場所を変更することが出来ます。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1