0

I have a resource in my cloudformation stack as follows:

"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": [], 

So far so good. As you can see there is a dependency on another resource called Git. However in my Git resource I have:

"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"}
           }
      }
    }

So as you see in Git there is a condition in which if it is true Git will be created and if not then my issue starts since the second resource depends on the creation of the first one and if the first one is not created the second will not as well and that is the issue since I want the codepipeline get created anyway so if "Condition" : "isNewGitRepo" is true in Git resource then CodePipelineStack should wait for the Git resource to get created if not then it should get created without caring about Git. Something like this:

 "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": [],

I mean this part:

"DependsOn":{"Fn::If": ["isNewGitRepo",["CodeBuildJavaProject","Git"],"CodeBuildJavaProject"]}

But not working. Any idea? How can I implement it?

Hamed Minaee
  • 2,480
  • 4
  • 35
  • 63
  • Hi @ChrisWhite Thanks for the link I am checking it if it is similar to my post I edit the question – Hamed Minaee Jul 05 '17 at 15:17
  • Also note that another way, though not as clean as I would like, would simply to be having the same resource with different DependOn values where one has a Condition= constraint for the Git part. – Chris White Jul 05 '17 at 15:22
  • Hi @ChrisWhite again. I looked at it and it is kind of similar but still I think does not address my concern completely. So I see I can handle it with if staement but what if Git resource finishes the creation after pipeline resource. So the approach in that link, can it handle asynchronous nature of resource creation. By that I mean if I use that approach does it know it should wait for the Git request when it is needed? – Hamed Minaee Jul 05 '17 at 16:20
  • For furthur people still I am not sure about it but seems that what @ChrisWhite mentioned is the best way to tackle the problem unless in complicated scenarios I see otherwise. – Hamed Minaee Jul 05 '17 at 19:26

0 Answers0