This repository has been archived by the owner on Jun 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcloudformation.yaml
187 lines (184 loc) · 5.27 KB
/
cloudformation.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
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
VpcId:
Type: AWS::EC2::VPC::Id
Description: VpcId of your existing Virtual Private Cloud (VPC)
GuardianIpRange:
Type: String
Description: Ip range for the office
Default: 77.91.248.0/21
InstanceType:
Type: String
Description: AWS instance type for the autoscaling group.
Default: t3.micro
App:
Type: String
Description: Name of the app
Stack:
Type: String
Description: Name of the stack
Stage:
Type: String
Description: Name of the stage
AllowedValues:
- CODE
- PROD
ImageId:
Type: String
Description: AMI ID
PrivateSubnets:
Type: List<AWS::EC2::Subnet::Id>
Description: The list of SubnetIds in your Virtual Private Cloud (VPC)
KeyName:
Type: AWS::EC2::KeyPair::KeyName
Description: Name of an existing key pair, which will be given root access to
the instances
ELKKinesisStream:
Type: String
Description: Name of the kinesis stream for logging to ELK (logs.gutools)
Mappings:
Config:
IpRange:
CODE: 77.91.248.0/21
PROD: 0.0.0.0/0
MaxSize:
CODE: 2
PROD: 2
MinSize:
CODE: 1
PROD: 1
Resources:
LaunchConfig:
Type: AWS::AutoScaling::LaunchConfiguration
Properties:
IamInstanceProfile: !Sub ${InstanceProfile.Arn}
ImageId: !Ref ImageId
InstanceType: !Ref InstanceType
KeyName: !Ref KeyName
AssociatePublicIpAddress: true
SecurityGroups:
- Ref: SSHSecurityGroup
UserData:
Fn::Base64:
!Sub |
#!/bin/bash -ev
aws s3 cp s3://capi-wpt-querybot/capi-wpt-querybot.conf /etc/gu/capi-wpt-querybot.conf
aws s3 cp s3://aws-frontend-artifacts/frontend/${Stage}/${App}/${App}_1.0_all.deb /tmp
dpkg -i /tmp/${App}_1.0_all.deb
echo "#!/bin/bash" > /etc/cron.hourly/wptcron
echo "curl localhost:9000/run > /dev/null" >> /etc/cron.hourly/wptcron
chmod +x /etc/cron.hourly/wptcron
SSMRunCommandPolicy:
Type: AWS::IAM::Policy
Properties:
PolicyName: ssm-run-command-policy
PolicyDocument:
Statement:
# minimal policy to allow running commands via ssm
- Effect: Allow
Resource: "*"
Action:
- ec2messages:AcknowledgeMessage
- ec2messages:DeleteMessage
- ec2messages:FailMessage
- ec2messages:GetEndpoint
- ec2messages:GetMessages
- ec2messages:SendReply
- ssm:UpdateInstanceInformation
- ssm:ListInstanceAssociations
- ssm:DescribeInstanceProperties
- ssm:DescribeDocumentParameters
Roles:
- !Ref Role
SSHSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Allow SSH access from the office
VpcId: !Ref VpcId
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp: '10.0.0.0/8'
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp: !Ref GuardianIpRange
AutoScalingGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
VPCZoneIdentifier: !Ref PrivateSubnets
Cooldown: '300'
MaxSize: !FindInMap [ Config, MaxSize, !Ref Stage ]
MinSize: !FindInMap [ Config, MinSize, !Ref Stage ]
HealthCheckGracePeriod: 300
HealthCheckType: ELB
LaunchConfigurationName:
Ref: LaunchConfig
Tags:
- Key: App
Value: !Ref App
PropagateAtLaunch: true
- Key: Stack
Value: !Ref Stack
PropagateAtLaunch: true
- Key: Stage
Value: !Ref Stage
PropagateAtLaunch: true
Role:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
-
Effect: Allow
Principal:
Service: ec2.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: S3ArtifactPolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- s3:GetObject
Resource:
- !Sub arn:aws:s3:::aws-frontend-artifacts/*
- PolicyName: capiwptbucketpolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- s3:GetObject
- s3:GetObjectAcl
- s3:PutObject
- s3:PutObjectAcl
Resource:
- !Sub arn:aws:s3:::capi-wpt-querybot/*
- PolicyName: ELKKinesisPolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- kinesis:PutRecord
- kinesis:DescribeStream
Resource: !Sub arn:aws:kinesis:eu-west-1:642631414762:stream/${ELKKinesisStream}
- PolicyName: DescribeEC2Policy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- EC2:Describe*
Resource: '*'
Path: /
InstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Path: /
Roles:
- Ref: Role