テスト環境用のAWSリソース作成(コマンド) 【CloudFormation】
テスト環境用のAWSリソース作成で作ったCloudFormationを使ってテスト環境を作成
■前提
・各種リソースを作れる権限をもつEC2(Linux)があること。
■必要ファイル
・VPC.yml https://hate-aaa3.hatenablog.com/entry/2022/01/20/171002
・SG.yml https://hate-aaa3.hatenablog.com/entry/2022/01/20/171404
・IAM.yml https://hate-aaa3.hatenablog.com/entry/2022/01/24/163729
・testserver.yml https://hate-aaa3.hatenablog.com/entry/2022/01/20/173432
#クロススタック参照するリソースにスタック名を入れている都合上、一番はじめにスタック名のキー文字列を変数宣言して
少しでも柔軟にしたつもり。それでも、かっこ悪いので良い落としどころを見つけたい。
■作成時の実行コマンド(変更セットなし)
STACK_NAME="TestCF" aws cloudformation deploy --template-file VPC.yml --stack-name ${STACK_NAME}-VPC aws cloudformation deploy --template-file SG.yml --stack-name ${STACK_NAME}-SG --parameter-overrides VPCstack=${STACK_NAME}-VPC aws cloudformation deploy --template-file IAM.yml --stack-name ${STACK_NAME}-IAM --capabilities CAPABILITY_NAMED_IAM aws cloudformation deploy --template-file testserver.yml --stack-name ${STACK_NAME}-testserver --parameter-overrides VPCstack=${STACK_NAME}-VPC SGstack=${STACK_NAME}-SG IAMstack=${STACK_NAME}-IAM
■作成時の実行コマンド(変更セットあり)
STACK_NAME="TestCF" aws cloudformation deploy --template-file VPC.yml --stack-name ${STACK_NAME}-VPC --no-execute-changeset aws cloudformation deploy --template-file SG.yml --stack-name ${STACK_NAME}-SG --parameter-overrides VPCstack=${STACK_NAME}-VPC --no-execute-changeset aws cloudformation deploy --template-file IAM.yml --stack-name ${STACK_NAME}-IAM --capabilities CAPABILITY_NAMED_IAM --no-execute-changeset aws cloudformation deploy --template-file testserver.yml --stack-name ${STACK_NAME}-testserver --parameter-overrides VPCstack=${STACK_NAME}-VPC SGstack=${STACK_NAME}-SG IAMstack=${STACK_NAME}-IAM --no-execute-changeset
■削除時の実行コマンド
STACK_NAME="TestCF" aws cloudformation delete-stack --stack-name ${STACK_NAME}-testserver aws cloudformation delete-stack --stack-name ${STACK_NAME}-SG aws cloudformation delete-stack --stack-name ${STACK_NAME}-IAM aws cloudformation delete-stack --stack-name ${STACK_NAME}-VPC