この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。
こんばんわ、札幌のヨシエです。
皆様はCloudFormationでシステム環境を作成しておりますでしょうか?
今回はCloudFormation活用の幅を広げる「taskcat」を試してみました。
taskcatとは?
taskcatとはaws-quickstartで公開されているCloudFormationテンプレートのテストを実行するツールになります。
ポイントとしてはあらかじめ設定ファイルを作成することでAWSが提供している各リージョンでCloudFormationテンプレートのデプロイを実施、リージョンで問題なく作成できることの評価を行います。
特徴としては以下の点が挙げられます。
Python3で実行するので環境を用意しやすい
具体的な導入手順は後述しますが、pip3にてインストールすることが可能です。
GIthub上のREADMEに注意点としてWindows上でのtaskcat実行はサポートされていないため、
Windowsユーザーで使ってみようと考えられる方はWSL2か小さいEC2インスタンスなどのLinux環境を用意する必要があります。
指定したテンプレートスタックをデプロイ、スタックの削除を一通り実施してくれる
taskcatはCloudFormationテンプレートのデプロイを実施、エラーが出力されないことを確認したあとにスタックの削除を実施してくれます。
この機能によって各リージョンでテストスタックが残ることがないので管理の手間が省けます。
テンプレートファイルの文法チェックを実施してくれる
テストの実施時にテンプレート内の適切ではない表記を注意してくれます。
今回の検証では検証用のVPCテンプレートで使用しておりましたが、AvailabilityZoneの指定部分やDependsonの指定が適切ではないというチェックを実施してくれました。
テスト時にはAWS Configに注意
taskcatは指定されたリージョンでスタックのデプロイを行うことからAWS Configの利用費用が発生する可能性がありますので、ご注意ください。
実際の作業を行う
taskcatをインストール
以下のコマンドでtaskcatをインストールします。
# pip3 install taskcat
問題なくインストールされれば、以下のコマンドでバージョンが出力されます。
# taskcat --version
_ _ _
| |_ __ _ ___| | _____ __ _| |_
| __/ _` / __| |/ / __/ _` | __|
| || (_| \__ \ < (_| (_| | |_
\__\__,_|___/_|\_\___\__,_|\__|
version 0.9.18
0.9.18
.taskcat.ymlを作成する
taskcatに実施させたい設定ファイルを作成します。
.taskcat.ymlは隠しファイルとして頭に.
が付くのでご注意ください。
今回は以下の条件でテストを実施します。
project:
name: yoshie-taskcat-test
s3_bucket: yoshie-taskcat-result // 試験パス時にテンプレートをUpするS3バケット
tags:
Name: yoshie-taskcat-test
tests:
ap-northeast-1: //東京リージョン用テスト名
regions:
- ap-northeast-1 //試験対象リージョン(東京リージョン)
parameters: //スタック作成時に渡すパラメーター(東京リージョンのAZを指定)
VPCPublicaParameter: ap-northeast-1a
VPCPubliccParameter: ap-northeast-1c
VPCFrontendaParameter: ap-northeast-1a
VPCFrontendcParameter: ap-northeast-1c
VPCDataStoreaParameter: ap-northeast-1a
VPCDataStorecParameter: ap-northeast-1c
template: ./yoshie-poc-vpc-template.yaml //試験対象テンプレートファイル
ap-south-1: //ムンバイリージョン用テスト名
regions:
- ap-south-1 //試験対象リージョン(ムンバイリージョン)
parameters: //スタック作成時に渡すパラメーター(ムンバイリージョンのAZを指定)
VPCPublicaParameter: ap-south-1a
VPCPubliccParameter: ap-south-1c
VPCFrontendaParameter: ap-south-1a
VPCFrontendcParameter: ap-south-1c
VPCDataStoreaParameter: ap-south-1a
VPCDataStorecParameter: ap-south-1c
template: ./yoshie-poc-vpc-template.yaml //試験対象テンプレートファイル
taskcatコマンドでテストを開始する
# tree -a
.
├── .taskcat.yml
└── yoshie-poc-vpc-template.yaml
以下のコマンドでテストを実行します。
# taskcat test run
_ _ _
| |_ __ _ ___| | _____ __ _| |_
| __/ _` / __| |/ / __/ _` | __|
| || (_| \__ \ < (_| (_| | |_
\__\__,_|___/_|\_\___\__,_|\__|
version 0.9.18
[INFO ] : Lint passed for test ap-northeast-1 on template /root/yoshie-taskcat-test/yoshie-poc-vpc-template.yaml
[INFO ] : Lint passed for test ap-south-1 on template /root/yoshie-taskcat-test/yoshie-poc-vpc-template.yaml
[S3: DELETE ] s3://yoshie-taskcat-result/yoshie-taskcat-test/yoshie-taskcat-test/yoshie-poc-vpc-template.yaml_old
[INFO ] : ┏ stack Ⓜ tCaT-yoshie-taskcat-test-ap-northeast-1-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx [INFO ] : ┣ region: ap-northeast-1 [INFO ] : ┗ status: CREATE_COMPLETE [INFO ] : ┏ stack Ⓜ tCaT-yoshie-taskcat-test-ap-south-1-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx [INFO ] : ┣ region: ap-south-1 [INFO ] : ┗ status: CREATE_COMPLETE
[INFO ] : Reporting on arn:aws:cloudformation:ap-northeast-1:xxxxxxxxxxxxx:stack/tCaT-yoshie-taskcat-test-ap-northeast-1-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[INFO ] : Reporting on arn:aws:cloudformation:ap-south-1:xxxxxxxxxxxxx:stack/tCaT-yoshie-taskcat-test-ap-south-1-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[INFO ] : Deleting stack: arn:aws:cloudformation:ap-northeast-1:xxxxxxxxxxxxx:stack/tCaT-yoshie-taskcat-test-ap-northeast-1-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[INFO ] : Deleting stack: arn:aws:cloudformation:ap-south-1:xxxxxxxxxxxxx:stack/tCaT-yoshie-taskcat-test-ap-south-1-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[INFO ] : ┏ stack Ⓜ tCaT-yoshie-taskcat-test-ap-northeast-1-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx [INFO ] : ┣ region: ap-northeast-1 [INFO ] : ┗ status: DELETE_COMPLETE [INFO ] : ┏ stack Ⓜ tCaT-yoshie-taskcat-test-ap-south-1-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx [INFO ] : ┣ region: ap-south-1 [INFO ] : ┗ status: DELETE_COMPLETE
[INFO ] : Will not delete bucket created outside of taskcat yoshie-taskcat-result
コマンド実行後はtaskcat_outputs
ディレクトリが作成され、ディレクトリ内の実施されたレポート(index.html)と実施されたCloudFormationスタックのログファイルが配置されます。
# tree -a
.
├── taskcat_outputs
│ ├── index.html
│ ├── tCaT-yoshie-taskcat-test-ap-northeast-1-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-ap-northeast-1-cfnlogs.txt
│ └── tCaT-yoshie-taskcat-test-ap-south-1-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-ap-south-1-cfnlogs.txt
├── .taskcat.yml
└── yoshie-poc-vpc-template.yaml
レポートファイルは下記画像のように各テスト項目ずつ作成され、テストログ列の「View Logs」を選択することでCloudFormationのスタック作成ログが表示されます。
最後に
CloudFormation自体を導入する理由は様々であり、容易に指定されたリソースを的確に作成することが大きい目的と考えます。
今回のtaskcatでは容易にマルチリージョンでテンプレートがデプロイ出来る事を確認ができ、万が一特定のリージョンが使用できなくなってしまった場合に備える事が可能になりますので一度試して頂けると幸いです。