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?

More than 3 years have passed since last update.

terragrunt(xxx-all系)でtfnotifyを使う方法

Last updated at Posted at 2020-10-13

[terragrunt] xxx-all系で個別処理にパイプやリダイレクト等の処理を追加する方法のパイプで出力を渡す先をtfnotifyに変更するだけ。

具体的には下記のような感じのscriptを用意して、

* 下記のような作りなら、ディレクトリ移動(terragrunt plan-all等が行ってくれていること)をterragrunt側に依存しておくことで、terragrunt moduleへの対応を自分で書かずに済む。

/usr/scr/app/script/tfwrapper.sh
# !/bin/bash

set -eu

terraform "$@" 2>&1 | tee ./terraform.log

type=$(echo "$@" |  awk '{print $1}')

if [ "$type" != "plan" ] && [ "$type" != "apply" ]; then
  exit 0
fi

current_directory=$(pwd)

tfnotify --config "$TF_NOTIFY_FILE_PATH" "$type" --message "$TF_VAR_env $current_directory" < ./terraform.log

下記のように呼び出す

$ terragrunt plan-all --terragrunt-non-interactive --terragrunt-tfpath /usr/src/app/script/tfwrapper.sh

プロジェクトルート以外で、terragrunt.hclが存在しているディレクトリ内で個別にterragrunt planterragrunt applyを実行すると依存順序(terragrunt.hclで定義したdependencies)が解決されないので、tfnotifyをそのまま使いたければ現状上記方法で解決するしかないと思います。

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?