forked from collinjlesko/dynatrace-monitoring-as-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DynatraceMonitoringAsAServiceCFStack.json
441 lines (437 loc) · 19.1 KB
/
DynatraceMonitoringAsAServiceCFStack.json
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Dynatrace ACM Monitoring as a Service Workshop: https://github.com/dynatrace-innovationlab/dynatrace-monitoring-as-service",
"Parameters": {
"TutorialGitHubLink" : {
"Description" : "The link to your cloned version of https://github.com/dynatrace-innovationlab/dynatrace-monitoring-as-service.git",
"Type" : "String",
"Default" : "https://github.com/dynatrace-innovationlab/dynatrace-monitoring-as-service.git"
},
"DownloadDTMaaSGitHubRepo": {
"Description": "Step 0: Download dynatrace-monitoring-as-service GitHub repo (only works once public)",
"Type": "String",
"Default": "yes",
"AllowedValues": [
"yes",
"no"
]
},
"UseDynatraceOneAgent": {
"Description": "Step 1 for Monitoring as a Service: Shall we install the OneAgent?",
"Type": "String",
"Default": "no",
"AllowedValues": [
"yes",
"no"
]
},
"InstallDynatraceCLI": {
"Description": "Step 2 for Monitoring as a Service: Download & Build Dynatrace CLI Container?",
"Type": "String",
"Default": "no",
"AllowedValues": [
"yes",
"no"
]
},
"DynatraceTenantURL": {
"Description": "Your full Dynatrace Tenant URL. For SaaS it is e.g: https://<YOURTENANTID>.live.dynatrace.com. For Managed something like https://yourserver/e/abcdefgh-1234-5678-abcd-55a7265f572f",
"Type": "String",
"AllowedPattern" : "https:\/\/.*",
"Default": "https://<YOURTENENTID>.live.dynatrace.com"
},
"DynatraceAPIToken": {
"Description": "Your Dynatrace API Token. If you dont have one create one first in your Dynatrace Web UI via Settings -> Integration -> Dynatrace API",
"Type": "String",
"MinLength" : "21",
"Default" : "ABCDEFGHIJKLMNOPQRSTU"
},
"DynatraceOneAgentURL": {
"Description": "Full Download Script URL. Go to Deploy Dynatrace -> Start Installation -> Linux and copy JUST the URL in the wget command and PASTE it here",
"Type": "String",
"AllowedPattern" : "https:\/\/.*",
"Default": "https://<YOURTENENTID>.live.dynatrace.com/api/v1/deployment/XXXXXXXXXXXXXXXXXXXXXXXXX"
},
"DynatraceCustomHostTags" : {
"Description": "Allows you to specify any number of tags that will be added to the hostautotag.conf file during installation, e.g: MyTag MyEnv=Staging",
"Type": "String",
"Default" : "Environment=Development DTMaaSHostTag CreatedBy=TeamDev1"
},
"DynatraceCustomHostProperties" : {
"Description" : "Allows you to specify a custom property that will be added to the hostcustomproperties.conf during installation",
"Type": "String",
"Default" : "Environment=Development"
},
"KeyName": {
"Description": "Name of Existing EC2 Key Pair which we will use to launch new EC2 Instances",
"Type": "AWS::EC2::KeyPair::KeyName",
"ConstraintDescription": "Must be the name of an existing Key Pair",
"MinLength" : "1",
"MaxLength" : "255"
},
"InstanceType": {
"Description": "Instance Types for the EC2 Instance we create",
"Type": "String",
"Default": "t2.small",
"AllowedValues": [
"t2.micro",
"t2.small",
"t2.medium"
]
}
},
"Metadata": {
"AWS::CloudFormation::Interface": {
"ParameterGroups": [
{
"Label": { "default": "Workshop Automation Steps"},
"Parameters": [ "DownloadDTMaaSGitHubRepo", "TutorialGitHubLink", "UseDynatraceOneAgent", "InstallDynatraceCLI" ]
},
{
"Label": { "default": "Dynatrace"},
"Parameters": [ "DynatraceTenantURL", "DynatraceAPIToken", "DynatraceOneAgentURL", "DynatraceCustomHostTags", "DynatraceCustomHostProperties" ]
},
{
"Label": {"default": "Deployment"},
"Parameters": ["InstanceType", "KeyName"]
}
]
}
},
"Conditions": {
"InstallOneAgent" : {"Fn::Equals" : [{"Ref" : "UseDynatraceOneAgent"}, "yes"]},
"InstallDTCLI" : {"Fn::Equals" : [{"Ref" : "InstallDynatraceCLI"}, "yes"]},
"DownloadTutorialGitHub" : {"Fn::Equals" : [{"Ref" : "DownloadDTMaaSGitHubRepo"}, "yes"]}
},
"Mappings": {
"RegionMap": {
"us-east-1": {
"AMI": "ami-97785bed"
},
"us-east-2": {
"AMI": "ami-f63b1193"
},
"us-west-1": {
"AMI": "ami-824c4ee2"
},
"us-west-2": {
"AMI": "ami-f2d3638a"
},
"ca-central-1" : {
"AMI" : "ami-a954d1cd"
},
"eu-central-1" : {
"AMI": "ami-5652ce39"
},
"eu-west-1" : {
"AMI" : "ami-d834aba1"
},
"eu-west-2" : {
"AMI" : "ami-403e2524"
},
"eu-west-3" : {
"AMI" : "ami-8ee056f3"
},
"ap-south-1" : {
"AMI" : "ami-531a4c3c"
},
"ap-northeast-2" : {
"AMI" : "ami-863090e8"
},
"ap-southeast-1" : {
"AMI" : "ami-68097514"
},
"ap-southeast-2" : {
"AMI" : "ami-942dd1f6"
},
"ap-northeast-1" : {
"AMI" : "ami-ceafcba8"
},
"sa-east-1" : {
"AMI" : "ami-84175ae8"
}
}
},
"Resources": {
"DynatraceEC2InstanceProfile": {
"Type": "AWS::IAM::InstanceProfile",
"Properties": {
"InstanceProfileName": {
"Fn::Join" : [
"",
[
"ACM_MAAS_DT_EC2ProfileName_",
{
"Ref": "AWS::StackName"
}
]
]
},
"Path": "/",
"Roles": [
{
"Ref": "DynatraceEC2InstanceProfileRole"
}
]
}
},
"DynatraceEC2InstanceProfileRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"RoleName": {
"Fn::Join" : [
"",
[
"ACM_MAAS_DT_EC2ProfileRoleName_",
{
"Ref": "AWS::StackName"
}
]
]
},
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "ec2.amazonaws.com"
}
}
]
},
"Path": "/",
"Policies": [
{
"PolicyName": "DynatraceEC2CodeDeployInstanceProfilePolicy",
"PolicyDocument": {
"Statement": [
{
"Action": [
"s3:Get*",
"s3:List*"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
}
]
}
},
"SecurityGroup": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupDescription": "Enable HTTP access via port 80 and SSH access.",
"GroupName": {
"Fn::Join" : [
"",
[
"ACM_MAAS_DT_EC2SecrutiyGroupName_",
{
"Ref": "AWS::StackName"
}
]
]
},
"SecurityGroupIngress": [
{
"IpProtocol": "tcp",
"FromPort": "80",
"ToPort": "80",
"CidrIp": "0.0.0.0/0"
},
{
"IpProtocol": "tcp",
"FromPort": "22",
"ToPort": "22",
"CidrIp": "0.0.0.0/0"
}
]
}
},
"ACMDTMaaSInstance": {
"Type": "AWS::EC2::Instance",
"Properties": {
"ImageId": {
"Fn::FindInMap": [
"RegionMap",
{
"Ref": "AWS::Region"
},
"AMI"
]
},
"InstanceType": {
"Ref": "InstanceType"
},
"IamInstanceProfile": {
"Ref": "DynatraceEC2InstanceProfile"
},
"KeyName": {
"Ref": "KeyName"
},
"SecurityGroups": [
{
"Ref": "SecurityGroup"
}
],
"Tags": [
{
"Key": "Name",
"Value": {
"Fn::Join" : [
"",
[
"ACM_MAAS_DT_",
{
"Ref": "AWS::StackName"
}
]
]
}
}
],
"UserData": {
"Fn::Base64": {
"Fn::Join": [
"",
[
"#!/bin/bash -x\n",
"# First: we download and install the Dynatrace OneAgent\n",
"yum update -y\n",
{
"Fn::If" : [
"InstallOneAgent",
{
"Fn::Join" : [
"",
[
"yum install ruby wget -y\n",
"cd /\n",
"wget --no-check-certificate -O Dynatrace-OneAgent-Linux.sh \"",
{
"Ref": "DynatraceOneAgentURL"
},
"\"\n",
"echo 'Ready to install & configure tags for OneAgent:'\n",
"mkdir -p /var/lib/dynatrace/oneagent/agent/config\n",
"cd /var/lib/dynatrace/oneagent/agent/config\n",
"echo \"StackName=",
{
"Ref" : "AWS::StackName"
},
" ",
{
"Ref" : "DynatraceCustomHostTags"
},
"\" > hostautotag.conf\n",
"cd /\n",
"sudo /bin/sh Dynatrace-OneAgent-Linux.sh APP_LOG_CONTENT_ACCESS=1\n",
"cd /var/lib/dynatrace/oneagent/agent/config\n",
"echo \"",
{
"Ref" : "DynatraceCustomHostProperties"
},
"\" > hostcustomproperties.conf\n",
"cd /home/ec2-user\n",
"echo \"export ",
{
"Ref" : "DynatraceCustomHostProperties"
},
"\" > setenv.sh\n",
"chmod +x setenv.sh\n",
"source setenv.sh\n"
]
]
},
"# NO OneAgent to Install!!"
]},
"\n",
"# Second: We install required components such as docker, git ...\n",
"yum install -y docker\n",
"service docker start\n",
"yum install -y git\n",
"# Third: we get our Dynatrace CLI Project and build the docker container\n",
{
"Fn::If" : [
"InstallDTCLI",
{
"Fn::Join" : [
"",
[
"cd /home/ec2-user\n",
"sudo runuser -l ec2-user -c 'git clone https://github.com/Dynatrace/dynatrace-cli.git'\n",
"cd dynatrace-cli\n",
"bash ./docker_build.sh\n"
]
]
},
"# NO DT CLI to Install!!"
]},
"# Fourth: We can get our Monitoring as a Service GitHub Repo\n",
{
"Fn::If" : [
"DownloadTutorialGitHub",
{
"Fn::Join" :
["",
[
"cd /home/ec2-user\n",
"sudo runuser -l ec2-user -c 'git clone ",
{
"Ref" : "TutorialGitHubLink"
},
" dynatrace-monitoring-as-service'\n",
"cd dynatrace-monitoring-as-service\n",
"bash ./build.sh\n",
"sudo runuser -l ec2-user -c 'echo \"{\\\"cacheupdate\\\" : \\\"5\\\", \\\"apitoken\\\" : \\\"",
{
"Ref" : "DynatraceAPIToken"
},
"\\\", \\\"tenanthost\\\" : \\\"",
{
"Ref" : "DynatraceTenantURL"
},
"\\\"}\" > ./dynatrace-monitoring-as-service/dtconfig.json'\n"
]
]
},
"# No GitHub Tutorial Download!"
]
},
"# Last: Get the latest CloudFormation package",
"yum update -y aws-cfn-bootstrap",
"# Start cfn-init",
"/opt/aws/bin/cfn-init -s ${AWS::StackId} -r ProductionInstance --region ${AWS::Region} || error_exit 'Failed to run cfn-init'",
"# Start up the cfn-hup daemon to listen for changes to the EC2 instance metadata",
"/opt/aws/bin/cfn-hup || error_exit 'Failed to start cfn-hup'",
"# All done so signal success",
"/opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackId} --resource StagingInstance --region ${AWS::Region}"
]
]
}
}
}
}
},
"Outputs": {
"MyStackRegion": {
"Value": {
"Ref": "AWS::Region"
},
"Description": "The region where the stack was created."
},
"TutorialInstance": {
"Value": {
"Fn::GetAtt": [
"ACMDTMaaSInstance",
"PublicDnsName"
]
},
"Description": "The Public DNS of your ACMDTMaaSInstance System"
}
}
}