Conditionally create CodePipeline actions based on CloudFormation conditions

[亡魂溺海] 提交于 2019-12-20 21:01:42

问题


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:


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


来源:https://stackoverflow.com/questions/41752007/conditionally-create-codepipeline-actions-based-on-cloudformation-conditions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!