-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipeline-roles.yaml
192 lines (174 loc) · 5.85 KB
/
pipeline-roles.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
---
AWSTemplateFormatVersion: 2010-09-09
Description: >
This template deploys the roles that will be needed for the pipeline
Parameters:
AppName:
Type: String
Description: Name of the application.
MinLength: "1"
MaxLength: "80"
AllowedPattern: "[A-Za-z0-9-]+"
ConstraintDescription: Malformed input parameter. AppName must only contain upper and lower case letters, numbers, and -.
AppStackName:
Type: String
Description: Name of stack for the application.
MinLength: "1"
MaxLength: "80"
AllowedPattern: "[A-Za-z0-9-]+"
ConstraintDescription: Malformed input parameter. AppStackName must only contain upper and lower case letters, numbers, and -.
Resources:
codeBuildTrustRole:
Description: Creating service role in IAM for AWS CodeBuild
Type: AWS::IAM::Role
Properties:
RoleName: !Sub ${AppName}-codebuild-role
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service: codebuild.amazonaws.com
Action: sts:AssumeRole
Path: /
codeBuildRolePolicy:
Description: Setting IAM policy for the service role for AWS CodeBuild
Type: AWS::IAM::Policy
Properties:
PolicyName: !Sub ${AppName}-CodeBuildRolePolicy-${AWS::Region}
PolicyDocument:
Statement:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource:
- !Sub arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/codebuild/*
- Effect: Allow
Action:
- cloudformation:DescribeStacks
Resource:
- !Sub arn:aws:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/${AppName}-*
- Effect: Allow
Action:
- dynamodb:PutItem
Resource: !Sub "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${AppName}-*"
Roles:
- !Ref codeBuildTrustRole
codePipelineTrustRole:
Description: Creating service role in IAM for AWS CodePipeline
Type: AWS::IAM::Role
Properties:
RoleName: !Sub ${AppName}-codepipeline-role
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service: codepipeline.amazonaws.com
Action: sts:AssumeRole
Path: /
codePipelineRolePolicy:
Description: Setting IAM policy for the service role for AWS CodePipeline
Type: AWS::IAM::Policy
Properties:
PolicyName: !Sub ${AppName}-CodePipelineRolePolicy-${AWS::Region}
PolicyDocument:
Statement:
- Effect: Allow
Action:
- codebuild:StartBuild
- codebuild:BatchGetBuilds
Resource: "*"
- Effect: Allow
Action:
- iam:GetRole
- iam:PassRole
Resource: !GetAtt lambdaDeployTrustRole.Arn
- Effect: Allow
Action:
- cloudformation:Describe*
- cloudformation:CreateChangeSet
- cloudformation:DeleteChangeSet
- cloudformation:ExecuteChangeSet
Resource: !Sub "arn:aws:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/${AppStackName}/*"
Roles:
- !Ref codePipelineTrustRole
lambdaDeployTrustRole:
Description: Creating service role in IAM for AWS CodePipeline
Type: AWS::IAM::Role
Properties:
RoleName: !Sub ${AppName}-LambdaDeploy-role
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service: cloudformation.amazonaws.com
Action: sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AWSCloudFormationReadOnlyAccess
Path: /
lambdaDeployRolePolicy:
Description: Setting IAM policy for for AWS CodePipeline to deploy Lambdas
Type: AWS::IAM::Policy
Properties:
PolicyName: !Sub ${AppName}-LambdaDeployRolePolicy-${AWS::Region}
PolicyDocument:
Statement:
- Effect: Allow
Action:
- cloudformation:Create*
- cloudformation:ExecuteChangeSet
- cloudformation:SetStackPolicy
- cloudformation:SignalResource
- cloudformation:StopStackSetOperation
- cloudformation:Update*
Resource: "*"
- Effect: Allow
Action:
- apigateway:*
Resource: !Sub "arn:aws:apigateway:${AWS::Region}::*"
- Effect: Allow
Action:
- iam:GetRole
- iam:CreateRole
- iam:DeleteRole
Resource: !Sub "arn:aws:iam::${AWS::AccountId}:role/${AppName}-*"
- Effect: Allow
Action:
- iam:AttachRolePolicy
- iam:DetachRolePolicy
- iam:PutRolePolicy
Resource: !Sub "arn:aws:iam::${AWS::AccountId}:role/${AppName}-*"
- Effect: Allow
Action:
- iam:PassRole
Resource: "*"
- Effect: Allow
Action:
- lambda:*
Resource: !Sub "arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${AppName}-*"
- Effect: Allow
Action:
- dynamodb:*
Resource: !Sub "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${AppName}-*"
Roles:
- !Ref lambdaDeployTrustRole
Outputs:
CodeBuildRoleArn:
Description: Role ARN for code build to build
Value: !GetAtt codeBuildTrustRole.Arn
CodeBuildRoleName:
Description: Role name for code build to build
Value: !Ref codeBuildTrustRole
CodePipelineRoleArn:
Description: Role ARN for code pipeline
Value: !GetAtt codePipelineTrustRole.Arn
CodePipelineRoleName:
Description: Role name for code pipeline
Value: !Ref codePipelineTrustRole
LambdaDeployRoleArn:
Description: Role ARN for deploying lambdas
Value: !GetAtt lambdaDeployTrustRole.Arn
LambdaDeployRoleName:
Description: Role name for deploying lambdas
Value: !Ref lambdaDeployTrustRole