CloudFormationのMappingsでListを使いたかった

CloudFormationのテンプレートをゴリゴリ書いていて,Mappingsの箇所でListを使ったらエラーでスタックがコケてしまった.
公式ドキュメントにはList使えるよって書いていたので色々試行錯誤したがうまく行かなかった.
無理やり解決させた方法の備忘録.

スポンサーリンク

概要

  • Dev,QA環境があるアカウントとProd環境のあるアカウントを分けている
  • テンプレートは共通
  • スタックのデプロイ時にパラメータで環境を渡してリソースを切り替え
  • 諸事情によりKMSのARNを複数渡す必要があった
  • 環境により渡すArnが異なるのでMappingsにList形式でArnを記載した

うまくいかなかったソース

cloudformation-mapping-list-test/template_ng.yml at main · Shinogasa/cloudformation-mapping-list-test
Contribute to Shinogasa/cloudformation-mapping-list-test development by creating an account on GitHub.

MappingsのところへList形式にてKMSのArnを複数記載.
公式ドキュメントにも「値は String または List タイプです」と記載があったので使えるもんだと思っていた.

ERROR: The request could not be satisfied

cloudformation deproyにてスタック作成,execution-stackにて実行したところ
Syntax errors in policy. (Service: AmazonIdentityManagement; Status Code: 400; Error Code: MalformedPolicyDocument; Request ID: hoge-fuga-poyo-piyo; Proxy: null)
でCREATE_FAILED.

うまくいったパターン

どうにかしてできないもんかと試行錯誤した結果,非常に泥臭くソースのメンテナンス性が悪い方法で成功した.

cloudformation-mapping-list-test/template_ok.yml at main · Shinogasa/cloudformation-mapping-list-test
Contribute to Shinogasa/cloudformation-mapping-list-test development by creating an account on GitHub.

結局List形式は使わずそれぞれのArnを変数に入れる羽目に.
これじゃあKeyが追加になった場合や環境が追加になった際に非常にメンテがめんどくさい.

カンマで区切ればいけるよって海外の質問サイトに書いていたのでやってみたが,結果は変わらず失敗.

Can FindInMap return a list?
I'm using CloudFormation to deploy an ELB to a pre-existing VPC which has pre-existing Subnets. I've listed the subnets in a Mappings section of the template an...

なにかいい方法はないものか.
今後解決策を見つけたら追記予定.

コメント

タイトルとURLをコピーしました