-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaws-landing-zone-initiation.template
5398 lines (5349 loc) · 200 KB
/
aws-landing-zone-initiation.template
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
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright 2012-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Amazon Software License (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
# http://aws.amazon.com/asl/
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.
AWSTemplateFormatVersion: '2010-09-09'
Description: (SO0044) - AWS Landing Zone Initiation Template
Parameters:
SharedServicesAccountEmail:
Description: Email address used to create a centralized Shared Services account
Type: String
MinLength: 6
MaxLength: 64
AllowedPattern: ^[_A-Za-z0-9-\+\.]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$
ConstraintDescription: Account Email can contain only ASCII characters. This must be in the format of [email protected]
LoggingAccountEmail:
Description: Email address used create a centralized audit log account
Type: String
MinLength: 6
MaxLength: 64
AllowedPattern: ^[_A-Za-z0-9-\+\.]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$
ConstraintDescription: Account Email can contain only ASCII characters. This must be in the format of [email protected]
SecurityAccountEmail:
Description: Email address used create a centralized security account
Type: String
MinLength: 6
MaxLength: 64
AllowedPattern: ^[_A-Za-z0-9-\+\.]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$
ConstraintDescription: Account Email can contain only ASCII characters. This must be in the format of [email protected]
SecurityAlertEmail:
Description: Email for all the Security Alerts related to Landing Zone
Type: String
MinLength: 6
MaxLength: 64
AllowedPattern: ^[_A-Za-z0-9-\+\.]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$
ConstraintDescription: Security Alert Email can contain only ASCII characters. This must be in the format of [email protected]
SubscribeAllChangeEventsEmailToTopic:
Type: String
Default: 'No'
Description: Indicates whether AllConfigurationEmail will be subscribed to the AllConfigurationTopicName topic.
AllowedValues:
- 'Yes'
- 'No'
AllChangeEventsEmail:
Description: Email for all the alerts related to Landing Zone
Type: String
Default: ''
MinLength: 0
MaxLength: 64
CoreOUName:
Description: Name of Organizations Unit for the Core Accounts. CloudFormation template validation only allows '-' (hyphen, '.' (period) special characters in the OU names
Type: String
Default: core
MinLength: 1
MaxLength: 128
AllowedPattern: ^[0-9a-zA-Z-\.]+
ConstraintDescription: Under the mapping section, the OU name is not allowed to contain special characters except '-' or '.'
NonCoreOUNames:
Description: Comma separated list of additional Organizations Unit names for organizing additional AWS accounts by applications, business units, etc. CloudFormation template validation only allows '-' (hyphen, '.' (period) special characters in the OU names
Default: applications
Type: CommaDelimitedList
PipelineApprovalStage:
Description: Do you want to add a manual approval stage to the AWS Landing Zone Configuration Pipeline?
AllowedValues:
- 'Yes'
- 'No'
Default: 'No'
Type: String
PipelineApprovalEmail:
Description: (Not required if Pipeline Approval Stage = 'No') Email for notifying that the Landing Zone pipeline is waiting for an Approval
Type: String
BuildLandingZone:
Description: Do you want to trigger the pipeline right away to build the Landing Zone?
AllowedValues:
- 'Yes'
- 'No'
Default: 'Yes'
Type: String
LockStackSetsExecutionRole:
Description: Do you want to lock down the AWS StackSetsExecution role in the member accounts?
AllowedValues:
- 'Yes'
- 'No'
Default: 'Yes'
Type: String
# Shared Services VPC
VPCOptions:
Type: String
Default: Shared-Services-Network-3-AZs
Description: Create a shared service VPC with subnets in 2 or 3 AZs. The 3 AZ option is recommended for all regions except when the desired AD Region only has 2 AZs.
AllowedValues:
- Shared-Services-Network-2-AZs
- Shared-Services-Network-3-AZs
VPCCidr:
Type: String
Default: '100.64.0.0/16'
AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(1[6-9]|2[0-8]))$
ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28
Description: CIDR block for the Shared Services VPC
# AWS Config
EnableConfigAllRegions:
Type: String
Description: "Do you want to enable AWS Config Service and Rules in all the regions?"
Default: 'Yes'
AllowedValues:
- 'Yes'
- 'No'
# AWS Config Rules
EnableEncryptedVolumesRule:
Type: String
Description: "Enables the AWS managed encrypted-volumes config rule."
Default: 'Yes'
AllowedValues:
- 'Yes'
- 'No'
EnableRdsEncryptionRule:
Type: String
Description: "Enables the AWS managed rds-storage-encrypted config rule."
Default: 'Yes'
AllowedValues:
- 'Yes'
- 'No'
EnableS3PublicReadRule:
Type: String
Description: "Enables the AWS managed s3-bucket-public-read-prohibited config rule."
Default: 'Yes'
AllowedValues:
- 'Yes'
- 'No'
EnableS3PublicWriteRule:
Type: String
Description: "Enables the AWS managed s3-bucket-public-write-prohibited config rule."
Default: 'Yes'
AllowedValues:
- 'Yes'
- 'No'
EnableS3ServerSideEncryptionRule:
Type: String
Description: "Enables the AWS managed s3-bucket-server-side-encryption-enabled config rule."
Default: 'Yes'
AllowedValues:
- 'Yes'
- 'No'
EnableRootMfaRule:
Type: String
Description: "Enables the AWS managed root-account-mfa-enabled config rule."
Default: 'Yes'
AllowedValues:
- 'Yes'
- 'No'
EnableIamPasswordPolicyRule:
Type: String
Description: "Enables the AWS managed iam-password-policy config rule."
Default: 'Yes'
AllowedValues:
- 'Yes'
- 'No'
EnableRestrictedCommonPortsRule:
Type: String
Description: "Enables the AWS managed restricted-common-ports config rule."
Default: 'Yes'
AllowedValues:
- 'Yes'
- 'No'
EnableRestrictedSshRule:
Type: String
Description: "Enables the AWS managed restricted-ssh config rule."
Default: 'Yes'
AllowedValues:
- 'Yes'
- 'No'
# Flow logs retention in days
LogsRetentionInDays:
Description: 'Specifies the number of days you want to retain VPC flow logs in each account.'
Type: Number
Default: 90
AllowedValues: [1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, 3653]
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: Landing Zone Core Account Configuration
Parameters:
- SharedServicesAccountEmail
- LoggingAccountEmail
- SecurityAccountEmail
- CoreOUName
- NonCoreOUNames
- SecurityAlertEmail
- LockStackSetsExecutionRole
- SubscribeAllChangeEventsEmailToTopic
- AllChangeEventsEmail
- Label:
default: Landing Zone Pipeline Configuration
Parameters:
- PipelineApprovalStage
- PipelineApprovalEmail
- BuildLandingZone
- Label:
default: Shared Services VPC Configuration
Parameters:
- VPCOptions
- VPCCidr
- Label:
default: VPC Flow Logs Retention Policy
Parameters:
- LogsRetentionInDays
- Label:
default: AWS Config Service Configuration
Parameters:
- EnableConfigAllRegions
- Label:
default: AWS Config Rules
Parameters:
- EnableEncryptedVolumesRule
- EnableRdsEncryptionRule
- EnableS3PublicReadRule
- EnableS3PublicWriteRule
- EnableS3ServerSideEncryptionRule
- EnableRootMfaRule
- EnableIamPasswordPolicyRule
- EnableRestrictedCommonPortsRule
- EnableRestrictedSshRule
ParameterLabels:
SharedServicesAccountEmail:
default: Shared Services Account Email Address
LoggingAccountEmail:
default: Log Archive Account Email Address
SecurityAccountEmail:
default: Security Account Email Address
CoreOUName:
default: Core OU Name
NonCoreOUNames:
default: Non Core OU Names
SecurityAlertEmail:
default: Security Alert Email Address
LockStackSetsExecutionRole:
default: Lock StackSetsExecution Role
AllChangeEventsEmail:
default: All Change Events Email
SubscribeAllChangeEventsEmailToTopic:
default: Subscribe All Change Events Email to Topic
PipelineApprovalStage:
default: Pipeline Approval Stage
PipelineApprovalEmail:
default: Pipeline Approval Email Address
BuildLandingZone:
default: Auto Build Landing Zone
VPCOptions:
default: Shared Services VPC Options
VPCCidr:
default: Shared Services VPC CIDR
EnableConfigAllRegions:
default: Enable Config Service in All Regions
EnableEncryptedVolumesRule:
default: Enable Encrypted Volumes Rule
EnableRdsEncryptionRule:
default: Enable RDS Encryption Rule
EnableS3PublicReadRule:
default: Enable S3 Public Read Rule
EnableS3PublicWriteRule:
default: Enable S3 Public Write Rule
EnableS3ServerSideEncryptionRule:
default: Enable S3 SSE Policy Rule
EnableRootMfaRule:
default: Enable Root MFA Rule
EnableIamPasswordPolicyRule:
default: Enable IAM Password Policy Rule
EnableRestrictedCommonPortsRule:
default: Enable Restricted Common Ports Rule
EnableRestrictedSshRule:
default: Enable Restricted SSH Rule
LogsRetentionInDays:
default: VPC Flow Logs Retention In Days
Mappings:
SSMParameterNames:
LandingZoneSCProductConstraintRoleParameterName:
Name: /org/primary/service_catalog/constraint/role_arn
LandingZoneSCPortfolioPrincipalRoleParameterName:
Name: /org/primary/service_catalog/principal/role_arn
LandingZoneSecurityAlertEmailParameterName:
Name: /org/primary/security_alert_email_id
LandingZoneAllAlertEmailParameterName:
Name: /org/primary/all_alerts_email_id
LandingZoneLambdaParameterName:
Name: /org/primary/avm_lambda_arn
BucketConfiguration:
SourceBucketName:
Name: solutions-reference
SourceKeyName:
Name: aws-landing-zone/v2.0.3/aws-landing-zone-configuration.zip
LandingZonePipelineS3TriggerKey:
Name: aws-landing-zone-configuration.zip
LandingZonePipelineS3NonTriggerKey:
Name: _aws-landing-zone-configuration.zip
KMS:
Alias:
Name: AwsLandingZoneKMSKey
VPC:
Shared-Services-Network-2-AZs:
AvailabilityZones: 2
PublicSubnets:
- PublicSubnet1CIDR
- PublicSubnet2CIDR
PrivateSubnets:
- PrivateSubnet1ACIDR
- PrivateSubnet2ACIDR
CreateAdditionalPrivateSubnets: 'false'
CreatePrivateSubnets: 'true'
CreatePublicSubnets: 'true'
TransitVPC: 'false'
Shared-Services-Network-3-AZs:
AvailabilityZones: 3
PublicSubnets:
- PublicSubnet1CIDR
- PublicSubnet2CIDR
- PublicSubnet3CIDR
PrivateSubnets:
- PrivateSubnet1ACIDR
- PrivateSubnet2ACIDR
- PrivateSubnet3ACIDR
CreateAdditionalPrivateSubnets: 'false'
CreatePrivateSubnets: 'true'
CreatePublicSubnets: 'true'
TransitVPC: 'false'
Solution:
Metrics:
SendAnonymousData: 'Yes'
LambdaFunction:
Logging:
Level: 'info'
Conditions:
IsPipelineApprovalStageCondition: !Equals [!Ref PipelineApprovalStage, 'Yes']
IsBuildLandingZoneCondition: !Equals [!Ref BuildLandingZone, 'Yes']
IsSubscribeToTopicCondition: !Equals [!Ref SubscribeAllChangeEventsEmailToTopic, 'Yes']
Resources:
# IAM Role for Service Catalog Principal
LandingZoneSCPortfolioPrincipalRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action: sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AWSServiceCatalogEndUserFullAccess
# IAM Role for Service Catalog Product Constraint
LandingZoneSCProductConstraintRole:
Type: AWS::IAM::Role
Metadata:
cfn_nag:
rules_to_suppress:
- id: F3
reason: "Override the IAM role to allow catalog-user:* resource on its permissions policy."
Properties:
RoleName: LandingZoneSCProductConstraintRole
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: servicecatalog.amazonaws.com
Action: sts:AssumeRole
Path: /
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AWSLambdaFullAccess
Policies:
- PolicyName: LZAVMProductPolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource:
- Fn::Sub: 'arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/*'
- Effect: Allow
Action:
- catalog-user:*
- cloudformation:CreateStack
- cloudformation:DeleteStack
- cloudformation:DescribeStackEvents
- cloudformation:DescribeStacks
- cloudformation:GetTemplateSummary
- cloudformation:SetStackPolicy
- cloudformation:ValidateTemplate
- cloudformation:UpdateStack
- s3:GetObject
Resource: '*'
- Effect: Allow
Action:
- xray:PutTraceSegments
- xray:PutTelemetryRecords
Resource: '*'
- Effect: Allow
Action:
- states:DescribeStateMachine
- states:DescribeStateMachineForExecution
- states:DescribeExecution
- states:ListExecutions
- states:StartExecution
- states:StopExecution
Resource:
- Fn::Sub: ${OrganizationsStateMachine}
- Fn::Sub: ${ServiceControlPolicyMachine}
- Fn::Sub: ${StackSetStateMachine}
- Fn::Sub: ${ServiceCatalogStateMachine}
- Fn::Sub: ${LaunchAVMStateMachine}
- Fn::Sub: ${CheckAVMExistsStateMachine}
# IAM Role for CloudFormation StackSet Administration in Master account
AWSCloudFormationStackSetAdministrationRole:
Type: AWS::IAM::Role
Properties:
RoleName: AWSCloudFormationStackSetAdministrationRole
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: cloudformation.amazonaws.com
Action:
- sts:AssumeRole
Path: /
Policies:
- PolicyName: AssumeRole-AWSCloudFormationStackSetExecutionRole
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- sts:AssumeRole
Resource:
- "arn:aws:iam::*:role/AWSCloudFormationStackSetExecutionRole"
# IAM Role for CloudFormation StackSet Execution in Master account
AWSCloudFormationStackSetExecutionRole:
Type: AWS::IAM::Role
Properties:
RoleName: AWSCloudFormationStackSetExecutionRole
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
AWS:
- Fn::Sub: ${AWSCloudFormationStackSetAdministrationRole.Arn}
- Fn::Sub: ${StateMachineLambdaRole.Arn}
- Fn::Sub: ${LandingZoneLambdaRole.Arn}
Action:
- sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AdministratorAccess
# SSM Parameter to store the IAM Role ARN of Service Catalog Principal
LandingZoneSCPortfolioPrincipalRoleParameter:
DependsOn:
- LandingZoneSCPortfolioPrincipalRole
Type: AWS::SSM::Parameter
Properties:
Name:
Fn::FindInMap:
- SSMParameterNames
- LandingZoneSCPortfolioPrincipalRoleParameterName
- Name
Description: Contains the IAM Role Arn for Landing Zone Service Catalog Principal
Type: StringList
Value:
Fn::Sub:
'${StateMachineLambdaRole.Arn}'
# SSM Parameter to store the IAM Role ARN of Service Catalog Constraint
LandingZoneSCProductConstraintRoleParameter:
DependsOn:
- LandingZoneSCProductConstraintRole
Type: AWS::SSM::Parameter
Properties:
Name:
Fn::FindInMap:
- SSMParameterNames
- LandingZoneSCProductConstraintRoleParameterName
- Name
Description: Contains the IAM Role Arn for Landing Zone Launch Constraint
Type: String
Value:
Fn::Sub:
'${LandingZoneSCProductConstraintRole.Arn}'
SecurityAlertEmailParameter:
Type: AWS::SSM::Parameter
Properties:
Name: !FindInMap [SSMParameterNames, LandingZoneSecurityAlertEmailParameterName, Name]
Description: Contains the Landing Zone Security Alert Email ID
Type: String
Value: !Ref SecurityAlertEmail
AllAlertEmailParameter:
Type: AWS::SSM::Parameter
Properties:
Name: !FindInMap [SSMParameterNames, LandingZoneAllAlertEmailParameterName, Name]
Description: Contains the Landing Zone Change Alert Email ID
Type: String
Value: !If [IsSubscribeToTopicCondition, !Ref AllChangeEventsEmail, '[email protected]']
PipelineApprovalTopic:
Type: AWS::SNS::Topic
Condition: IsPipelineApprovalStageCondition
Properties:
Subscription:
- Endpoint: !Ref PipelineApprovalEmail
Protocol: email
LandingZonePipelineS3Bucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub aws-landing-zone-configuration-${AWS::AccountId}-${AWS::Region}
VersioningConfiguration:
Status: Enabled
LandingZonePipelineArtifactS3Bucket:
Type: AWS::S3::Bucket
DeletionPolicy: Retain
Properties:
VersioningConfiguration:
Status: Enabled
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
LandingZoneCodePipelineRole:
Type: AWS::IAM::Role
Properties:
RoleName: LandingZoneCodePipelineRole
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- "codepipeline.amazonaws.com"
Action:
- "sts:AssumeRole"
Path: "/"
Policies:
- PolicyName: "AWS-Landing-Zone-CodePipeline-Policy"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Action:
- s3:GetBucketVersioning
Resource:
- !Sub "arn:aws:s3:::${LandingZonePipelineArtifactS3Bucket}"
- !Sub "arn:aws:s3:::${LandingZonePipelineS3Bucket}"
- Effect: "Allow"
Action:
- s3:PutObject
- s3:GetObject
- s3:GetObjectVersion
Resource:
- !Sub "arn:aws:s3:::${LandingZonePipelineArtifactS3Bucket}/*"
- !Sub "arn:aws:s3:::${LandingZonePipelineS3Bucket}/*"
- Effect: Allow
Action:
- ssm:PutParameter
- ssm:GetParameter
- ssm:DeleteParameter
- ssm:GetParametersByPath
- ssm:DescribeParameters
Resource: '*'
- Effect: "Allow"
Action:
- "codebuild:BatchGetBuilds"
- "codebuild:StartBuild"
Resource:
- !Sub "arn:aws:codebuild:${AWS::Region}:${AWS::AccountId}:project/${LandingZoneCodeBuild}"
- !Sub "arn:aws:codebuild:${AWS::Region}:${AWS::AccountId}:project/${LaunchAVMCodeBuild}"
- Effect: "Allow"
Action:
- codecommit:GetBranch
- codecommit:GetCommit
- codecommit:UploadArchive
- codecommit:GetUploadArchiveStatus
- codecommit:CancelUploadArchive
Resource: "*"
- Effect: "Allow"
Action:
- "lambda:InvokeFunction"
Resource: !GetAtt StateMachineTriggerLambda.Arn
- Effect: "Allow"
Action:
- lambda:ListFunctions
- lambda:ListVersionsByFunction
Resource: "*"
- !If
- IsPipelineApprovalStageCondition
- Effect: "Allow"
Action:
- "sns:Publish"
Resource: !Ref PipelineApprovalTopic
- !Ref AWS::NoValue
LandingZoneCodePipeline:
Type: AWS::CodePipeline::Pipeline
Properties:
Name: AWS-Landing-Zone-CodePipeline
RoleArn: !GetAtt LandingZoneCodePipelineRole.Arn
ArtifactStore:
Location: !Ref LandingZonePipelineArtifactS3Bucket
Type: S3
Stages:
- Name: Source
Actions:
- Name: Source
ActionTypeId:
Category: Source
Owner: AWS
Version: 1
Provider: S3
OutputArtifacts:
- Name: SourceApp
Configuration:
S3Bucket: !Ref LandingZonePipelineS3Bucket
S3ObjectKey: !FindInMap [BucketConfiguration, LandingZonePipelineS3TriggerKey, Name]
RunOrder: 1
- Name: Build
Actions:
- Name: CodeBuild
InputArtifacts:
- Name: SourceApp
ActionTypeId:
Category: Build
Owner: AWS
Version: 1
Provider: CodeBuild
OutputArtifacts:
- Name: BuiltApp
Configuration:
ProjectName: !Ref LandingZoneCodeBuild
- !If
- IsPipelineApprovalStageCondition
- Name: Approval
Actions:
- Name: Approval
ActionTypeId:
Category: Approval
Owner: AWS
Version: 1
Provider: Manual
RunOrder: 1
Configuration:
NotificationArn: !Ref PipelineApprovalTopic
- !Ref AWS::NoValue
- Name: CoreAccounts
Actions:
- Name: Deploy
InputArtifacts:
- Name: BuiltApp
ActionTypeId:
Category: Invoke
Owner: AWS
Version: 1
Provider: Lambda
Configuration:
FunctionName: !Ref StateMachineTriggerLambda
UserParameters: "{\"pipeline_stage\": \"core_accounts\", \"artifact\" : \"BuiltApp\", \"exec_mode\" : \"sequential\"}"
RunOrder: 1
- Name: ServiceControlPolicy
Actions:
- Name: Deploy
InputArtifacts:
- Name: BuiltApp
ActionTypeId:
Category: Invoke
Owner: AWS
Version: 1
Provider: Lambda
Configuration:
FunctionName: !Ref StateMachineTriggerLambda
UserParameters: "{\"pipeline_stage\": \"service_control_policy\", \"artifact\" : \"BuiltApp\", \"exec_mode\" : \"parallel\"}"
RunOrder: 1
- Name: CoreResource
Actions:
- Name: Deploy
InputArtifacts:
- Name: BuiltApp
ActionTypeId:
Category: Invoke
Owner: AWS
Version: 1
Provider: Lambda
Configuration:
FunctionName: !Ref StateMachineTriggerLambda
UserParameters: "{\"pipeline_stage\": \"core_resources\", \"artifact\" : \"BuiltApp\", \"exec_mode\" : \"sequential\"}"
RunOrder: 1
- Name: ServiceCatalog
Actions:
- Name: Deploy
InputArtifacts:
- Name: BuiltApp
ActionTypeId:
Category: Invoke
Owner: AWS
Version: 1
Provider: Lambda
Configuration:
FunctionName: !Ref StateMachineTriggerLambda
UserParameters: "{\"pipeline_stage\": \"service_catalog\", \"artifact\" : \"BuiltApp\", \"exec_mode\" : \"parallel\"}"
RunOrder: 1
- Name: BaselineResource
Actions:
- Name: Deploy
InputArtifacts:
- Name: BuiltApp
ActionTypeId:
Category: Invoke
Owner: AWS
Version: 1
Provider: Lambda
Configuration:
FunctionName: !Ref StateMachineTriggerLambda
UserParameters: "{\"pipeline_stage\": \"baseline_resources\", \"artifact\" : \"BuiltApp\", \"exec_mode\" : \"sequential\"}"
RunOrder: 1
- Name: LaunchAVM
Actions:
- Name: CodeBuild
InputArtifacts:
- Name: BuiltApp
ActionTypeId:
Category: Build
Owner: AWS
Version: 1
Provider: CodeBuild
Configuration:
ProjectName: !Ref LaunchAVMCodeBuild
LandingZoneCodeBuildRole:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- "codebuild.amazonaws.com"
Action:
- "sts:AssumeRole"
Path: "/"
Policies:
- PolicyName: "AWS-Landing-Zone-CodeBuild-Policy"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource:
- !Sub "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/codebuild/*"
- Effect: "Allow"
Action:
- s3:PutObject
- s3:GetObjectVersion
- s3:DeleteObject
Resource:
- !Sub "arn:aws:s3:::${LandingZonePipelineArtifactS3Bucket}/*"
- Effect: Allow
Action:
- s3:GetObject
- cloudformation:ValidateTemplate
Resource: "*"
- Effect: "Allow"
Action:
- s3:GetObject
Resource:
- !Sub "arn:aws:s3:::solutions-reference/*"
- Effect: Allow
Action:
- ssm:GetParameter
- ssm:GetParametersByPath
- ssm:DescribeParameters
Resource: '*'
LandingZoneCodeBuild:
Type: AWS::CodeBuild::Project
Properties:
Name: AWS-Landing-Zone-CodeBuild
ServiceRole: !GetAtt LandingZoneCodeBuildRole.Arn
Source:
Type: CODEPIPELINE
BuildSpec: "version: 0.2\nphases:\n install:\n commands:\n - export current=`pwd`\n - if [ -f manifest.yaml ];then export current=`pwd`;else if [ -f aws-landing-zone-configuration/manifest.yaml ]; then export current=`pwd`/aws-landing-zone-configuration; else echo 'manifest.yaml does not exist at the root level of aws-landing-zone-configuration.zip or inside aws-landing-zone-configuration folder, please check the ZIP file'; exit 1; fi; fi;\n - apt-add-repository ppa:brightbox/ruby-ng\n - apt-get update && apt-get upgrade -y\n - apt-get install zip wget python-pip libyaml-dev ruby2.2 rsync -y\n - which python && python --version\n - which python3 && python3 --version\n - which pip && pip --version\n - pip install --upgrade pip==18.0\n - pip install --upgrade setuptools\n - pip install --upgrade virtualenv\n - pip install --upgrade PyYAML\n - pip install --upgrade yorm\n - pip install --upgrade jinja2\n - pip install --upgrade boto3\n - pip install --upgrade pyyaml\n - pip install --upgrade pykwalify\n - pip install cfn_flip\n - pip freeze\n - gem install cfn-nag\n pre_build:\n commands:\n - cd $current\n - echo 'Download the Validation scripts'\n - aws s3 cp s3://solutions-reference/aws-landing-zone/v2.0.3/aws-landing-zone-validation.zip $current\n - unzip -o $current/aws-landing-zone-validation.zip -d $current\n - cp bin/lz_scripts/* .\n build:\n commands:\n - echo 'Starting build `date` in `pwd`'\n - echo 'bash merge_directories.sh $LAMBDA_ARN_SSM_PS_KEY'\n - bash merge_directories.sh $LAMBDA_ARN_SSM_PS_KEY\n - echo 'Executing validation tests'\n - echo 'bash $current/validation/run-validation.sh $ARTIFACT_BUCKET'\n - bash $current/validation/run-validation.sh $ARTIFACT_BUCKET\n - echo 'Installing validation tests completed `date`'\n - echo 'Source Dist completed `date`'\n post_build:\n commands:\n - echo 'Starting post build `date` in `pwd`'\n - echo 'build completed on `date`'\n - echo 'Printing Merge Report'\n - cat merge_report.txt\nartifacts:\n files:\n - '**/*'"
Environment:
ComputeType: BUILD_GENERAL1_SMALL
Image: "aws/codebuild/python:3.6.5"
Type: LINUX_CONTAINER
EnvironmentVariables:
- Name: ARTIFACT_BUCKET
Value: !Ref LandingZonePipelineArtifactS3Bucket
- Name: LAMBDA_ARN_SSM_PS_KEY
Value: !FindInMap [SSMParameterNames, LandingZoneLambdaParameterName, Name]
Artifacts:
Name: !Sub ${LandingZonePipelineArtifactS3Bucket}-Built
Type: CODEPIPELINE
LaunchAVMCodeBuildRole:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- "codebuild.amazonaws.com"
Action:
- "sts:AssumeRole"
Path: "/"
Policies:
- PolicyName: "AWS-Landing-Zone-LaunchAVM-CodeBuild-Policy"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource:
- !Sub "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/codebuild/*"
- Effect: "Allow"
Action:
- s3:GetObject
Resource:
- !Sub "arn:aws:s3:::${LandingZonePipelineArtifactS3Bucket}/*"
- Effect: "Allow"
Action:
- s3:GetObject
Resource:
- !Sub "arn:aws:s3:::solutions-reference/*"
- Effect: Allow
Action:
- states:ListExecutions
- states:StartExecution
- states:StopExecution
Resource:
- !Ref LaunchAVMStateMachine
- Effect: Allow
Action:
- states:DescribeStateMachine
- states:DescribeStateMachineForExecution
- states:DescribeExecution
Resource: '*'
- Effect: Allow
Action:
- organizations:ListRoots
- organizations:ListOrganizationalUnitsForParent
- organizations:ListAccountsForParent
- organizations:DescribeAccount
- organizations:MoveAccount
Resource: '*'
LaunchAVMCodeBuild:
Type: AWS::CodeBuild::Project
Properties:
Name: AWS-Landing-Zone-LaunchAVM-CodeBuild
ServiceRole: !GetAtt LaunchAVMCodeBuildRole.Arn
Source:
Type: CODEPIPELINE
BuildSpec: "version: 0.2\nphases:\n install:\n commands:\n - export current=`pwd`\n - if [ -f manifest.yaml ];then export current=`pwd`;else if [ -f aws-landing-zone-configuration/manifest.yaml ]; then export current=`pwd`/aws-landing-zone-configuration; else echo 'manifest.yaml does not exist at the root level of aws-landing-zone-configuration.zip or inside aws-landing-zone-configuration folder, please check the ZIP file'; exit 1; fi; fi;\n - apt-get update && apt-get upgrade -y\n - apt-get install zip wget python-pip libyaml-dev -y\n - which python && python --version\n - which python3 && python3 --version\n - which pip && pip --version\n - pip install --upgrade pip==18.0\n - pip install --upgrade setuptools\n - pip install --upgrade virtualenv\n - pip install --upgrade PyYAML\n - pip install --upgrade yorm\n - pip install --upgrade boto3\n - pip install --upgrade pyyaml\n - pip freeze\n pre_build:\n commands:\n - cd $current\n - echo 'Download the Launch AVM Code'\n - aws s3 cp s3://solutions-reference/aws-landing-zone/v2.0.3/aws-landing-zone-launch-avm.zip $current\n - unzip -o $current/aws-landing-zone-launch-avm.zip -d $current\n build:\n commands:\n - echo 'Starting Launch AVM `date` in `pwd`'\n - echo 'python3 launch_avm.py $log_level $wait_time $current/manifest.yaml $sm_arn_launch_avm'\n - python3 launch_avm.py $log_level $wait_time $current/manifest.yaml $sm_arn_launch_avm\n - echo 'Completed Launch AVM `date` in `pwd`'\nartifacts:\n files:\n - '**/*'"
Environment:
ComputeType: BUILD_GENERAL1_SMALL
Image: "aws/codebuild/python:3.6.5"
Type: LINUX_CONTAINER
EnvironmentVariables:
- Name: sm_arn_launch_avm
Value: !Ref LaunchAVMStateMachine
- Name: log_level
Value: !FindInMap [LambdaFunction, Logging, Level]
- Name: wait_time
Value: 300
Artifacts:
Name: !Sub ${LandingZonePipelineArtifactS3Bucket}-Built
Type: CODEPIPELINE
TimeoutInMinutes: 480
LandingZoneDeploymentLambdaRole:
Type: AWS::IAM::Role
Properties:
RoleName: LandingZoneDeploymentLambdaRole
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action: sts:AssumeRole
Path: /
Policies:
- PolicyName: LandingZoneDeploymentLambda
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource:
- !Join ['', ['arn:aws:logs:', !Ref 'AWS::Region', ':', !Ref 'AWS::AccountId',':log-group:/aws/lambda/*']]
- Effect: Allow
Action:
- xray:PutTraceSegments
- xray:PutTelemetryRecords
Resource: '*'
- Effect: "Allow"
Action:
- s3:GetEncryptionConfiguration
- s3:PutEncryptionConfiguration
Resource: '*'
- Effect: "Allow"
Action:
- "kms:CreateKey"
- "kms:CreateAlias"
- "kms:ListAliases"
- "kms:DescribeKey"
- "kms:TagResource"
- "kms:PutKeyPolicy"
Resource: "*"
- Effect: Allow
Action:
- ssm:PutParameter
- ssm:GetParameter
- ssm:DeleteParameter
- ssm:GetParametersByPath
- ssm:DescribeParameters
Resource: '*'
- Effect: "Allow"
Action:
- s3:GetObject
Resource:
- !Sub "arn:aws:s3:::solutions-reference/*"
- Effect: "Allow"
Action:
- s3:GetObject
- "s3:PutObject"
Resource:
- !Sub "arn:aws:s3:::${LandingZonePipelineS3Bucket}/*"
LandingZoneDeploymentLambda:
Type: AWS::Lambda::Function
Properties:
Environment:
Variables:
log_level: !FindInMap [LambdaFunction, Logging, Level]
kms_key_alias_name: !FindInMap [KMS, Alias, Name]
Code:
S3Bucket: !Sub solutions-${AWS::Region}
S3Key: aws-landing-zone/v2.0.3/aws-landing-zone-config-deployer.zip
FunctionName: LandingZoneDeploymentLambda
Description: AWS Landing Zone Deployment Lambda
Handler: config_deployer.lambda_handler
MemorySize: '512'
Role: !GetAtt 'LandingZoneDeploymentLambdaRole.Arn'
Runtime: python3.6
Timeout: '300'
TracingConfig:
Mode: Active
LandingZoneConfigDeployer:
Type: Custom::ConfigDeployer
Properties:
metrics_flag: !FindInMap [Solution, Metrics, SendAnonymousData]
email_list:
- !Ref SharedServicesAccountEmail
- !Ref LoggingAccountEmail
- !Ref SecurityAccountEmail
- !Ref SecurityAlertEmail
bucket_config:
destination_bucket_name: !Ref LandingZonePipelineS3Bucket
destination_s3_key: !If [IsBuildLandingZoneCondition, !FindInMap [BucketConfiguration, LandingZonePipelineS3TriggerKey, Name], !FindInMap [BucketConfiguration, LandingZonePipelineS3NonTriggerKey, Name]]