通常の 【Mac】 【Windows(PowerShell)】 【Mac】 以上です。 最後まで読んでいただきありがとうございました!環境
目的
terraform plan
を実行すると、各リソースの詳細な設定まで表示されてしまい、コードの作成途中などでリソースの変更内容だけを確認したいときに不便です。この記事では、ワンライナーを用いて、リソースの変更内容の一覧を各リソース1行でコンパクトに表示する方法を紹介します。コマンド
terraform plan | grep -E '#|Plan:'
terraform plan | Select-String -Pattern "#|Plan:"
実行結果
改善前(terraform plan)
user@xxxx sample-tf-project % terraform plan'
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# module.vpc.aws_subnet.private["subnet_private01"] will be created
+ resource "aws_subnet" "private" {
+ arn = (known after apply)
+ assign_ipv6_address_on_creation = false
+ availability_zone = "ap-northeast-1a"
+ availability_zone_id = (known after apply)
+ cidr_block = "xxx.xx.x.x/12"
+ enable_dns64 = false
+ enable_resource_name_dns_a_record_on_launch = false
+ enable_resource_name_dns_aaaa_record_on_launch = false
+ id = (known after apply)
+ ipv6_cidr_block_association_id = (known after apply)
+ ipv6_native = false
+ map_public_ip_on_launch = false
+ owner_id = (known after apply)
+ private_dns_hostname_type_on_launch = (known after apply)
+ tags = {
+ "Name" = "sample-subnet-private-common-a1"
}
+ tags_all = {
+ "Name" = "sample-subnet-private-common-a1"
+ "Service" = "sample"
}
+ vpc_id = (known after apply)
}
(... 以下省略)
改善後(terraform plan | grep -E '#|Plan:' など)
user@xxxx sample-tf-project % terraform plan | grep -E '#|Plan:'
# module.vpc.aws_subnet.private["subnet_private01"] will be created
# module.vpc.aws_subnet.private["subnet_private02"] will be created
# module.vpc.aws_subnet.private["subnet_private03"] will be created
# module.vpc.aws_subnet.public["subnet_public01"] will be created
# module.vpc.aws_subnet.public["subnet_public02"] will be created
# module.vpc.aws_subnet.public["subnet_public03"] will be created
# module.vpc.aws_vpc.default will be created
Plan: 7 to add, 0 to change, 0 to destroy.
【Windows(PowerShell)】PS C:\Users\xxxx\sample-tf-project> terraform plan | Select-String -Pattern "#|Plan:"
>>
# module.vpc.aws_subnet.private["subnet_private01"] will be created
# module.vpc.aws_subnet.private["subnet_private02"] will be created
# module.vpc.aws_subnet.private["subnet_private03"] will be created
# module.vpc.aws_subnet.public["subnet_public01"] will be created
# module.vpc.aws_subnet.public["subnet_public02"] will be created
# module.vpc.aws_subnet.public["subnet_public03"] will be created
# module.vpc.aws_vpc.default will be created
Plan: 7 to add, 0 to change, 0 to destroy.
自己紹介
かわいち
都内ではたらくWeb系エンジニアです! 普段から効率良く開発できるように心がけています。 また、趣味でもプログラミングをしており、モノづくりが好きです。 このブログでは、プログラミングに役立つコトを日々発信しています!