-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.yaml
More file actions
807 lines (784 loc) · 29.6 KB
/
template.yaml
File metadata and controls
807 lines (784 loc) · 29.6 KB
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
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
Resources:
SonarQubeSG6C05C623:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Aurora Security Group
SecurityGroupEgress:
- CidrIp: 0.0.0.0/0
Description: Allow all outbound traffic by default
IpProtocol: "-1"
SecurityGroupIngress:
- CidrIp: 0.0.0.0/0
Description: SonarDBAurora
FromPort: 5432
IpProtocol: tcp
ToPort: 5432
VpcId: vpc-0a80e435cc7a23539
Metadata:
aws:cdk:path: CdkPythoncStack/SonarQubeSG/Resource
SonarDBClusterSubnetsAB5EA67D:
Type: AWS::RDS::DBSubnetGroup
Properties:
DBSubnetGroupDescription: Subnets for SonarDBCluster database
SubnetIds:
- subnet-0a7a0a3d8744f386f
- subnet-080a99253fa7f5a12
Metadata:
aws:cdk:path: CdkPythoncStack/SonarDBCluster/Subnets/Default
SonarDBClusterSecret8F820211:
Type: AWS::SecretsManager::Secret
Properties:
Description:
Fn::Join:
- ""
- - "Generated by the CDK for stack: "
- Ref: AWS::StackName
GenerateSecretString:
ExcludeCharacters: " %+~`#$&*()|[]{}:;<>?!'/@\"\\"
GenerateStringKey: password
PasswordLength: 30
SecretStringTemplate: '{"username":"postgres"}'
UpdateReplacePolicy: Delete
DeletionPolicy: Delete
Metadata:
aws:cdk:path: CdkPythoncStack/SonarDBCluster/Secret/Resource
SonarDBClusterSecretAttachment74FE44D9:
Type: AWS::SecretsManager::SecretTargetAttachment
Properties:
SecretId:
Ref: SonarDBClusterSecret8F820211
TargetId:
Ref: SonarDBClusterE2562227
TargetType: AWS::RDS::DBCluster
Metadata:
aws:cdk:path: CdkPythoncStack/SonarDBCluster/Secret/Attachment/Resource
SonarDBClusterE2562227:
Type: AWS::RDS::DBCluster
Properties:
CopyTagsToSnapshot: true
DatabaseName: sonarqube
DBClusterParameterGroupName: default.aurora-postgresql12
DBSubnetGroupName:
Ref: SonarDBClusterSubnetsAB5EA67D
Engine: aurora-postgresql
EngineVersion: "12.9"
MasterUsername:
Fn::Join:
- ""
- - "{{resolve:secretsmanager:"
- Ref: SonarDBClusterSecret8F820211
- :SecretString:username::}}
MasterUserPassword:
Fn::Join:
- ""
- - "{{resolve:secretsmanager:"
- Ref: SonarDBClusterSecret8F820211
- :SecretString:password::}}
Port: 5432
VpcSecurityGroupIds:
- Fn::GetAtt:
- SonarQubeSG6C05C623
- GroupId
UpdateReplacePolicy: Snapshot
DeletionPolicy: Snapshot
Metadata:
aws:cdk:path: CdkPythoncStack/SonarDBCluster/Resource
SonarDBClusterInstance107C65031:
Type: AWS::RDS::DBInstance
Properties:
DBClusterIdentifier:
Ref: SonarDBClusterE2562227
DBInstanceClass: db.t3.medium
DBSubnetGroupName:
Ref: SonarDBClusterSubnetsAB5EA67D
Engine: aurora-postgresql
UpdateReplacePolicy: Delete
DeletionPolicy: Delete
Metadata:
aws:cdk:path: CdkPythoncStack/SonarDBCluster/Instance1
SonarDBClusterInstance29E32FBB9:
Type: AWS::RDS::DBInstance
Properties:
DBClusterIdentifier:
Ref: SonarDBClusterE2562227
DBInstanceClass: db.t3.medium
DBSubnetGroupName:
Ref: SonarDBClusterSubnetsAB5EA67D
Engine: aurora-postgresql
UpdateReplacePolicy: Delete
DeletionPolicy: Delete
Metadata:
aws:cdk:path: CdkPythoncStack/SonarDBCluster/Instance2
SonarCluster26427412:
Type: AWS::ECS::Cluster
Metadata:
aws:cdk:path: CdkPythoncStack/SonarCluster/Resource
SonarClusterDefaultAutoScalingGroupInstanceSecurityGroup5A14A3BB:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: CdkPythoncStack/SonarCluster/DefaultAutoScalingGroup/InstanceSecurityGroup
SecurityGroupEgress:
- CidrIp: 0.0.0.0/0
Description: Allow all outbound traffic by default
IpProtocol: "-1"
Tags:
- Key: Name
Value: CdkPythoncStack/SonarCluster/DefaultAutoScalingGroup
VpcId: vpc-0a80e435cc7a23539
Metadata:
aws:cdk:path: CdkPythoncStack/SonarCluster/DefaultAutoScalingGroup/InstanceSecurityGroup/Resource
SonarClusterDefaultAutoScalingGroupInstanceSecurityGroupfromCdkPythoncStackSonarServiceLBSecurityGroupDFB0343F3276865535ECA716E1:
Type: AWS::EC2::SecurityGroupIngress
Properties:
IpProtocol: tcp
Description: Load balancer to target
FromPort: 32768
GroupId:
Fn::GetAtt:
- SonarClusterDefaultAutoScalingGroupInstanceSecurityGroup5A14A3BB
- GroupId
SourceSecurityGroupId:
Fn::GetAtt:
- SonarServiceLBSecurityGroup155666B5
- GroupId
ToPort: 65535
Metadata:
aws:cdk:path: CdkPythoncStack/SonarCluster/DefaultAutoScalingGroup/InstanceSecurityGroup/from CdkPythoncStackSonarServiceLBSecurityGroupDFB0343F:32768-65535
SonarClusterDefaultAutoScalingGroupInstanceRole1E491345:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
Service: ec2.amazonaws.com
Version: "2012-10-17"
Tags:
- Key: Name
Value: CdkPythoncStack/SonarCluster/DefaultAutoScalingGroup
Metadata:
aws:cdk:path: CdkPythoncStack/SonarCluster/DefaultAutoScalingGroup/InstanceRole/Resource
SonarClusterDefaultAutoScalingGroupInstanceRoleDefaultPolicy2210237C:
Type: AWS::IAM::Policy
Properties:
PolicyDocument:
Statement:
- Action:
- ecs:DeregisterContainerInstance
- ecs:RegisterContainerInstance
- ecs:Submit*
Effect: Allow
Resource:
Fn::GetAtt:
- SonarCluster26427412
- Arn
- Action:
- ecs:Poll
- ecs:StartTelemetrySession
Condition:
ArnEquals:
ecs:cluster:
Fn::GetAtt:
- SonarCluster26427412
- Arn
Effect: Allow
Resource: "*"
- Action:
- ecr:GetAuthorizationToken
- ecs:DiscoverPollEndpoint
- logs:CreateLogStream
- logs:PutLogEvents
Effect: Allow
Resource: "*"
Version: "2012-10-17"
PolicyName: SonarClusterDefaultAutoScalingGroupInstanceRoleDefaultPolicy2210237C
Roles:
- Ref: SonarClusterDefaultAutoScalingGroupInstanceRole1E491345
Metadata:
aws:cdk:path: CdkPythoncStack/SonarCluster/DefaultAutoScalingGroup/InstanceRole/DefaultPolicy/Resource
SonarClusterDefaultAutoScalingGroupInstanceProfileB6433243:
Type: AWS::IAM::InstanceProfile
Properties:
Roles:
- Ref: SonarClusterDefaultAutoScalingGroupInstanceRole1E491345
Metadata:
aws:cdk:path: CdkPythoncStack/SonarCluster/DefaultAutoScalingGroup/InstanceProfile
SonarClusterDefaultAutoScalingGroupLaunchConfig49841B24:
Type: AWS::AutoScaling::LaunchConfiguration
Properties:
ImageId:
Ref: SsmParameterValueawsserviceecsoptimizedamiamazonlinux2recommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter
InstanceType: t3.large
IamInstanceProfile:
Ref: SonarClusterDefaultAutoScalingGroupInstanceProfileB6433243
SecurityGroups:
- Fn::GetAtt:
- SonarClusterDefaultAutoScalingGroupInstanceSecurityGroup5A14A3BB
- GroupId
UserData:
Fn::Base64:
Fn::Join:
- ""
- - |-
#!/bin/bash
echo ECS_CLUSTER=
- Ref: SonarCluster26427412
- |-2
>> /etc/ecs/ecs.config
sudo iptables --insert FORWARD 1 --in-interface docker+ --destination 169.254.169.254/32 --jump DROP
sudo service iptables save
echo ECS_AWSVPC_BLOCK_IMDS=true >> /etc/ecs/ecs.config
sysctl -qw vm.max_map_count=262144
sysctl -w fs.file-max=65536
ulimit -n 65536
ulimit -u 4096
DependsOn:
- SonarClusterDefaultAutoScalingGroupInstanceRoleDefaultPolicy2210237C
- SonarClusterDefaultAutoScalingGroupInstanceRole1E491345
Metadata:
aws:cdk:path: CdkPythoncStack/SonarCluster/DefaultAutoScalingGroup/LaunchConfig
SonarClusterDefaultAutoScalingGroupASG8768A876:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
MaxSize: "1"
MinSize: "1"
LaunchConfigurationName:
Ref: SonarClusterDefaultAutoScalingGroupLaunchConfig49841B24
Tags:
- Key: Name
PropagateAtLaunch: true
Value: CdkPythoncStack/SonarCluster/DefaultAutoScalingGroup
VPCZoneIdentifier:
- subnet-0a7a0a3d8744f386f
- subnet-080a99253fa7f5a12
UpdatePolicy:
AutoScalingReplacingUpdate:
WillReplace: true
AutoScalingScheduledAction:
IgnoreUnmodifiedGroupSizeProperties: true
Metadata:
aws:cdk:path: CdkPythoncStack/SonarCluster/DefaultAutoScalingGroup/ASG
SonarClusterDefaultAutoScalingGroupDrainECSHookFunctionServiceRole486D5691:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
Service: lambda.amazonaws.com
Version: "2012-10-17"
ManagedPolicyArns:
- Fn::Join:
- ""
- - "arn:"
- Ref: AWS::Partition
- :iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
Tags:
- Key: Name
Value: CdkPythoncStack/SonarCluster/DefaultAutoScalingGroup
Metadata:
aws:cdk:path: CdkPythoncStack/SonarCluster/DefaultAutoScalingGroup/DrainECSHook/Function/ServiceRole/Resource
SonarClusterDefaultAutoScalingGroupDrainECSHookFunctionServiceRoleDefaultPolicyB468CFBE:
Type: AWS::IAM::Policy
Properties:
PolicyDocument:
Statement:
- Action:
- ec2:DescribeHosts
- ec2:DescribeInstanceAttribute
- ec2:DescribeInstanceStatus
- ec2:DescribeInstances
Effect: Allow
Resource: "*"
- Action: autoscaling:CompleteLifecycleAction
Effect: Allow
Resource:
Fn::Join:
- ""
- - arn:aws:autoscaling:eu-central-1:838223663339:autoScalingGroup:*:autoScalingGroupName/
- Ref: SonarClusterDefaultAutoScalingGroupASG8768A876
- Action:
- ecs:DescribeContainerInstances
- ecs:DescribeTasks
- ecs:ListTasks
- ecs:UpdateContainerInstancesState
Condition:
ArnEquals:
ecs:cluster:
Fn::GetAtt:
- SonarCluster26427412
- Arn
Effect: Allow
Resource: "*"
- Action:
- ecs:ListContainerInstances
- ecs:SubmitContainerStateChange
- ecs:SubmitTaskStateChange
Effect: Allow
Resource:
Fn::GetAtt:
- SonarCluster26427412
- Arn
Version: "2012-10-17"
PolicyName: SonarClusterDefaultAutoScalingGroupDrainECSHookFunctionServiceRoleDefaultPolicyB468CFBE
Roles:
- Ref: SonarClusterDefaultAutoScalingGroupDrainECSHookFunctionServiceRole486D5691
Metadata:
aws:cdk:path: CdkPythoncStack/SonarCluster/DefaultAutoScalingGroup/DrainECSHook/Function/ServiceRole/DefaultPolicy/Resource
SonarClusterDefaultAutoScalingGroupDrainECSHookFunction3E1C6F0C:
Type: AWS::Lambda::Function
Properties:
Code:
ZipFile: |
import boto3, json, os, time
ecs = boto3.client('ecs')
autoscaling = boto3.client('autoscaling')
def lambda_handler(event, context):
print(json.dumps(dict(event, ResponseURL='...')))
cluster = os.environ['CLUSTER']
snsTopicArn = event['Records'][0]['Sns']['TopicArn']
lifecycle_event = json.loads(event['Records'][0]['Sns']['Message'])
instance_id = lifecycle_event.get('EC2InstanceId')
if not instance_id:
print('Got event without EC2InstanceId: %s', json.dumps(dict(event, ResponseURL='...')))
return
instance_arn = container_instance_arn(cluster, instance_id)
print('Instance %s has container instance ARN %s' % (lifecycle_event['EC2InstanceId'], instance_arn))
if not instance_arn:
return
task_arns = container_instance_task_arns(cluster, instance_arn)
if task_arns:
print('Instance ARN %s has task ARNs %s' % (instance_arn, ', '.join(task_arns)))
while has_tasks(cluster, instance_arn, task_arns):
time.sleep(10)
try:
print('Terminating instance %s' % instance_id)
autoscaling.complete_lifecycle_action(
LifecycleActionResult='CONTINUE',
**pick(lifecycle_event, 'LifecycleHookName', 'LifecycleActionToken', 'AutoScalingGroupName'))
except Exception as e:
# Lifecycle action may have already completed.
print(str(e))
def container_instance_arn(cluster, instance_id):
"""Turn an instance ID into a container instance ARN."""
arns = ecs.list_container_instances(cluster=cluster, filter='ec2InstanceId==' + instance_id)['containerInstanceArns']
if not arns:
return None
return arns[0]
def container_instance_task_arns(cluster, instance_arn):
"""Fetch tasks for a container instance ARN."""
arns = ecs.list_tasks(cluster=cluster, containerInstance=instance_arn)['taskArns']
return arns
def has_tasks(cluster, instance_arn, task_arns):
"""Return True if the instance is running tasks for the given cluster."""
instances = ecs.describe_container_instances(cluster=cluster, containerInstances=[instance_arn])['containerInstances']
if not instances:
return False
instance = instances[0]
if instance['status'] == 'ACTIVE':
# Start draining, then try again later
set_container_instance_to_draining(cluster, instance_arn)
return True
task_count = None
if task_arns:
# Fetch details for tasks running on the container instance
tasks = ecs.describe_tasks(cluster=cluster, tasks=task_arns)['tasks']
if tasks:
# Consider any non-stopped tasks as running
task_count = sum(task['lastStatus'] != 'STOPPED' for task in tasks) + instance['pendingTasksCount']
if not task_count:
# Fallback to instance task counts if detailed task information is unavailable
task_count = instance['runningTasksCount'] + instance['pendingTasksCount']
print('Instance %s has %s tasks' % (instance_arn, task_count))
return task_count > 0
def set_container_instance_to_draining(cluster, instance_arn):
ecs.update_container_instances_state(
cluster=cluster,
containerInstances=[instance_arn], status='DRAINING')
def pick(dct, *keys):
"""Pick a subset of a dict."""
return {k: v for k, v in dct.items() if k in keys}
Role:
Fn::GetAtt:
- SonarClusterDefaultAutoScalingGroupDrainECSHookFunctionServiceRole486D5691
- Arn
Environment:
Variables:
CLUSTER:
Ref: SonarCluster26427412
Handler: index.lambda_handler
Runtime: python3.9
Tags:
- Key: Name
Value: CdkPythoncStack/SonarCluster/DefaultAutoScalingGroup
Timeout: 310
DependsOn:
- SonarClusterDefaultAutoScalingGroupDrainECSHookFunctionServiceRoleDefaultPolicyB468CFBE
- SonarClusterDefaultAutoScalingGroupDrainECSHookFunctionServiceRole486D5691
Metadata:
aws:cdk:path: CdkPythoncStack/SonarCluster/DefaultAutoScalingGroup/DrainECSHook/Function/Resource
SonarClusterDefaultAutoScalingGroupDrainECSHookFunctionAllowInvokeCdkPythoncStackSonarClusterDefaultAutoScalingGroupLifecycleHookDrainHookTopic689529115C307343:
Type: AWS::Lambda::Permission
Properties:
Action: lambda:InvokeFunction
FunctionName:
Fn::GetAtt:
- SonarClusterDefaultAutoScalingGroupDrainECSHookFunction3E1C6F0C
- Arn
Principal: sns.amazonaws.com
SourceArn:
Ref: SonarClusterDefaultAutoScalingGroupLifecycleHookDrainHookTopic34CD5F37
Metadata:
aws:cdk:path: CdkPythoncStack/SonarCluster/DefaultAutoScalingGroup/DrainECSHook/Function/AllowInvoke:CdkPythoncStackSonarClusterDefaultAutoScalingGroupLifecycleHookDrainHookTopic68952911
SonarClusterDefaultAutoScalingGroupDrainECSHookFunctionTopic1EBB0E98:
Type: AWS::SNS::Subscription
Properties:
Protocol: lambda
TopicArn:
Ref: SonarClusterDefaultAutoScalingGroupLifecycleHookDrainHookTopic34CD5F37
Endpoint:
Fn::GetAtt:
- SonarClusterDefaultAutoScalingGroupDrainECSHookFunction3E1C6F0C
- Arn
Metadata:
aws:cdk:path: CdkPythoncStack/SonarCluster/DefaultAutoScalingGroup/DrainECSHook/Function/Topic/Resource
SonarClusterDefaultAutoScalingGroupLifecycleHookDrainHookTopic34CD5F37:
Type: AWS::SNS::Topic
Properties:
Tags:
- Key: Name
Value: CdkPythoncStack/SonarCluster/DefaultAutoScalingGroup
Metadata:
aws:cdk:path: CdkPythoncStack/SonarCluster/DefaultAutoScalingGroup/LifecycleHookDrainHook/Topic/Resource
SonarClusterDefaultAutoScalingGroupLifecycleHookDrainHookRoleE08A5DEC:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
Service: autoscaling.amazonaws.com
Version: "2012-10-17"
Tags:
- Key: Name
Value: CdkPythoncStack/SonarCluster/DefaultAutoScalingGroup
Metadata:
aws:cdk:path: CdkPythoncStack/SonarCluster/DefaultAutoScalingGroup/LifecycleHookDrainHook/Role/Resource
SonarClusterDefaultAutoScalingGroupLifecycleHookDrainHookRoleDefaultPolicy713100C9:
Type: AWS::IAM::Policy
Properties:
PolicyDocument:
Statement:
- Action: sns:Publish
Effect: Allow
Resource:
Ref: SonarClusterDefaultAutoScalingGroupLifecycleHookDrainHookTopic34CD5F37
Version: "2012-10-17"
PolicyName: SonarClusterDefaultAutoScalingGroupLifecycleHookDrainHookRoleDefaultPolicy713100C9
Roles:
- Ref: SonarClusterDefaultAutoScalingGroupLifecycleHookDrainHookRoleE08A5DEC
Metadata:
aws:cdk:path: CdkPythoncStack/SonarCluster/DefaultAutoScalingGroup/LifecycleHookDrainHook/Role/DefaultPolicy/Resource
SonarClusterDefaultAutoScalingGroupLifecycleHookDrainHook082C154E:
Type: AWS::AutoScaling::LifecycleHook
Properties:
AutoScalingGroupName:
Ref: SonarClusterDefaultAutoScalingGroupASG8768A876
LifecycleTransition: autoscaling:EC2_INSTANCE_TERMINATING
DefaultResult: CONTINUE
HeartbeatTimeout: 300
NotificationTargetARN:
Ref: SonarClusterDefaultAutoScalingGroupLifecycleHookDrainHookTopic34CD5F37
RoleARN:
Fn::GetAtt:
- SonarClusterDefaultAutoScalingGroupLifecycleHookDrainHookRoleE08A5DEC
- Arn
DependsOn:
- SonarClusterDefaultAutoScalingGroupLifecycleHookDrainHookRoleDefaultPolicy713100C9
- SonarClusterDefaultAutoScalingGroupLifecycleHookDrainHookRoleE08A5DEC
Metadata:
aws:cdk:path: CdkPythoncStack/SonarCluster/DefaultAutoScalingGroup/LifecycleHookDrainHook/Resource
SonarTaskRoleED103E92:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
Service: ecs-tasks.amazonaws.com
Version: "2012-10-17"
ManagedPolicyArns:
- Fn::Join:
- ""
- - "arn:"
- Ref: AWS::Partition
- :iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy
RoleName: SonarTaskRole
Metadata:
aws:cdk:path: CdkPythoncStack/SonarTaskRole/Resource
SonarTaskRoleDefaultPolicy17297841:
Type: AWS::IAM::Policy
Properties:
PolicyDocument:
Statement:
- Action:
- secretsmanager:DescribeSecret
- secretsmanager:GetSecretValue
Effect: Allow
Resource:
Ref: SonarDBClusterSecretAttachment74FE44D9
Version: "2012-10-17"
PolicyName: SonarTaskRoleDefaultPolicy17297841
Roles:
- Ref: SonarTaskRoleED103E92
Metadata:
aws:cdk:path: CdkPythoncStack/SonarTaskRole/DefaultPolicy/Resource
SonarServiceLBEE839818:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
LoadBalancerAttributes:
- Key: deletion_protection.enabled
Value: "false"
Scheme: internet-facing
SecurityGroups:
- Fn::GetAtt:
- SonarServiceLBSecurityGroup155666B5
- GroupId
Subnets:
- subnet-05f06d57a1389f223
- subnet-026e1999bbb0bb80c
Type: application
Metadata:
aws:cdk:path: CdkPythoncStack/SonarService/LB/Resource
SonarServiceLBSecurityGroup155666B5:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Automatically created Security Group for ELB CdkPythoncStackSonarServiceLB50EC59E6
SecurityGroupIngress:
- CidrIp: 0.0.0.0/0
Description: Allow from anyone on port 80
FromPort: 80
IpProtocol: tcp
ToPort: 80
VpcId: vpc-0a80e435cc7a23539
Metadata:
aws:cdk:path: CdkPythoncStack/SonarService/LB/SecurityGroup/Resource
SonarServiceLBSecurityGrouptoCdkPythoncStackSonarClusterDefaultAutoScalingGroupInstanceSecurityGroupC7F1071B32768655356F39771B:
Type: AWS::EC2::SecurityGroupEgress
Properties:
GroupId:
Fn::GetAtt:
- SonarServiceLBSecurityGroup155666B5
- GroupId
IpProtocol: tcp
Description: Load balancer to target
DestinationSecurityGroupId:
Fn::GetAtt:
- SonarClusterDefaultAutoScalingGroupInstanceSecurityGroup5A14A3BB
- GroupId
FromPort: 32768
ToPort: 65535
Metadata:
aws:cdk:path: CdkPythoncStack/SonarService/LB/SecurityGroup/to CdkPythoncStackSonarClusterDefaultAutoScalingGroupInstanceSecurityGroupC7F1071B:32768-65535
SonarServiceLBPublicListenerD6C54638:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
DefaultActions:
- TargetGroupArn:
Ref: SonarServiceLBPublicListenerECSGroup1BFB21EC
Type: forward
LoadBalancerArn:
Ref: SonarServiceLBEE839818
Port: 80
Protocol: HTTP
Metadata:
aws:cdk:path: CdkPythoncStack/SonarService/LB/PublicListener/Resource
SonarServiceLBPublicListenerECSGroup1BFB21EC:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
Port: 80
Protocol: HTTP
TargetGroupAttributes:
- Key: stickiness.enabled
Value: "false"
TargetType: instance
VpcId: vpc-0a80e435cc7a23539
Metadata:
aws:cdk:path: CdkPythoncStack/SonarService/LB/PublicListener/ECSGroup/Resource
SonarServiceTaskDefED6D849E:
Type: AWS::ECS::TaskDefinition
Properties:
ContainerDefinitions:
- Environment:
- Name: sonar.jdbc.url
Value:
Fn::Join:
- ""
- - jdbc:postgresql://
- Fn::GetAtt:
- SonarDBClusterE2562227
- Endpoint.Address
- ":"
- Fn::GetAtt:
- SonarDBClusterE2562227
- Endpoint.Port
- /sonarqube
Essential: true
Image: sonarqube:9.8-community
LogConfiguration:
LogDriver: awslogs
Options:
awslogs-group:
Ref: SonarServiceTaskDefwebLogGroup6DBF3E58
awslogs-stream-prefix: SonarService
awslogs-region: eu-central-1
Memory: 2048
Name: web
PortMappings:
- ContainerPort: 9000
HostPort: 0
Protocol: tcp
Secrets:
- Name: sonar.jdbc.username
ValueFrom:
Fn::Join:
- ""
- - Ref: SonarDBClusterSecretAttachment74FE44D9
- ":username::"
- Name: sonar.jdbc.password
ValueFrom:
Fn::Join:
- ""
- - Ref: SonarDBClusterSecretAttachment74FE44D9
- ":password::"
Ulimits:
- HardLimit: 65536
Name: nofile
SoftLimit: 65536
ExecutionRoleArn:
Fn::GetAtt:
- SonarServiceTaskDefExecutionRoleEF6A9987
- Arn
Family: CdkPythoncStackSonarServiceTaskDef1530315E
NetworkMode: bridge
RequiresCompatibilities:
- EC2
TaskRoleArn:
Fn::GetAtt:
- SonarTaskRoleED103E92
- Arn
Metadata:
aws:cdk:path: CdkPythoncStack/SonarService/TaskDef/Resource
SonarServiceTaskDefwebLogGroup6DBF3E58:
Type: AWS::Logs::LogGroup
UpdateReplacePolicy: Retain
DeletionPolicy: Retain
Metadata:
aws:cdk:path: CdkPythoncStack/SonarService/TaskDef/web/LogGroup/Resource
SonarServiceTaskDefExecutionRoleEF6A9987:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
Service: ecs-tasks.amazonaws.com
Version: "2012-10-17"
Metadata:
aws:cdk:path: CdkPythoncStack/SonarService/TaskDef/ExecutionRole/Resource
SonarServiceTaskDefExecutionRoleDefaultPolicy639B757E:
Type: AWS::IAM::Policy
Properties:
PolicyDocument:
Statement:
- Action:
- logs:CreateLogStream
- logs:PutLogEvents
Effect: Allow
Resource:
Fn::GetAtt:
- SonarServiceTaskDefwebLogGroup6DBF3E58
- Arn
- Action:
- secretsmanager:DescribeSecret
- secretsmanager:GetSecretValue
Effect: Allow
Resource:
Ref: SonarDBClusterSecretAttachment74FE44D9
Version: "2012-10-17"
PolicyName: SonarServiceTaskDefExecutionRoleDefaultPolicy639B757E
Roles:
- Ref: SonarServiceTaskDefExecutionRoleEF6A9987
Metadata:
aws:cdk:path: CdkPythoncStack/SonarService/TaskDef/ExecutionRole/DefaultPolicy/Resource
SonarServiceF91D02E7:
Type: AWS::ECS::Service
Properties:
Cluster:
Ref: SonarCluster26427412
DeploymentConfiguration:
MaximumPercent: 100
MinimumHealthyPercent: 0
DesiredCount: 1
EnableECSManagedTags: false
HealthCheckGracePeriodSeconds: 60
LaunchType: EC2
LoadBalancers:
- ContainerName: web
ContainerPort: 9000
TargetGroupArn:
Ref: SonarServiceLBPublicListenerECSGroup1BFB21EC
SchedulingStrategy: REPLICA
TaskDefinition:
Ref: SonarServiceTaskDefED6D849E
DependsOn:
- SonarServiceLBPublicListenerECSGroup1BFB21EC
- SonarServiceLBPublicListenerD6C54638
Metadata:
aws:cdk:path: CdkPythoncStack/SonarService/Service/Service
CDKMetadata:
Type: AWS::CDK::Metadata
Properties:
Analytics: v2:deflate64:H4sIAAAAAAAA/31TTW/bMAz9Lb0rGuABBXZMm24rEGBBkntBy7TDRZYMfXQIDP/30XKUqe3Qk/j4SJF8lCp5X8nqDv74lWrOK021HA8B1Fns0dvoFArmXkZUFROooqNw+eFsHMRjaz53PJvOofcf/E/JPQnXeDluIEANHh919AGdOMTaYLhduHkoHTmYr3MYFj4nJvBsfACjcBI+hfgeDHTo5Lg0MWctxxFch2EdeNZTjyaIW8B7ZhKouNGiTjafVHUEf95gS4YCWTOT7z3WBCCDrvBx3gHdK7G4qWoyJwExWK9Ak+nkuGZwWMBNjC1Eo058Y0tddJArfgjdUovqojT+tPacEkvHJAh6Oe6tTuXTubOa1GWG/6ys5c7ZljT3p6GvG5Djd+4i1y7tHbqevGfE8huWjFfnlaMhB7zBRzuQSoLNRhL5ZYDAunLqehi4jTTh1kLzAHrupCmEQw0+kNLM1onl6V/5jf4/M63tDS7jiLdprjHZLvjlQdy2UEDWxHY86NYWS7ra05Q0AQc9Xt/NrxiGmF5a/lyT2F3CyZovX+U3eX/32xOtXDSBepT75fwLv85WN6IDAAA=
Metadata:
aws:cdk:path: CdkPythoncStack/CDKMetadata/Default
Parameters:
SsmParameterValueawsserviceecsoptimizedamiamazonlinux2recommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter:
Type: AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>
Default: /aws/service/ecs/optimized-ami/amazon-linux-2/recommended/image_id
BootstrapVersion:
Type: AWS::SSM::Parameter::Value<String>
Default: /cdk-bootstrap/hnb659fds/version
Description: Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]
Outputs:
SonarServiceLoadBalancerDNSF086EBD2:
Value:
Fn::GetAtt:
- SonarServiceLBEE839818
- DNSName
SonarServiceServiceURL18C7E97E:
Value:
Fn::Join:
- ""
- - http://
- Fn::GetAtt:
- SonarServiceLBEE839818
- DNSName
Rules:
CheckBootstrapVersion:
Assertions:
- Assert:
Fn::Not:
- Fn::Contains:
- - "1"
- "2"
- "3"
- "4"
- "5"
- Ref: BootstrapVersion
AssertDescription: CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI.