Conditionally create CodePipeline actions based on

2019-04-07 16:54发布

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.

1条回答
够拽才男人
2楼-- · 2019-04-07 17:26

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
查看更多
登录 后发表回答