Skip to content
This repository was archived by the owner on Jul 10, 2021. It is now read-only.

Commit e813a5d

Browse files
authored
docs(aws): Move EC2 CloudFormation templates into repo (#2020)
* docs(aws): add CloudFormation templates to spinnaker.io downloads folder * docs(aws): Fix broken CFN output when EC2 role is not created * docs(aws): Switch to using Secrets Manager to store access key creds instead of directly in CFN outputs * docs(aws): Temporarily remove 'option 3' stub from EC2 docs
1 parent 5c291ed commit e813a5d

File tree

3 files changed

+364
-14
lines changed

3 files changed

+364
-14
lines changed

downloads/aws/managed.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
AWSTemplateFormatVersion: '2010-09-09'
2+
Description: Setup AWS CloudProvider for Spinnaker
3+
Parameters:
4+
AuthArn:
5+
Description: ARN which Spinnaker is using. It should be the ARN either of the IAM user or the EC2 Instance Role, which is used by Spinnaker in Managing Account
6+
Type: String
7+
ManagingAccountId:
8+
Description: AWS Account number, in which Spinnaker is running
9+
Type: String
10+
11+
Resources:
12+
13+
SpinnakerManagedRole:
14+
Type: AWS::IAM::Role
15+
Properties:
16+
RoleName: spinnakerManaged
17+
AssumeRolePolicyDocument:
18+
Statement:
19+
- Action:
20+
- sts:AssumeRole
21+
Effect: Allow
22+
Principal:
23+
AWS: !Ref AuthArn
24+
Version: '2012-10-17'
25+
ManagedPolicyArns:
26+
- arn:aws:iam::aws:policy/PowerUserAccess
27+
SpinnakerManagedPolicy:
28+
Type: AWS::IAM::Policy
29+
Properties:
30+
Roles:
31+
- !Ref SpinnakerManagedRole
32+
PolicyDocument:
33+
Version: '2012-10-17'
34+
Statement:
35+
- Action: iam:PassRole
36+
Effect: Allow
37+
Resource: "*" # You should restrict this only to certain set of roles, if required
38+
PolicyName: SpinnakerPassRole

downloads/aws/managing.yaml

Lines changed: 303 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,303 @@
1+
AWSTemplateFormatVersion: "2010-09-09"
2+
Description: Setup AWS CloudProvider for Spinnaker
3+
Parameters:
4+
SpinnakerVPCCIDR:
5+
Description: CIDR Block for Developer VPC
6+
Type: String
7+
Default: 10.100.0.0/16
8+
SpinnakerPublicSubnet1CIDR:
9+
Description: SpinnakerEnv Public Subnet
10+
Type: String
11+
Default: 10.100.10.0/24
12+
ConstraintDescription: IP CIDR must be in the range of your VPC
13+
SpinnakerPublicSubnet2CIDR:
14+
Description: SpinnakerEnv Private Subnet
15+
Type: String
16+
Default: 10.100.11.0/24
17+
ConstraintDescription: IP CIDR must be in the range of your VPC
18+
UseAccessKeyForAuthentication:
19+
Description: >
20+
Select Yes, if you want to use Access Keys and Secrets for Authentication.Selecting Yes will also create Access Keys and Secrets,
21+
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.
22+
Select No, if you will use EC2 Instance profile.
23+
Type: String
24+
AllowedValues:
25+
- true
26+
- false
27+
EksClusterName:
28+
Description: >
29+
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.
30+
For more information about EKS availability, refer https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/
31+
If you leave this parameter as the default value of None, EKS cluster will not be created.
32+
Type: String
33+
Default: None
34+
35+
Conditions:
36+
CreateAccessKeys: !Equals [!Ref UseAccessKeyForAuthentication, true]
37+
CreateEc2Role: !Equals [!Ref UseAccessKeyForAuthentication, false]
38+
SupportEKS: !Not [!Equals ["None", !Ref EksClusterName]]
39+
Resources:
40+
BaseIAMRole:
41+
Properties:
42+
RoleName: BaseIAMRole
43+
AssumeRolePolicyDocument:
44+
Statement:
45+
- Action:
46+
- sts:AssumeRole
47+
Effect: Allow
48+
Principal:
49+
Service:
50+
- ec2.amazonaws.com
51+
Version: "2012-10-17"
52+
Path: /
53+
Type: AWS::IAM::Role
54+
55+
EksServiceRole:
56+
Type: AWS::IAM::Role
57+
Condition: SupportEKS
58+
Properties:
59+
AssumeRolePolicyDocument:
60+
Statement:
61+
- Action:
62+
- sts:AssumeRole
63+
Effect: Allow
64+
Principal:
65+
Service:
66+
- eks.amazonaws.com
67+
Version: "2012-10-17"
68+
Path: /
69+
ManagedPolicyArns:
70+
- arn:aws:iam::aws:policy/AmazonEKSClusterPolicy
71+
- arn:aws:iam::aws:policy/AmazonEKSServicePolicy
72+
EksCluster:
73+
Type: AWS::EKS::Cluster
74+
Condition: SupportEKS
75+
Properties:
76+
Name: !Ref EksClusterName
77+
Version: "1.14"
78+
RoleArn: !GetAtt EksServiceRole.Arn
79+
ResourcesVpcConfig:
80+
SecurityGroupIds:
81+
- !Ref ControlPlaneSecurityGroup
82+
SubnetIds:
83+
- !Ref SpinnakerPublicSubnet1
84+
- !Ref SpinnakerPublicSubnet2
85+
86+
# Creates Instance Profile to be used by any APP created by Spinnaker. Spinnaker has passRole access only to this instance Profile
87+
BaseInstanceProfile:
88+
DependsOn: SpinnakerAuthRole
89+
Condition: CreateEc2Role
90+
Properties:
91+
InstanceProfileName: BaseInstanceProfile
92+
Path: /
93+
Roles:
94+
- !Ref BaseIAMRole
95+
Type: AWS::IAM::InstanceProfile
96+
97+
# Creates EC2 Role and Instance Profile with which Spinnaker Runs
98+
SpinnakerInstanceProfile:
99+
DependsOn: SpinnakerAuthRole
100+
Condition: CreateEc2Role
101+
Properties:
102+
Path: /
103+
Roles:
104+
- !Ref "SpinnakerAuthRole"
105+
Type: AWS::IAM::InstanceProfile
106+
SpinnakerAuthRole:
107+
Properties:
108+
RoleName: SpinnakerAuthRole
109+
AssumeRolePolicyDocument:
110+
Statement:
111+
- Action:
112+
- sts:AssumeRole
113+
Effect: Allow
114+
Principal:
115+
Service:
116+
- ec2.amazonaws.com
117+
Version: "2012-10-17"
118+
ManagedPolicyArns:
119+
- arn:aws:iam::aws:policy/PowerUserAccess
120+
- !If [
121+
SupportEKS,
122+
"arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy",
123+
!Ref "AWS::NoValue",
124+
]
125+
- !If [
126+
SupportEKS,
127+
"arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy",
128+
!Ref "AWS::NoValue",
129+
]
130+
- !If [
131+
SupportEKS,
132+
"arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly",
133+
!Ref "AWS::NoValue",
134+
]
135+
Type: AWS::IAM::Role
136+
Condition: CreateEc2Role
137+
138+
# Creates IAM user and AccessKeys
139+
SpinnakerUser:
140+
Description: User identity Spinnaker uses to create AWS resources
141+
Properties:
142+
ManagedPolicyArns:
143+
- arn:aws:iam::aws:policy/PowerUserAccess
144+
Type: AWS::IAM::User
145+
Condition: CreateAccessKeys
146+
SpinnakerAccessKey:
147+
DependsOn: SpinnakerUser
148+
Condition: CreateAccessKeys
149+
Description: Generate AccessKey for Spinnaker
150+
Properties:
151+
UserName: !Ref "SpinnakerUser"
152+
Type: AWS::IAM::AccessKey
153+
SpinnakerAccessKeyCredentials:
154+
DependsOn: SpinnakerAccessKey
155+
Condition: CreateAccessKeys
156+
Description: Store the access key credentials for Spinnaker in a secure location
157+
Type: AWS::SecretsManager::Secret
158+
Properties:
159+
Description: Spinnaker user access key credentials
160+
SecretString: !Sub |
161+
{
162+
"AccessKeyId":"${SpinnakerAccessKey}",
163+
"SecretAccessKey":"${SpinnakerAccessKey.SecretAccessKey}"
164+
}
165+
166+
# Either Keys or Instances
167+
168+
SpinnakerAssumeRolePolicy:
169+
Type: AWS::IAM::Policy
170+
Properties:
171+
Users:
172+
- !If [CreateAccessKeys, !Ref SpinnakerUser, !Ref "AWS::NoValue"]
173+
Roles:
174+
- !If [CreateEc2Role, !Ref SpinnakerAuthRole, !Ref "AWS::NoValue"]
175+
PolicyDocument:
176+
Version: "2012-10-17"
177+
Statement:
178+
- Action: sts:AssumeRole
179+
Effect: Allow
180+
Resource:
181+
- !Sub arn:aws:iam::${AWS::AccountId}:role/spinnakerManaged # This is the current account
182+
#- arn:aws:iam::YOUR_MANAGED_ACCOUNT1:role/spinnakerManaged # Keep Adding Managed Accounts like this
183+
PolicyName: SpinnakerAssumeRolePolicy
184+
185+
# Creates a single subnet VPC
186+
SpinnakerVPC:
187+
Type: AWS::EC2::VPC
188+
Properties:
189+
CidrBlock: !Ref "SpinnakerVPCCIDR"
190+
EnableDnsSupport: "true"
191+
EnableDnsHostnames: "true"
192+
Tags:
193+
- Key: VPC
194+
Value: Spinnaker VPC
195+
- Key: Name
196+
Value: SpinnakerVPC
197+
SpinnakerInternetGateway:
198+
Type: AWS::EC2::InternetGateway
199+
SpinnakerAttachGateway:
200+
Type: AWS::EC2::VPCGatewayAttachment
201+
Properties:
202+
VpcId: !Ref "SpinnakerVPC"
203+
InternetGatewayId: !Ref "SpinnakerInternetGateway"
204+
SpinnakerPublicSubnet1:
205+
Type: AWS::EC2::Subnet
206+
Properties:
207+
VpcId: !Ref "SpinnakerVPC"
208+
CidrBlock: !Ref SpinnakerPublicSubnet1CIDR
209+
AvailabilityZone: !Select
210+
- "0"
211+
- !GetAZs ""
212+
Tags:
213+
- Key: Name
214+
Value: !Sub SpinnakerVPC.external.${AWS::Region}a
215+
- Key: immutable_metadata # If you cannot name the VPC as done above, use this tag
216+
Value: !Sub |
217+
{"purpose": "public-subnet"}
218+
SpinnakerPublicSubnet2:
219+
Type: AWS::EC2::Subnet
220+
Properties:
221+
VpcId: !Ref "SpinnakerVPC"
222+
CidrBlock: !Ref SpinnakerPublicSubnet2CIDR
223+
AvailabilityZone: !Select
224+
- "1"
225+
- !GetAZs ""
226+
Tags:
227+
- Key: Name
228+
Value: !Sub SpinnakerVPC.external.${AWS::Region}b
229+
- Key: immutable_metadata
230+
Value: !Sub |
231+
{"purpose": "public-subnet"}
232+
SpinnakerPublicRouteTable:
233+
Type: AWS::EC2::RouteTable
234+
DependsOn:
235+
- SpinnakerVPC
236+
- SpinnakerAttachGateway
237+
Properties:
238+
VpcId: !Ref "SpinnakerVPC"
239+
Tags:
240+
- Key: Name
241+
Value: Spinnaker Public Route Table
242+
SpinnakerPublicRoute:
243+
Type: AWS::EC2::Route
244+
Properties:
245+
RouteTableId: !Ref "SpinnakerPublicRouteTable"
246+
DestinationCidrBlock: "0.0.0.0/0"
247+
GatewayId: !Ref "SpinnakerInternetGateway"
248+
SpinnakerPublicSubnet1RouteTableAssociation:
249+
Type: AWS::EC2::SubnetRouteTableAssociation
250+
Properties:
251+
SubnetId: !Ref SpinnakerPublicSubnet1
252+
RouteTableId: !Ref "SpinnakerPublicRouteTable"
253+
SpinnakerPublicSubnet2RouteTableAssociation:
254+
Type: AWS::EC2::SubnetRouteTableAssociation
255+
Properties:
256+
SubnetId: !Ref SpinnakerPublicSubnet2
257+
RouteTableId: !Ref "SpinnakerPublicRouteTable"
258+
259+
ControlPlaneSecurityGroup:
260+
Type: AWS::EC2::SecurityGroup
261+
Condition: SupportEKS
262+
Properties:
263+
GroupDescription: Cluster communication with worker nodes
264+
VpcId: !Ref SpinnakerVPC
265+
266+
Outputs:
267+
SpinnakerUserSecret:
268+
Condition: CreateAccessKeys
269+
Value: !Ref SpinnakerAccessKeyCredentials
270+
ManagingAccountId:
271+
Value: !Ref AWS::AccountId
272+
AuthArn:
273+
Value:
274+
!If [
275+
CreateAccessKeys,
276+
!GetAtt SpinnakerUser.Arn,
277+
!GetAtt SpinnakerAuthRole.Arn,
278+
]
279+
EksClusterEndpoint:
280+
Condition: SupportEKS
281+
Value: !GetAtt EksCluster.Endpoint
282+
EksClusterCA:
283+
Condition: SupportEKS
284+
Value: !GetAtt EksCluster.CertificateAuthorityData
285+
SubnetIds:
286+
Description: All subnets in the VPC
287+
Value:
288+
!Join [",", [!Ref SpinnakerPublicSubnet1, !Ref SpinnakerPublicSubnet2]]
289+
EksClusterName:
290+
Condition: SupportEKS
291+
Value: !Ref EksClusterName
292+
293+
SpinnakerInstanceProfileArn:
294+
Condition: CreateEc2Role
295+
Value: !GetAtt SpinnakerInstanceProfile.Arn
296+
297+
VpcId:
298+
Value: !Ref SpinnakerVPC
299+
300+
SecurityGroups:
301+
Condition: SupportEKS
302+
Description: Security group for the cluster control plane communication with worker nodes
303+
Value: !Join [",", [!Ref ControlPlaneSecurityGroup]]

0 commit comments

Comments
 (0)