-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathpipeline.yaml
146 lines (146 loc) · 4.28 KB
/
pipeline.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
---
AWSTemplateFormatVersion: '2010-09-09'
Description: 'Pipeline'
Resources:
CodeRepository:
Type: 'AWS::CodeCommit::Repository'
Properties:
RepositoryName: !Ref 'AWS::StackName'
ArtifactsBucket:
DeletionPolicy: Retain
Type: 'AWS::S3::Bucket'
Properties: {}
PipelineRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- 'cloudformation.amazonaws.com'
- 'codepipeline.amazonaws.com'
Action:
- 'sts:AssumeRole'
ManagedPolicyArns:
- 'arn:aws:iam::aws:policy/AdministratorAccess'
Pipeline:
Type: 'AWS::CodePipeline::Pipeline'
Properties:
ArtifactStore:
Type: S3
Location: !Ref ArtifactsBucket
Name: !Ref 'AWS::StackName'
RestartExecutionOnUpdate: true
RoleArn: !GetAtt 'PipelineRole.Arn'
Stages:
- Name: Source
Actions:
- Name: FetchSource
ActionTypeId:
Category: Source
Owner: AWS
Provider: CodeCommit
Version: 1
Configuration:
RepositoryName: !GetAtt 'CodeRepository.Name'
BranchName: master
PollForSourceChanges: false # see CodeCommitPipelineTriggerRule
OutputArtifacts:
- Name: Source
RunOrder: 1
- Name: VPC
Actions:
- Name: Deploy
ActionTypeId:
Category: Deploy
Owner: AWS
Provider: CloudFormation
Version: 1
Configuration:
ActionMode: CREATE_UPDATE
Capabilities: CAPABILITY_IAM
RoleArn: !GetAtt 'PipelineRole.Arn'
StackName: !Sub '${AWS::StackName}-vpc'
TemplatePath: 'Source::vpc-2azs.yaml'
OutputFileName: 'output.json'
InputArtifacts:
- Name: Source
OutputArtifacts:
- Name: VPC
RunOrder: 1
- Name: Production
Actions:
- Name: DeployInfrastructure
ActionTypeId:
Category: Deploy
Owner: AWS
Provider: CloudFormation
Version: 1
Configuration:
ActionMode: CREATE_UPDATE
Capabilities: CAPABILITY_IAM
RoleArn: !GetAtt 'PipelineRole.Arn'
StackName: !Sub '${AWS::StackName}-infrastructure'
TemplatePath: 'Source::infrastructure.yaml'
TemplateConfiguration: 'Source::infrastructure.json'
InputArtifacts:
- Name: VPC
- Name: Source
RunOrder: 1
PipelineTriggerRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- 'events.amazonaws.com'
Action:
- 'sts:AssumeRole'
Policies:
- PolicyName: 'codepipeline'
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: 'codepipeline:StartPipelineExecution'
Resource: !Sub 'arn:aws:codepipeline:${AWS::Region}:${AWS::AccountId}:${Pipeline}'
CodeCommitPipelineTriggerRule:
Type: 'AWS::Events::Rule'
Properties:
EventPattern:
source:
- 'aws.codecommit'
'detail-type':
- 'CodeCommit Repository State Change'
resources:
- !GetAtt 'CodeRepository.Arn'
detail:
referenceType:
- branch
referenceName:
- master
State: ENABLED
Targets:
- Arn: !Sub 'arn:aws:codepipeline:${AWS::Region}:${AWS::AccountId}:${Pipeline}'
Id: pipeline
RoleArn: !GetAtt 'PipelineTriggerRole.Arn'
ParameterStorePipelineTriggerRule:
Type: 'AWS::Events::Rule'
Properties:
EventPattern:
source:
- 'aws.ssm'
'detail-type':
- 'Parameter Store Change'
resources:
- !Sub 'arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/application/stage/instancetype'
State: ENABLED
Targets:
- Arn: !Sub 'arn:aws:codepipeline:${AWS::Region}:${AWS::AccountId}:${Pipeline}'
Id: pipeline
RoleArn: !GetAtt 'PipelineTriggerRole.Arn'