Skip to content

Instantly share code, notes, and snippets.

@takenoko-str
Last active March 4, 2017 09:23
Show Gist options
  • Save takenoko-str/a518370d20163589ef40c9503ee0d7a3 to your computer and use it in GitHub Desktop.
Save takenoko-str/a518370d20163589ef40c9503ee0d7a3 to your computer and use it in GitHub Desktop.
terraform remove states in the terraform.tfstate

###なにこれ このコマンドはterraformで起動したAWSリソースを誰かが手動で消してしまった場合に使います。
あなたのterraform.tfstateファイルにはリソースは存在していることになっており、かつ、実際にはリソースがなくなっている場合を想定してください。
あなたはterraform.tfstateに記載されているjsonを直接編集しなくとも、
terraform state rmを用いて対象のリソースを設定から取り除くことができます。
まとめて削除したい場合にはシェルで一気にエラーが生じたリソースのみ取り除けます。

(terraform plan 1> /dev/null) 2>&1 | grep \* | awk '{print $2}' | sed "s|:||g" | xargs terraform state rm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment