5
5

More than 1 year has passed since last update.

[Pluralith]Terraformコードから構成図/アーキテクチャを作成する

Last updated at Posted at 2023-07-05

はじめに

Terrafomのコードから構成図を作成してくれるPluralithというもおがあったので使用感などを検証してみる

公式ページ

公式ドキュメント

料金

  • Local Setupであれば無料
  • CI Setupは実行した回数によって課金
    image.png

公式ページの料金

操作方法

ユーザー登録

Pluralithの画面にてユーザー登録を行う
image.png

今回はLocalで実施したい為、Local Setupを選択する
CI Setupを選択すると、Github ActionsやTerraform Cloudで実行することができる

冒頭に記載したが、CI Setupは料金がかかるらしいので今回はLocal Setupでテストした。

image.png

セットアップ

公式ページ

Download CLIを選択して、モジュールをダウンロードする

Loginに記載のあるKeyは後でログイン時にし使用するので控えておく

image.png

以下コマンドでモジュールの名前を変更してからパスを通し、実行権限を付与

mv pluralith_cli_darwin_amd64_v0.2.2 pluralith
mv pluralith /usr/local/bin/
chmod 755 /usr/local/bin/pluralith

これでコマンドpluralithが実行できるようになったので、上記に表示されていたKeyをセットしてログイン

pluralith login --api-key 7b2f928475b3bdxxxxxxxxx

以下のように表示されればOK

実行結果
✔ No graph module installed, found latest release
⠿ None → 0.2.1

Installing Latest Graph Module 100% [██████████████████████████████] (22.656 MB/s)

✔ Graph Module updated!

 _
|_)|    _ _ |._|_|_
|  ||_|| (_||| | | |

Welcome to Pluralith!

  ✔ API key is valid, you are authenticated!

これでセットアップは完了

Pluralithを実行し構成図作成

Terraformのディレクトリを実行し、以下コマンドを実行

pluralith graph

terraform initを実行していなかったので以下エラーが出力された
ちゃんと、tfstateの保管場所とかをみてくれているみたい

⠿ Initiating Graph ⇢ Posting Diagram To Pluralith Dashboard

→ Authentication
  ✔ API key is valid, you are authenticated!

→ Plan
  ✘ Couldn't Generate Local Execution Plan

Error: Backend initialization required, please run "terraform init"

Reason: Initial configuration of the requested backend "s3"

The "backend" is the interface that Terraform uses to store state,
perform operations, etc. If this message is showing up, it means that the
Terraform configuration you're using is using a custom configuration for
the Terraform backend.

Changes to backend configurations require reinitialization. This allows
Terraform to set up the new configuration, copy existing state, etc. Please
run
"terraform init" with either the "-reconfigure" or "-migrate-state" flags to
use the current configuration.

If the change reason above is incorrect, please verify your configuration
hasn't changed and try again. At this point, no changes to your existing
configuration or state have been made.

running terraform plan failed -> GenerateGraph: RunPlan: exit status 1

改めてterraform initを実行してからpluralith graphを実行
WEBページが開き、構成図が表示された
今回は作成済みのリソースだったので、terraform planの差分はなしとなり、構成図上も変更差分はない状態だった。
image.png

変更差分確認

画面右下にCreatedUpdateなどがあったので試しにTerraformコードを変更し、実施してみる

すべて削除する場合

Deleteとして検知されていた(赤枠)
image.png

変更の場合

Updateとして検知された(黄色枠)
ただし、今回はS3のBucket名変更だったので、Recreatedとして検知されていた
image.png

その他機能

料金表示

今回は、Cloudfront+S3という定常的に料金のかからない構成で作成してしまったが、EC2など定常的に料金が掛かってくるリソースなどを作成した場合は料金も表示してくれるみたい(画面左のCostsを選択すると表示される)
image.png

実行履歴

Local Runsを表示するとローカルでの実行履歴が確認できる。
image.png

補足

コマンドpluralithを実行したあとにディレクトリを確認するとディレクトリ.pluralithができているのが確認できた。
これもGithubなどに含めたら、実行履歴なども共有できそう

.
├── .DS_Store
├── .pluralith
│   ├── pluralith.cache.json
│   ├── pluralith.plan.bin
│   └── pluralith.state.json
├── .terraform
│   ├── modules
│   │   └── modules.json
│   ├── providers
│   │   └── registry.terraform.io
│   │       └── hashicorp
│   │           └── aws
│   │               └── 4.55.0
│   │                   └── darwin_arm64
│   │                       └── terraform-provider-aws_v4.55.0_x5
│   └── terraform.tfstate
├── .terraform.lock.hcl
├── cloudfront-s3.tf
├── datasource.tf
├── locals.tf
├── modules
│   ├── .DS_Store
│   └── public-static-web
│       ├── .DS_Store
│       ├── cloudfront.tf
│       ├── img
│       │   ├── error.html
│       │   ├── index.html
│       │   └── mock_img.jpeg
│       ├── output.tf
│       ├── s3.tf
│       └── variables.tf
├── provider.tf
├── terraform.tfvars
└── variables.tf

13 directories, 23 files

あとがき

  • これまで、Terraformコードから構成図を作成するものはいくつかあったが、moduleに対応していないなど、少し不便なところがあったがPluralithはStateファイルから読みってくれるのでかなり良い。
  • 構成図作成する際はもうこれで良いんじゃないかなと思う。

参考記事

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