-
Notifications
You must be signed in to change notification settings - Fork 0
/
run
281 lines (256 loc) · 8.16 KB
/
run
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
276
277
278
279
280
281
AWSTemplateFormatVersion: 2010-09-09
Description: |
**A single CloudFormation file** that deletes all resources in the running AWS account.
It uses aws-nuke by rebuy-de (https://github.com/rebuy-de/aws-nuke) binary for nuking your account.
Parameters:
LatestAmiId:
Type: 'AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>'
Default: '/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2'
Resources:
WorkerVPC:
Type: AWS::EC2::VPC
DependsOn:
- WorkerRole
Properties:
CidrBlock: 10.0.0.0/16
EnableDnsSupport: true
EnableDnsHostnames: true
Tags:
- Key: Name
Value: nukeme-vpc
WorkerIGW:
Type: AWS::EC2::InternetGateway
DependsOn:
- WorkerRole
Properties:
Tags:
- Key: Name
Value: nukeme-igw
InternetGatewayAttachment:
Type: AWS::EC2::VPCGatewayAttachment
DependsOn:
- WorkerRole
Properties:
InternetGatewayId: !Ref WorkerIGW
VpcId: !Ref WorkerVPC
WorkerRouteTable:
Type: AWS::EC2::RouteTable
DependsOn:
- WorkerRole
Properties:
VpcId: !Ref WorkerVPC
Tags:
- Key: Name
Value: nukeme-rtb-public
DefaultWorkerRoute:
Type: AWS::EC2::Route
DependsOn:
- WorkerRole
- InternetGatewayAttachment
Properties:
RouteTableId: !Ref WorkerRouteTable
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref WorkerIGW
WorkerSubnetRouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
DependsOn:
- WorkerRole
Properties:
RouteTableId: !Ref WorkerRouteTable
SubnetId: !Ref WorkerSubnet
WorkerSubnet:
Type: AWS::EC2::Subnet
DependsOn:
- WorkerRole
Properties:
VpcId: !Ref WorkerVPC
AvailabilityZone: !Select [ 0, !GetAZs '' ]
CidrBlock: 10.0.0.0/24
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value: nukeme-subnet-public-a
WorkerSecurityGroup:
Type: AWS::EC2::SecurityGroup
DependsOn:
- WorkerRole
Properties:
GroupName: nukeme-sg
GroupDescription: "Allow nukeme worker to connect aws api endpoints"
VpcId: !Ref WorkerVPC
SecurityGroupEgress:
- IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: 0.0.0.0/0
Tags:
- Key: Name
Value: nukeme-sg-worker
WorkerRole:
Type: 'AWS::IAM::Role'
Properties:
RoleName: nukeme-role-worker
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service:
- ec2.amazonaws.com
Action:
- 'sts:AssumeRole'
Path: /
Policies:
- PolicyName: nukeme-policy-admin
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action: '*'
Resource: '*'
WorkerInstanceProfile:
Type: 'AWS::IAM::InstanceProfile'
DependsOn:
- WorkerRole
Properties:
Path: /
InstanceProfileName: nukeme-role-worker
Roles:
- !Ref WorkerRole
WorkerLogGroup:
Type: AWS::Logs::LogGroup
DependsOn:
- WorkerRole
Properties:
LogGroupName: nukeme-log
RetentionInDays: 1
WorkerLogStream:
Type: AWS::Logs::LogStream
DependsOn:
- WorkerRole
Properties:
LogGroupName: !Ref WorkerLogGroup
LogStreamName: nukeme-worker-log
WorkerInstance:
Type: AWS::EC2::Instance
DependsOn:
- WorkerRole
Properties:
ImageId: !Ref LatestAmiId
InstanceType: t3.micro
IamInstanceProfile: !Ref WorkerInstanceProfile
PropagateTagsToVolumeOnCreation: true
NetworkInterfaces:
- AssociatePublicIpAddress: "true"
DeviceIndex: "0"
GroupSet:
- !Ref WorkerSecurityGroup
SubnetId:
!Ref WorkerSubnet
UserData:
Fn::Base64: !Sub
- |
#!/bin/sh
yum install -y amazon-cloudwatch-agent
mkdir -p /opt/aws/amazon-cloudwatch-agent/etc
cat <<EOF > /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json
{
"agent": {
"run_as_user": "root"
},
"logs": {
"logs_collected": {
"files": {
"collect_list": [
{
"file_path": "/var/log/cloud-init-output.log",
"log_group_name": "nukeme-log",
"log_stream_name": "nukeme-worker-log",
"retention_in_days": 1
}
]
}
}
},
"metrics": {
"metrics_collected": {
"collectd": {
"metrics_aggregation_interval": 60
}
}
}
}
EOF
mkdir -p /usr/share/collectd
touch /usr/share/collectd/types.db
systemctl enable --now amazon-cloudwatch-agent.service
wget https://github.com/rebuy-de/aws-nuke/releases/download/v2.25.0/aws-nuke-v2.25.0-linux-amd64.tar.gz
tar xvf aws-nuke-v2.25.0-linux-amd64.tar.gz
chmod +x aws-nuke-v2.25.0-linux-amd64
cat <<EOF > config.yaml
regions:
- global
- ${AWS::Region}
account-blocklist:
- "999999999999"
resource-types:
excludes:
- EC2DHCPOption
accounts:
"${AWS::AccountId}":
filters:
CloudFormationStack:
- "${AWS::StackName}"
EC2VPC:
- property: tag:Name
value: nukeme-vpc
EC2InternetGateway:
- property: tag:Name
value: nukeme-igw
EC2InternetGatewayAttachment:
- property: tag:igw:Name
value: nukeme-igw
EC2RouteTable:
- property: tag:Name
value: nukeme-rtb-public
EC2Subnet:
- property: tag:Name
value: nukeme-subnet-public-a
EC2SecurityGroup:
- property: tag:Name
value: nukeme-sg-worker
IAMRole:
- "nukeme-role-worker"
IAMRolePolicy:
- "nukeme-role-worker -> nukeme-policy-admin"
IAMInstanceProfile:
- "nukeme-role-worker"
IAMInstanceProfileRole:
- "nukeme-role-worker -> nukeme-role-worker"
CloudWatchLogsLogGroup:
- "nukeme-log"
EC2Instance:
- property: tag:Name
value: nukeme-worker
EC2Volume:
- property: tag:Name
value: "nukeme-worker"
EC2NetworkInterface:
- property: VPC
value: ${Vpc}
EOF
./aws-nuke-v2.25.0-linux-amd64 -c config.yaml --force-sleep 3 --force --no-dry-run
echo "☢️ Nuking finished. If you have any problems: https://github.com/cloudshit/nukeme/issues/new"
sleep 10
aws cloudformation delete-stack --stack-name "${AWS::StackName}" --region ${AWS::Region}
- Vpc: !Ref WorkerVPC
Tags:
- Key: Name
Value: nukeme-worker
Outputs:
Monitoring:
Description: Monitor aws-nuke with Cloudwatch Live Tail service.
Value: !Sub "https://${AWS::Region}.console.aws.amazon.com/cloudwatch/home?region=${AWS::Region}#logsV2:live-tail$3FlogGroupArns$3D~(~'arn*3aaws*3alogs*3a${AWS::Region}*3a${AWS::AccountId}*3alog-group*3anukeme-log*3a*2a)$26logStreamNames$3D~(~'nukeme-worker-log)"
Notice:
Description: Notice
Value: DO NOT delete this CloudFormation stack manually. this will automatically destroy itself when finished.