0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

terraformのnull_resourceで指定したShellScriptに変更があるときに再実行する方法

Last updated at Posted at 2024-07-16

null_resourceでapply時にShellScriptが実行されるようにした時に、ShellScriptの中身に変更があったらそれをトリガーして再実行したいなと思ったので、その方法をメモします。

こちらを参考に、以下のように記述。

shell.tf
resource "null_resource" "default" {
  triggers = {
    script_hash = "${filesha256("${path.module}/sample.sh")}"
  }

  provisioner "local-exec" {
    command = "sh ${path.module}/sample.sh"
  }
}

これで、前回のapplyからsample.shの中身が書き変わっていれば、filesha256で得られるhash値が変化するので、terraform planの差分として検出されるようになります。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?