メインコンテンツにスキップ

terraformで特定のmoduleだけapplyする

タグ: 🏷 terraform

背景

terraformのボリュームが大きくなると、少しの変更を待っている時間が長くなります。

リファクタリングしていて、変更ないようにちょこちょこコードを直している時なんかは、この時間がとても長く感じます。

そこで、モジュールを指定して更新するようにしました。

やったこと

たとえば、ec2モジュールを対象にします。

terraform plan --target=module.ec2

以下のようにwarningは出力されます。不安ですけど、なんとかなります。

Plan: 0 to add, 0 to change, 5 to destroy.
│ Warning: Resource targeting is in effect
│ You are creating a plan with the -target option, which means that the result of this plan may not represent all of
│ the changes requested by the current configuration.
│ The -target option is not for routine use, and is provided only for exceptional situations such as recovering from
│ errors or mistakes, or when Terraform specifically suggests to use it as part of an error message.

Do you really want to destroy all resources?
  Terraform will destroy all your managed infrastructure, as shown above.
  There is no undo. Only 'yes' will be accepted to confirm.