Skip to content

Instantly share code, notes, and snippets.

@StanGenchev
Created August 5, 2020 10:40
Show Gist options
  • Save StanGenchev/d19e8689a0e173be84d9b7486877d951 to your computer and use it in GitHub Desktop.
Save StanGenchev/d19e8689a0e173be84d9b7486877d951 to your computer and use it in GitHub Desktop.
CloudFormation CodePipeline Conditional Action
AWSTemplateFormatVersion: 2010-09-09
Transform:
- AWS::Serverless-2016-10-31
Parameters:
ProjectId:
Type: String
Stage:
Type: String
Conditions:
StageNameProd: !Equals [!Ref Stage, prod]
Resources:
...
CodePipelineStack:
Type: AWS::CodePipeline::Pipeline
Properties:
Name: "Example-pipeline"
RoleArn: !GetAtt CodePipelineRole.Arn
ArtifactStore:
Location: !Ref ArtifactStoreBucket
Type: S3
Stages:
...
- Name: Deploy
Actions:
- Name: GenerateChangeSet
ActionTypeId:
Category: Deploy
Owner: AWS
Version: 1
Provider: CloudFormation
InputArtifacts:
- Name: BuildArtifact
Configuration:
ActionMode: CHANGE_SET_REPLACE
Capabilities: CAPABILITY_NAMED_IAM
ChangeSetName: !Sub "${Stage}-${ProjectId}-changeset"
RoleArn: !GetAtt CloudFormationRole.Arn
StackName: !Sub "${Stage}-${ProjectId}-stack-${AWS::Region}"
TemplatePath: BuildArtifact::template.yml
RunOrder: 3
Region: !Ref AWS::Region
Namespace: DeployVariables
- !If
- StageNameProd
- Name: DeployApproval
ActionTypeId:
Category: Approval
Owner: AWS
Version: 1
Provider: Manual
Configuration:
NotificationArn: arn:aws:sns:us-west-2:00123456789:codepipeline-appvoral
CustomData: !Sub "Approve the changeset for ${ProjectId} to deploy to the ${Stage} stage."
RunOrder: 4
- !Ref AWS::NoValue
- Name: ExecuteChangeSet
ActionTypeId:
Category: Deploy
Owner: AWS
Version: 1
Provider: CloudFormation
Configuration:
ActionMode: CHANGE_SET_EXECUTE
ChangeSetName: !Sub "${Stage}-${ProjectId}-changeset"
StackName: !Sub "${Stage}-${ProjectId}-stack-${AWS::Region}"
RunOrder: !If [StageNameProd, 5, 4]
Region: !Ref AWS::Region
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment