我的cloudformation堆栈中有一个资源如下:
"CodePipelineStack":{
"Type":"AWS::CodePipeline::Pipeline",
"DependsOn":["CodeBuildJavaProject","Git"],
"Properties":{
"RoleArn":{
"Fn::Join":[
"",
[
"arn:aws:iam::",
{
"Ref":"AWS::AccountId"
},
":role/",
{
"Ref":"CodePipelineRole"
}
]
]
},
"Stages":[
{
"Name": "Source",
"Actions": [
{
"InputArtifacts": [],
到目前为止一切顺利。正如您所看到的,对另一个名为Git的资源存在依赖关系。但是在我的Git资源中我有:
"Git":{
"Type":"AWS::CloudFormation::Stack",
"Condition" : "isNewGitRepo",
"Properties":{
"TemplateURL":"..../git.json",
"TimeoutInMinutes":"60",
"Parameters" : {
"OutputBucketName" : {"Ref":"OutputBucketName"},
"AllowedIps" : {"Ref":"AllowedIps"},
"ApiSecret" : {"Ref":"ApiSecret"},
"GitToken" : {"Ref":"GitToken"},
"OauthKey" : {"Ref":"OauthKey"},
"OauthSecret" : {"Ref":"OauthSecret"}
}
}
}
正如你在Git中看到的那样,如果确实存在Git,那么将创建Git,如果没有,那么我的问题就开始了,因为第二个资源依赖于第一个资源的创建以及第一个资源是否未创建第二个也不会这样,这就是问题,因为我希望无论如何都要创建codepipeline所以如果“条件”:“isNewGitRepo”在Git资源中为真,那么CodePipelineStack应该等待Git资源被创建,如果不是那么它应该得到在没有关心Git的情况下创建。像这样:
"CodePipelineStack":{
"Type":"AWS::CodePipeline::Pipeline",
"DependsOn":{"Fn::If": ["isNewGitRepo",
["CodeBuildJavaProject","Git"],"CodeBuildJavaProject"]}
"Properties":{
"RoleArn":{
"Fn::Join":[
"",
[
"arn:aws:iam::",
{
"Ref":"AWS::AccountId"
},
":role/",
{
"Ref":"CodePipelineRole"
}
]
]
},
"Stages":[
{
"Name": "Source",
"Actions": [
{
"InputArtifacts": [],
我的意思是这一部分:
"DependsOn":{"Fn::If": ["isNewGitRepo",["CodeBuildJavaProject","Git"],"CodeBuildJavaProject"]}
但不行。任何的想法?我该如何实施呢?