-
Notifications
You must be signed in to change notification settings - Fork 5
/
managing.yaml
275 lines (262 loc) · 8.97 KB
/
managing.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
AWSTemplateFormatVersion: '2010-09-09'
Description: Setup AWS CloudProvider for Spinnaker
Parameters:
SpinnakerVPCCIDR:
Description: CIDR Block for Developer VPC
Type: String
Default: 10.100.0.0/16
SpinnakerPublicSubnet1CIDR:
Description: SpinnakerEnv Public Subnet
Type: String
Default: 10.100.10.0/24
ConstraintDescription: IP CIDR must be in the range of your VPC
SpinnakerPublicSubnet2CIDR:
Description: SpinnakerEnv Private Subnet
Type: String
Default: 10.100.11.0/24
ConstraintDescription: IP CIDR must be in the range of your VPC
UseAccessKeyForAuthentication:
Description: >
Select Yes, if you want to use Access Keys and Secrets for Authentication.Selecting Yes will also create Access Keys and Secrets,
which will be visible in Outputs Section, once the template runs successfully. It is recommended that you update the stack and remove the outputs section.
Select No, if you will use EC2 Instance profile.
Type: String
AllowedValues:
- true
- false
EksClusterName:
Description : >
Enter EKS cluster name, if you want to run Spinnaker on EKS. Please ensure EKS is available in the region you are executing this template.
For more information about EKS availability, refer https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/
If you leave this parameter as the default value of None, EKS cluster will not be created.
Type: String
Default: None
Conditions:
CreateAccessKeys : !Equals [ !Ref UseAccessKeyForAuthentication, true ]
CreateEc2Role: !Equals [ !Ref UseAccessKeyForAuthentication, false ]
SupportEKS: !Not [!Equals ["None",!Ref EksClusterName]]
Resources:
BaseIAMRole:
Properties:
RoleName: BaseIAMRole
AssumeRolePolicyDocument:
Statement:
- Action:
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- ec2.amazonaws.com
Version: '2012-10-17'
Path: /
Type: AWS::IAM::Role
EksServiceRole:
Type: AWS::IAM::Role
Condition: SupportEKS
Properties:
AssumeRolePolicyDocument:
Statement:
- Action:
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- eks.amazonaws.com
Version: '2012-10-17'
Path: /
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AmazonEKSClusterPolicy
- arn:aws:iam::aws:policy/AmazonEKSServicePolicy
EksCluster:
Type: AWS::EKS::Cluster
Condition: SupportEKS
Properties:
Name: !Ref EksClusterName
Version: "1.11"
RoleArn: !GetAtt EksServiceRole.Arn
ResourcesVpcConfig:
SecurityGroupIds:
- !Ref ControlPlaneSecurityGroup
SubnetIds:
- !Ref SpinnakerPublicSubnet1
- !Ref SpinnakerPublicSubnet2
# Creates Instance Profile to be used by any APP created by Spinnaker. Spinnaker has passRole access only to this instance Profile
BaseInstanceProfile:
DependsOn: SpinnakerAuthRole
Condition: CreateEc2Role
Properties:
InstanceProfileName: BaseInstanceProfile
Path: /
Roles:
- !Ref BaseIAMRole
Type: AWS::IAM::InstanceProfile
# Creates EC2 Role and Instance Profile with which Spinnaker Runs
SpinnakerInstanceProfile:
DependsOn: SpinnakerAuthRole
Condition: CreateEc2Role
Properties:
Path: /
Roles:
- !Ref 'SpinnakerAuthRole'
Type: AWS::IAM::InstanceProfile
SpinnakerAuthRole:
Properties:
RoleName: SpinnakerAuthRole
AssumeRolePolicyDocument:
Statement:
- Action:
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- ec2.amazonaws.com
Version: '2012-10-17'
ManagedPolicyArns:
- arn:aws:iam::aws:policy/PowerUserAccess
- !If [SupportEKS,"arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy",!Ref "AWS::NoValue"]
- !If [SupportEKS,"arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy",!Ref "AWS::NoValue"]
- !If [SupportEKS,"arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly",!Ref "AWS::NoValue"]
Type: AWS::IAM::Role
Condition: CreateEc2Role
# Creates IAM user and AccessKeys
SpinnakerUser:
Description: User identity Spinnaker uses to create AWS resources
Properties:
ManagedPolicyArns:
- arn:aws:iam::aws:policy/PowerUserAccess
Type: AWS::IAM::User
Condition: CreateAccessKeys
SpinnakerAccessKey:
DependsOn: SpinnakerUser
Condition: CreateAccessKeys
Description: Generate AccessKey for Spinnaker
Properties:
UserName: !Ref 'SpinnakerUser'
Type: AWS::IAM::AccessKey
# Either Keys or Instances
SpinnakerAssumeRolePolicy:
Type: AWS::IAM::Policy
Properties:
Users:
- !If [CreateAccessKeys,!Ref SpinnakerUser,!Ref 'AWS::NoValue']
Roles:
- !If [CreateEc2Role,!Ref SpinnakerAuthRole,!Ref 'AWS::NoValue']
PolicyDocument:
Version: '2012-10-17'
Statement:
- Action: sts:AssumeRole
Effect: Allow
Resource:
- !Sub arn:aws:iam::${AWS::AccountId}:role/spinnakerManaged # This is the current account
#- arn:aws:iam::YOUR_MANAGED_ACCOUNT1:role/spinnakerManaged # Keep Adding Managed Accounts like this
PolicyName: SpinnakerAssumeRolePolicy
# Creates a single subnet VPC
SpinnakerVPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: !Ref 'SpinnakerVPCCIDR'
EnableDnsSupport: 'true'
EnableDnsHostnames: 'true'
Tags:
- Key: VPC
Value: Spinnaker VPC
- Key: Name
Value: SpinnakerVPC
SpinnakerInternetGateway:
Type: AWS::EC2::InternetGateway
SpinnakerAttachGateway:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
VpcId: !Ref 'SpinnakerVPC'
InternetGatewayId: !Ref 'SpinnakerInternetGateway'
SpinnakerPublicSubnet1:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref 'SpinnakerVPC'
CidrBlock: !Ref SpinnakerPublicSubnet1CIDR
AvailabilityZone: !Select
- '0'
- !GetAZs ''
Tags:
- Key: Name
Value: !Sub SpinnakerVPC.external.${AWS::Region}a
- Key: immutable_metadata # If you cannot name the VPC as done above, use this tag
Value: !Sub |
{"purpose": "public-subnet"}
SpinnakerPublicSubnet2:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref 'SpinnakerVPC'
CidrBlock: !Ref SpinnakerPublicSubnet2CIDR
AvailabilityZone: !Select
- '1'
- !GetAZs ''
Tags:
- Key: Name
Value: !Sub SpinnakerVPC.external.${AWS::Region}b
- Key: immutable_metadata
Value: !Sub |
{"purpose": "public-subnet"}
SpinnakerPublicRouteTable:
Type: AWS::EC2::RouteTable
DependsOn:
- SpinnakerVPC
- SpinnakerAttachGateway
Properties:
VpcId: !Ref 'SpinnakerVPC'
Tags:
- Key: Name
Value: Spinnaker Public Route Table
SpinnakerPublicRoute:
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref 'SpinnakerPublicRouteTable'
DestinationCidrBlock: '0.0.0.0/0'
GatewayId: !Ref 'SpinnakerInternetGateway'
SpinnakerPublicSubnet1RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref SpinnakerPublicSubnet1
RouteTableId: !Ref 'SpinnakerPublicRouteTable'
SpinnakerPublicSubnet2RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref SpinnakerPublicSubnet2
RouteTableId: !Ref 'SpinnakerPublicRouteTable'
ControlPlaneSecurityGroup:
Type: AWS::EC2::SecurityGroup
Condition: SupportEKS
Properties:
GroupDescription: Cluster communication with worker nodes
VpcId: !Ref SpinnakerVPC
Outputs:
AccessKeyId:
Condition: CreateAccessKeys
Value: !Ref SpinnakerAccessKey
Secret:
Condition: CreateAccessKeys
Value: !GetAtt SpinnakerAccessKey.SecretAccessKey
ManagingAccountId:
Value: !Ref AWS::AccountId
AuthArn:
Value: !If [CreateAccessKeys,!GetAtt SpinnakerUser.Arn,!GetAtt SpinnakerAuthRole.Arn ]
EksClusterEndpoint:
Condition: SupportEKS
Value: !GetAtt EksCluster.Endpoint
EksClusterCA:
Condition: SupportEKS
Value: !GetAtt EksCluster.CertificateAuthorityData
SubnetIds:
Description: All subnets in the VPC
Value: !Join [ ",", [ !Ref SpinnakerPublicSubnet1,!Ref SpinnakerPublicSubnet2 ] ]
EksClusterName:
Condition: SupportEKS
Value: !Ref EksClusterName
SpinnakerInstanceProfileArn:
Value: !GetAtt SpinnakerInstanceProfile.Arn
VpcId:
Value: !Ref SpinnakerVPC
SecurityGroups:
Condition: SupportEKS
Description: Security group for the cluster control plane communication with worker nodes
Value: !Join [ ",", [ !Ref ControlPlaneSecurityGroup ] ]