AWS CloudFormationでEKSFargateProfileを作成しようとするとdid not stabilizeエラー
CloudFormationでEKS Fargateを作成していて詰まったので
書き残して置こうと思います
何が起こったのか
CloudFormationテンプレートを、FargateProfile設定の
ClusterNameにParametersの値を設定したところ
以下のようにFargateProfileが同時に作成実行され、
「~~~ did not stabilize.」とClusterが安定していないため
FargateProfileが作成できないエラーが発生しました


テンプレートは以下のような感じです
Clusterが作成されてからFargateProfileが実行されるように
DependsOn属性は追加しています
AWSTemplateFormatVersion: '2010-09-09'
Description: eks fargate cluster
Parameters:
EksName:
Type: String
Resources:
EKS:
Type: AWS::EKS::Cluster
Properties:
Name: !Ref EksName
〜割愛〜
FargateApp1:
Type: AWS::EKS::FargateProfile
Properties:
ClusterName: !Ref EksName
FargateProfileName: 'fp-app1'
〜割愛〜
DependsOn: EKS
FargateApp2:
Type: AWS::EKS::FargateProfile
Properties:
ClusterName: !Ref EksName
FargateProfileName: 'fp-app2'
〜割愛〜
DependsOn: EKS
解決した方法
!Refや!GetAttを使えばリソース間の作成順をCloudFormation側がよしなにみてくれます
公式を確認したところEKSクラスターをRefした場合、
クラスター名が戻り値と返ることがわかったので!Refに置き換えました
DependsOn属性も不要です
AWSTemplateFormatVersion: '2010-09-09'
Description: eks fargate cluster
Parameters:
EksName:
Type: String
Resources:
EKS:
Type: AWS::EKS::Cluster
Properties:
Name: !Ref EksName
〜割愛〜
FargateApp1:
Type: AWS::EKS::FargateProfile
Properties:
ClusterName: !Ref EKS
FargateProfileName: 'fp-app1'
〜割愛〜
FargateApp2:
Type: AWS::EKS::FargateProfile
Properties:
ClusterName: !Ref EKS
FargateProfileName: 'fp-app2'
〜割愛〜

リソース順をテンプレートで意識するよりも、CloudFormation側に
任せてしまったほうが楽ですね