15

Enable / disable sections of a CloudFormation for CodePipeline using Conditionals:

This creates a manual notification action once staging has been built and passed Runscope tests:

- InputArtifacts: []
      Name: !Join ["",[!Ref GitHubRepository, "-prd-approval"]]
      ActionTypeId:
        Category: Approval
        Owner: AWS
        Version: '1'
        Provider: Manual
      OutputArtifacts: []
      Configuration:
        NotificationArn: !GetAtt ["SNSApprovalNotification", "Outputs.SNSTopicArn"]
        ExternalEntityLink: OutputTestUrl
      RunOrder: 3

How to enable/disable this like other CloudFormation resources with a Condition: .

Action steps don't recognize Condition: param

I could make 2 copies of the whole pipeline code one with and one without and then toggle which pipeline I create but it seems like there should be a better way.

Eric Nord
  • 4,674
  • 3
  • 28
  • 56

1 Answers1

33

You should be able to accomplish this by conditionally inserting the AWS::CodePipeline::Pipeline Resource's Action into the Actions list using the Fn::If Intrinsic Function referencing your Conditions element, returning the Action when the Condition is true and AWS::NoValue (which removes the property, in this case removing the item from the list) when it is not true:

- !If
  - IsProdCondition
  - InputArtifacts: []
    Name: !Join ["",[!Ref GitHubRepository, "-prd-approval"]]
    ActionTypeId:
      Category: Approval
      Owner: AWS
      Version: '1'
      Provider: Manual
    OutputArtifacts: []
    Configuration:
      NotificationArn: !GetAtt ["SNSApprovalNotification", "Outputs.SNSTopicArn"]
      ExternalEntityLink: OutputTestUrl
    RunOrder: 3
  - !Ref AWS::NoValue
wjordan
  • 19,770
  • 3
  • 85
  • 98
  • 2
    AWS support: "This is a very interesting question, and it took me a while to think about it... Well, I need to admit that the solution from Stackoverflow is the most convenient one. And I tested in my simulation stack, it worked perfect." – Eric Nord Jan 23 '17 at 16:47
  • I am getting the following error Property Actions cannot be empty. – Jeetendra Pujari Jan 14 '20 at 16:22