1
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.

terraform show コマンドで plan 内容を自由自在に表示する

Posted at

terraform plan コマンドはリソースの変更内容を、色付きで詳細に表示できますが、プロジェクトが大きくなると、リソース数が多くなりすぎ全体像を把握しにくくなります。

そんなとき便利なのが 1.0.1 から追加されていた terraform show コマンド。planファイルをJSON形式に変換します。一度JSONに変換してしまえば、お好みのプログラミング言語で整形できます。

たとえば、これは追加・削除・変更されるリソースの名前だけを一覧表示するRubyのスクリプト。

# diff.rb
require 'json'

JSON.parse(STDIN.read)['resource_changes'].each do |c|
    a = c['change']['actions'][0]
    next if a == 'no-op'
    op = {
        'create' => '+',
        'delete' => '-',
        'update' => 'M'
    }[a]
    puts "#{op} #{c['address']}"
end

実行例

$ terraform plan -out=plan

$ terraform show -json plan | ruby diff.rb
M aws_db_subnet_group.private
- aws_subnet.public[0]
- aws_subnet.public[1]
+ module.public.aws_subnet.this["1a"]
+ module.public.aws_subnet.this["1c"]
1
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
1
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?