🛕

terraform planを見やすくするワンライナー

2022/07/12に公開

めっちゃ小ネタです🍣
terraform plan をした際に差分がめっちゃあった時に見やすくするためのワンライナーです

terminal
terraform plan -no-color | grep --line-buffered -E '^\S+|^\s{,2}(\+|-|~|-/\+) |^\s<=|^Plan'

こんな感じで出てきます
\s{,2} の数字を大きくするとネストの深い差分を見ることができます

動作イメージ
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create
  ~ update in-place
  - destroy
 <= read (data resources)
Terraform will perform the following actions:
 <= data "cluster" "thumb"  {
 <= data "template_file" "node_user_data"  {
  + resource "aws_autoscaling_group" "asg" {
  + resource "aws_eks_cluster" "cluster" {
  + resource "aws_eks_fargate_profile" "profile" {
  + resource "aws_iam_openid_connect_provider" "cluster" {
  + resource "aws_launch_template" "eks_node" {
  ~ resource "aws_security_group" "sg" {
  - resource "aws_vpc_endpoint" "vpc_endpoint" {
  ~ resource "aws_subnet" "private_subnet_1" {
  ~ resource "aws_subnet" "private_subnet_2" {
  ~ resource "aws_subnet" "private_subnet_3" {
  ~ resource "aws_subnet" "public_subnet_1" {
  ~ resource "aws_subnet" "public_subnet_2" {
  ~ resource "aws_subnet" "public_subnet_3" {
  ~ resource "aws_vpc" "vpc" {
Plan: 5 to add, 8 to change, 1 to destroy.
Changes to Outputs:
  + cluster_security_group = (known after apply)
  - eks_node_security_group_id      = "sg-xxxxx" -> null
  + identity_provider_arn  = (known after apply)
  - peering_id             = "pcx-xxxxx" -> null

そんだけ😌

Discussion