LoginSignup
3
0

More than 1 year has passed since last update.

StackSets用のテンプレートは「taskcat」で簡単に全Regionテストしましょう

Last updated at Posted at 2021-07-17

はじめに

Organizations+StackSetsでマルチリージョンにばらまくテンプレートが、本当に各リージョンで使えるか確認するのは面倒ですよね。
単なる文法チェックではエラーが見つからないので、実際にデプロイする必要がありますし。
かといってサボると付帯リソースが、特定リージョンに対応しておらず失敗してしまうことも:disappointed_relieved:

そんな時に見つけたのがAWS謹製OSSのtaskcat!

AWS CloudFormationテンプレートを複数のAWSリージョンにデプロイし、リージョンごとに合格/不合格のグレードを含むレポートを生成してくれるようです。見た感じ、オレオレスクリプト書くより良さそうなので試してみましょう。
※先人たちのノウハウは既に転がっていますが、せめて2021年現在っぽいリソースを使いながら。ということで……

実行環境

本来はCI/CD環境に組み込むものなのでしょうが、今回はお試しなのでCloudShellで立ち上げます。

# install
pip3 install -U pip
sudo pip3 install taskcat
# 確認
taskcat
 _            _             _   
| |_ __ _ ___| | _____ __ _| |_ 
| __/ _` / __| |/ / __/ _` | __|
| || (_| \__ \   < (_| (_| | |_ 
 \__\__,_|___/_|\_\___\__,_|\__|



version 0.9.23
usage: taskcat [args] <command> [args] [subcommand] [args] 

taskcat is a tool that tests AWS CloudFormation templates. It deploys your AWS CloudFormation template in multiple AWS Regions and generates a report with a pass/fail grade for each region. You can specify the regions and number of Availability Zones you want to include in the test, and pass in parameter values from your AWS CloudFormation template.

optional arguments:
  -h, --help          show this help message and exit
  -v, --version       show program's version number and exit
  -q, --quiet         reduce output to the minimum
  -d, --debug         adds debug output and tracebacks
  --profile _PROFILE  set the default profile used.

commands:
  delete - [ALPHA] Deletes an installed package in an AWS account/region
  deploy - [ALPHA] installs a stack into an AWS account/region
  lint - checks CloudFormation templates for issues using cfn-python-lint
  list - [ALPHA] lists taskcat jobs with active stacks
  package - packages lambda source files into zip files. If a dockerfile is present in asource folder, it will be run prior to zipping the contents
  test - Performs functional tests on CloudFormation templates.
  update-ami - Updates AMI IDs within CloudFormation templates
  upload - Uploads project to S3.

普通に動きましたね。

定義ファイル

taskcat.yml
project:
  name: sample-analyzer
  s3_bucket: sample-bucket
  tags:
    Name: sample-analyzer
tests:
  defaultRegion:
    parameters:
      AnalyzerName: test-analyzer
      Email: xxxxxxxx@gmail.com
    regions:
    - us-east-2                                           
    - us-east-1                                             
    - us-west-1                                           
    - us-west-2                                       
    - ap-south-1                                
    - ap-northeast-3                                                       
    - ap-northeast-2
    - ap-southeast-1
    - ap-southeast-2                                                       
    - ap-northeast-1                                                        
    - ca-central-1
    - eu-central-1
    - eu-west-1
    - eu-west-2
    - eu-west-3
    - eu-north-1
    - sa-east-1
    template: ./sample-aa.yaml 
  • 本ファイルを「.taskcat.yml」として実行ディレクトリに配置する。
    • ※projectの内容は任意です
  • 今回のマルチリージョンの定義は下に掲載の「オプトイン=不要」の17リージョンを対象とします。

テスト対象のCloudFormationテンプレート

こちらの記事のテンプレートをお借りしました。※ファイル名はsample-aa.yaml としました。

実行

  • 必要なファイルを配置したら下のコマンドで実行できます。
    • 並列にCreateStack→ツールでのReport→DeleteStackを実施している様子なので、本来IAMRole設定が必要ですね。
      • 今回はCloudShell内なので割愛できました。
    • 標準出力汚れるのが嫌な人は「-q」オプションで。
taskcat test run 

結果

result-taskcat.PNG

東京リージョンでのみ失敗していました……! ナンデ?

result-taskcat-error.PNG

 Resource handler returned message: "Analyzer limit exceeded (Service: AccessAnalyzer

とあるので、既にリソース数の上限を超えていたのが原因でした。
こういった実環境で試さないとハマるところを、スッと試せるのがうれしいですね。

注意点?

  • CloudFormationを連打するとAWS Configの課金カウントがかなりのものになってしまうので、CIに組み込む際は考慮しましょう!
3
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
3
0