-
Notifications
You must be signed in to change notification settings - Fork 227
/
Copy pathtemplate.yml
2691 lines (2588 loc) · 95.8 KB
/
template.yml
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 Amazon.com Inc. or its affiliates.
# SPDX-License-Identifier: Apache-2.0
AWSTemplateFormatVersion: "2010-09-09"
Transform: "AWS::Serverless-2016-10-31"
Description: ADF CloudFormation Initial Base Stack for the Management Account in the us-east-1 region.
Metadata:
AWS::ServerlessRepo::Application:
Name: aws-deployment-framework
Description: >-
The AWS Deployment Framework (ADF) is an extensive and flexible framework to manage and
deploy resources across multiple AWS accounts and regions based on AWS Organizations.
Author: AWS ADF Builders Team
SpdxLicenseId: Apache-2.0
LicenseUrl: ../LICENSE.txt
ReadmeUrl: ../docs/installation-guide.md
Labels:
["adf", "aws-deployment-framework", "multi-account", "cicd", "devops"]
HomePageUrl: https://github.com/awslabs/aws-deployment-framework
SemanticVersion: 4.0.0
SourceCodeUrl: https://github.com/awslabs/aws-deployment-framework
Mappings:
Metadata:
ADF:
Version: 4.0.0
Parameters:
CrossAccountAccessRoleName:
Type: String
Default: OrganizationAccountAccessRole
AllowedPattern: "[a-zA-Z0-9_+=,.@\\-]+"
MainNotificationEndpoint:
Type: String
Default: ""
Description: >-
Example -> [email protected]. (Only required when installing ADF for the
first time.)
DeploymentAccountName:
Type: String
Default: ""
AllowedPattern: "[\\s\\S]*"
MinLength: 0
MaxLength: 50
Description: >-
The name of the new or existing deployment account. (Only required when
installing ADF for the first time.)
DeploymentAccountEmailAddress:
Type: String
Default: ""
Description: >-
The email address for the new or existing deployment account. (Only required when
installing ADF for the first time.)
DeploymentAccountAlias:
Type: String
Default: ""
AllowedPattern: "([a-z0-9](([a-z0-9]|-(?!-))*[a-z0-9])?)?"
MinLength: 0
MaxLength: 63
Description: >-
Example -> companyname-deployment (Must be globally unique. Only required when
installing ADF for the first time.)
DeploymentAccountId:
Type: String
AllowedPattern: "(\\d{12})?"
Default: ""
Description: >-
Example -> 123456789012 (Only supported when installing ADF for the first time
and you have an existing AWS Account that you wish to use as the deployment
account. Leave blank otherwise.)
DeploymentAccountMainRegion:
Type: String
AllowedPattern: "(us(-gov)?|ap|ca|eu|sa)-(central|(north|south)?(east|west)?)-\\d"
MinLength: 6
Description: "Example -> us-east-1, us-gov-west-1, eu-west-1"
DeploymentAccountTargetRegions:
Type: CommaDelimitedList
Default: ""
Description: >-
(Optional) Example -> us-east-1, us-west-1, eu-west-3. (Only supported when
installing ADF for the first time. If you would like to update this later,
please look at the adfconfig.yml file in the aws-deployment-framework-bootstrap
repository.)
ProtectedOUs:
Type: CommaDelimitedList
Default: ""
Description: >-
(Optional) Example -> ou-123,ou-234 (Only supported when installing ADF for
the first time. If you would like to update this later, please look at the
adfconfig.yml file in the aws-deployment-framework-bootstrap repository.)
LogLevel:
Description: >-
At what Log Level the ADF should operate, default is INFO.
Valid options are: DEBUG, INFO, WARN, ERROR, and CRITICAL.
Type: String
Default: "INFO"
AllowedValues:
- DEBUG
- INFO
- WARN
- ERROR
- CRITICAL
AllowBootstrappingOfManagementAccount:
Description: >-
Would ADF need to bootstrap the Management Account of your AWS
Organization too? If so, set this to "Yes".
Only set this to "Yes" if a pipeline will deploy to the management
account. Or if you need some of the bootstrap resources in the
management account too.
Please be careful: if you plan to set this to "Yes", make sure
that the management account is in a dedicated organization unit
that has bare minimum IAM permissions to deploy. Only grant access
to resource types that are required using least-privilege!
If you set/leave this at "No", make sure the management organization is
in the root of your AWS Organization structure. Or in a dedicated
organization unit and add the organization unit id to the protected
organization unit list via the (ProtectedOUs) parameter.
If not, leave at the default of "No".
Valid options are: Yes, No
Type: String
Default: "No"
AllowedValues:
- "Yes"
- "No"
GrantOrgWidePrivilegedBootstrapAccessUntil:
Description: >-
When set at a date in the future, ADF will use the privileged
cross-account access role to bootstrap the accounts. This is useful
in situations where you are reworking the IAM permissions of the
ADF bootstrap stacks (global-iam.yml). In some cases, setting this
in the future might be required to upgrade ADF to newer versions of
ADF too. If an ADF upgrade requires this, it will be clearly described
in the CHANGELOG.md file and the release notes.
Leave at the configured default to disable privileged bootstrap
access for all accounts. When the date is in the past, only the AWS
Accounts that are accessible to ADF but are not bootstrapped yet will
be allowed access via the privileged cross-account access role.
Date time format according to ISO 8601
https://www.w3.org/TR/NOTE-datetime
Type: String
Default: "1900-12-31T23:59:59Z"
AllowedPattern: "\\d{4}-[0-1]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d([+-][0-2]\\d:[0-5]\\d|Z)"
Globals:
Function:
Architectures:
- arm64
CodeUri: lambda_codebase
Runtime: python3.12
Timeout: 300
Conditions:
CreateCrossAccountAccessRole: !Equals
- !Ref AllowBootstrappingOfManagementAccount
- "Yes"
Resources:
BootstrapTemplatesBucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref "BootstrapTemplatesBucket"
PolicyDocument:
Statement:
- Sid: "AllowBootstrapDeployments"
Action:
- s3:GetObject
Effect: Allow
Resource:
- !Sub arn:${AWS::Partition}:s3:::${BootstrapTemplatesBucket}/adf-bootstrap/*
Principal:
AWS: "*"
Condition:
StringEquals:
"aws:PrincipalOrgID":
- !GetAtt Organization.OrganizationId
ArnLike:
"aws:PrincipalArn":
- !Sub "arn:${AWS::Partition}:iam::*:role/${CrossAccountAccessRoleName}"
- !Sub "arn:${AWS::Partition}:iam::*:role/adf/bootstrap/adf-bootstrap-update-deployment-role"
- Sid: "DenyInsecureConnections"
Action:
- "s3:*"
Effect: Deny
Condition:
Bool:
aws:SecureTransport: "false"
Resource:
- !Sub arn:${AWS::Partition}:s3:::${BootstrapTemplatesBucket}
- !Sub arn:${AWS::Partition}:s3:::${BootstrapTemplatesBucket}/*
Principal:
AWS: "*"
- Sid: "DenyInsecureTLS"
Action:
- "s3:*"
Effect: Deny
Condition:
NumericLessThan:
"s3:TlsVersion": "1.2"
Resource:
- !Sub arn:${AWS::Partition}:s3:::${BootstrapTemplatesBucket}
- !Sub arn:${AWS::Partition}:s3:::${BootstrapTemplatesBucket}/*
Principal:
AWS: "*"
BootstrapArtifactStorageBucket:
Type: AWS::S3::Bucket
DeletionPolicy: Retain
UpdateReplacePolicy: Retain
Properties:
AccessControl: BucketOwnerFullControl
OwnershipControls:
Rules:
- ObjectOwnership: BucketOwnerEnforced
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
VersioningConfiguration:
Status: Enabled
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
BootstrapTemplatesBucket:
Type: "AWS::S3::Bucket"
DeletionPolicy: Retain
UpdateReplacePolicy: Retain
Properties:
AccessControl: BucketOwnerFullControl
OwnershipControls:
Rules:
- ObjectOwnership: BucketOwnerEnforced
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
VersioningConfiguration:
Status: Enabled
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
### Account processing begin
AccountFileProcessingLambdaRole:
Type: "AWS::IAM::Role"
Properties:
Path: "/adf/account-management/"
RoleName: "adf-account-management-account-file-processing"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- "lambda.amazonaws.com"
Action:
- "sts:AssumeRole"
ManagedPolicyArns:
- !Ref LambdaLayerPolicy
- !Ref AccountAccessRolePolicy
- !Ref AccountProcessingLambdaBasePolicy
AccountFileProcessingLambdaPolicy:
# Added as an IAM Managed Policy to break the circular dependency chain
# This should not be added as a DependsOn on the lambda, by the time objects
# are written in the bucket this policy is in effect already.
Type: "AWS::IAM::ManagedPolicy"
Properties:
Description: "Policy to process accounts as configured in the bucket"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Action:
- "organizations:DescribeOrganizationalUnit"
- "organizations:ListParents"
- "organizations:ListAccounts"
- "organizations:DescribeOrganization"
- "organizations:DescribeAccount"
Resource: "*"
- Effect: "Allow"
Action: "s3:ListBucket"
Resource: !GetAtt ADFAccountBucket.Arn
- Effect: "Allow"
Action: "s3:GetObject"
Resource: !Sub "${ADFAccountBucket.Arn}/*"
- Effect: "Allow"
Action: "states:StartExecution"
Resource: !Ref AccountManagementStateMachine
Roles:
- !Ref AccountFileProcessingLambdaRole
AccountAccessRolePolicy:
Type: "AWS::IAM::ManagedPolicy"
Properties:
Description: "Additional policy that allows a lambda to assume the cross account access role"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- "sts:AssumeRole"
Resource:
- !GetAtt CrossAccountJumpRoleArn.Value
AccountProcessingLambdaBasePolicy:
Type: "AWS::IAM::ManagedPolicy"
Properties:
Description: "Base policy for all ADF account processing lambdas"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- "logs:CreateLogGroup"
- "logs:CreateLogStream"
- "logs:PutLogEvents"
- "xray:PutTelemetryRecords"
- "xray:PutTraceSegments"
Resource: "*"
AccountManagementStateMachineExecutionRole:
Type: "AWS::IAM::Role"
Properties:
Path: "/adf/account-management/"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- states.amazonaws.com
Action: "sts:AssumeRole"
Condition:
ArnEquals:
"aws:SourceArn": !Sub "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:stateMachine:adf-account-management"
Policies:
- PolicyName: "adf-state-machine-role-policy"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- "xray:PutTelemetryRecords"
- "xray:PutTraceSegments"
Resource: "*"
- Effect: Allow
Action:
- "lambda:InvokeFunction"
Resource:
- !GetAtt AccountAliasConfigFunction.Arn
- !GetAtt CreateAccountFunction.Arn
- !GetAtt RegisterAccountForSupportFunction.Arn
- !GetAtt AccountTagConfigFunction.Arn
- !GetAtt AccountOUConfigFunction.Arn
- !GetAtt GetAccountRegionsFunction.Arn
- !GetAtt DeleteDefaultVPCFunction.Arn
- !GetAtt AccountRegionConfigFunction.Arn
- !GetAtt JumpRoleApplication.Outputs.ManagerFunctionArn
AccountFileProcessingFunction:
Type: "AWS::Serverless::Function"
Properties:
Handler: process_account_files.lambda_handler
Description: >-
ADF - Account Management - Account File Event Processing.
Responsible to kick-off the account management state machine.
Triggers when new account configurations were added in the
adf-accounts folder of the aws-deployment-framework-bootstrap
repository.
CodeUri: lambda_codebase/account_processing
Tracing: Active
Layers:
- !Ref ADFSharedPythonLambdaLayerVersion
Environment:
Variables:
MANAGEMENT_ACCOUNT_ID: !Ref AWS::AccountId
ORGANIZATION_ID: !GetAtt Organization.OrganizationId
ADF_VERSION: !FindInMap ["Metadata", "ADF", "Version"]
ADF_LOG_LEVEL: !Ref LogLevel
ACCOUNT_MANAGEMENT_STATEMACHINE_ARN: !Ref AccountManagementStateMachine
ADF_PRIVILEGED_CROSS_ACCOUNT_ROLE_NAME: !Ref CrossAccountAccessRoleName
FunctionName: adf-account-management-file-event-processor
Role: !GetAtt AccountFileProcessingLambdaRole.Arn
Events:
S3YmlSuffixEvent:
Type: S3
Properties:
Bucket:
Ref: ADFAccountBucket
Events: s3:ObjectCreated:*
Filter:
S3Key:
Rules:
- Name: suffix
Value: yml
S3YamlSuffixEvent:
Type: S3
Properties:
Bucket:
Ref: ADFAccountBucket
Events: s3:ObjectCreated:*
Filter:
S3Key:
Rules:
- Name: suffix
Value: yaml
Metadata:
BuildMethod: python3.12
AccountAliasConfigLambdaRole:
Type: "AWS::IAM::Role"
Properties:
Path: "/adf/account-management/"
RoleName: "adf-account-management-config-account-alias"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- lambda.amazonaws.com
Action: "sts:AssumeRole"
ManagedPolicyArns:
- !Ref LambdaLayerPolicy
- !Ref AccountAccessRolePolicy
- !Ref AccountProcessingLambdaBasePolicy
AccountAliasConfigFunction:
Type: "AWS::Serverless::Function"
Properties:
Handler: configure_account_alias.lambda_handler
Description: ADF - Account Management - Account Alias Configuration
CodeUri: lambda_codebase/account_processing
Tracing: Active
Layers:
- !Ref ADFSharedPythonLambdaLayerVersion
Environment:
Variables:
AWS_PARTITION: !Ref AWS::Partition
MANAGEMENT_ACCOUNT_ID: !Ref AWS::AccountId
ORGANIZATION_ID: !GetAtt Organization.OrganizationId
ADF_VERSION: !FindInMap ["Metadata", "ADF", "Version"]
ADF_LOG_LEVEL: !Ref LogLevel
ADF_PRIVILEGED_CROSS_ACCOUNT_ROLE_NAME: !Ref CrossAccountAccessRoleName
FunctionName: adf-account-management-config-alias
Role: !GetAtt AccountAliasConfigLambdaRole.Arn
Metadata:
BuildMethod: python3.12
AccountTagConfigFunctionRole:
Type: "AWS::IAM::Role"
Properties:
Path: "/adf/account-management/"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- lambda.amazonaws.com
Action: "sts:AssumeRole"
ManagedPolicyArns:
- !Ref LambdaLayerPolicy
- !Ref AccountProcessingLambdaBasePolicy
Policies:
- PolicyName: "adf-lambda-tag-resource-policy"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- "organizations:TagResource"
- "organizations:UntagResource"
Resource:
- !Sub "arn:${AWS::Partition}:organizations::${AWS::AccountId}:account/${Organization.OrganizationId}/*"
AccountTagConfigFunction:
Type: "AWS::Serverless::Function"
Properties:
Handler: configure_account_tags.lambda_handler
Description: ADF - Account Management - Account Tag Configuration
CodeUri: lambda_codebase/account_processing
Tracing: Active
Layers:
- !Ref ADFSharedPythonLambdaLayerVersion
Environment:
Variables:
MANAGEMENT_ACCOUNT_ID: !Ref AWS::AccountId
ORGANIZATION_ID: !GetAtt Organization.OrganizationId
ADF_VERSION: !FindInMap ["Metadata", "ADF", "Version"]
ADF_LOG_LEVEL: !Ref LogLevel
FunctionName: adf-account-management-config-tags
Role: !GetAtt AccountTagConfigFunctionRole.Arn
Metadata:
BuildMethod: python3.12
AccountRegionConfigFunctionRole:
Type: "AWS::IAM::Role"
Properties:
Path: "/adf/account-management/"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- lambda.amazonaws.com
Action: "sts:AssumeRole"
ManagedPolicyArns:
- !Ref LambdaLayerPolicy
- !Ref AccountProcessingLambdaBasePolicy
Policies:
- PolicyName: "adf-lambda-account-region-resource-policy"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- "account:ListRegions"
- "account:EnableRegion"
- "sts:GetCallerIdentity"
Resource: "*"
- Effect: Allow
Action: ssm:GetParameter
Resource:
- !Sub "arn:${AWS::Partition}:ssm:${AWS::Region}:${AWS::AccountId}:parameter/adf/target_regions"
AccountRegionConfigFunction:
Type: "AWS::Serverless::Function"
Properties:
Handler: configure_account_regions.lambda_handler
Description: ADF - Account Management - Account Region Configuration
CodeUri: lambda_codebase/account_processing
Tracing: Active
Layers:
- !Ref ADFSharedPythonLambdaLayerVersion
Environment:
Variables:
MANAGEMENT_ACCOUNT_ID: !Ref AWS::AccountId
ORGANIZATION_ID: !GetAtt Organization.OrganizationId
ADF_VERSION: !FindInMap ["Metadata", "ADF", "Version"]
ADF_LOG_LEVEL: !Ref LogLevel
FunctionName: adf-account-management-config-region
Role: !GetAtt AccountRegionConfigFunctionRole.Arn
Metadata:
BuildMethod: python3.12
AccountOUConfigFunction:
Type: "AWS::Serverless::Function"
Properties:
Handler: configure_account_ou.lambda_handler
Description: ADF - Account Management - Account OU Configuration
CodeUri: lambda_codebase/account_processing
Tracing: Active
Layers:
- !Ref ADFSharedPythonLambdaLayerVersion
Environment:
Variables:
MANAGEMENT_ACCOUNT_ID: !Ref AWS::AccountId
ORGANIZATION_ID: !GetAtt Organization.OrganizationId
ADF_VERSION: !FindInMap ["Metadata", "ADF", "Version"]
ADF_LOG_LEVEL: !Ref LogLevel
FunctionName: adf-account-management-config-ou
Role: !GetAtt AccountOUConfigFunctionRole.Arn
Metadata:
BuildMethod: python3.12
AccountOUConfigFunctionRole:
Type: "AWS::IAM::Role"
Properties:
Path: "/adf/account-management/"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- lambda.amazonaws.com
Action: "sts:AssumeRole"
ManagedPolicyArns:
- !Ref LambdaLayerPolicy
- !Ref AccountProcessingLambdaBasePolicy
Policies:
- PolicyName: "adf-lambda-policy-move-ou"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- "organizations:ListRoots"
- "organizations:ListParents"
- "organizations:MoveAccount"
- "organizations:ListOrganizationalUnitsForParent"
- "organizations:ListChildren"
- "organizations:ListAccounts*"
Resource: "*"
GetAccountRegionsFunction:
Type: "AWS::Serverless::Function"
Properties:
Handler: get_account_regions.lambda_handler
Description: ADF - Account Management - Get Default Regions
CodeUri: lambda_codebase/account_processing
Tracing: Active
Layers:
- !Ref ADFSharedPythonLambdaLayerVersion
Environment:
Variables:
AWS_PARTITION: !Ref AWS::Partition
MANAGEMENT_ACCOUNT_ID: !Ref AWS::AccountId
ORGANIZATION_ID: !GetAtt Organization.OrganizationId
ADF_VERSION: !FindInMap ["Metadata", "ADF", "Version"]
ADF_LOG_LEVEL: !Ref LogLevel
ADF_PRIVILEGED_CROSS_ACCOUNT_ROLE_NAME: !Ref CrossAccountAccessRoleName
FunctionName: adf-account-management-get-regions
Role: !GetAtt GetAccountRegionsLambdaRole.Arn
Metadata:
BuildMethod: python3.12
GetAccountRegionsLambdaRole:
Type: "AWS::IAM::Role"
Properties:
Path: "/adf/account-management/"
RoleName: "adf-account-management-get-account-regions"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- lambda.amazonaws.com
Action: "sts:AssumeRole"
ManagedPolicyArns:
- !Ref LambdaLayerPolicy
- !Ref AccountAccessRolePolicy
- !Ref AccountProcessingLambdaBasePolicy
DeleteDefaultVPCFunction:
Type: "AWS::Serverless::Function"
Properties:
Handler: delete_default_vpc.lambda_handler
Description: ADF - Account Management - Delete the Default VPCs
CodeUri: lambda_codebase/account_processing
Tracing: Active
Layers:
- !Ref ADFSharedPythonLambdaLayerVersion
Environment:
Variables:
AWS_PARTITION: !Ref AWS::Partition
MANAGEMENT_ACCOUNT_ID: !Ref AWS::AccountId
ORGANIZATION_ID: !GetAtt Organization.OrganizationId
ADF_VERSION: !FindInMap ["Metadata", "ADF", "Version"]
ADF_LOG_LEVEL: !Ref LogLevel
ADF_PRIVILEGED_CROSS_ACCOUNT_ROLE_NAME: !Ref CrossAccountAccessRoleName
FunctionName: adf-account-management-delete-default-vpc
Role: !GetAtt DeleteDefaultVPCLambdaRole.Arn
Metadata:
BuildMethod: python3.12
DeleteDefaultVPCLambdaRole:
Type: "AWS::IAM::Role"
Properties:
Path: "/adf/account-management/"
RoleName: "adf-account-management-delete-default-vpc"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- lambda.amazonaws.com
Action: "sts:AssumeRole"
ManagedPolicyArns:
- !Ref LambdaLayerPolicy
- !Ref AccountAccessRolePolicy
- !Ref AccountProcessingLambdaBasePolicy
CreateAccountFunction:
Type: "AWS::Serverless::Function"
Properties:
Handler: create_account.lambda_handler
Description: ADF - Account Management - Create Account
CodeUri: lambda_codebase/account_processing
Tracing: Active
Layers:
- !Ref ADFSharedPythonLambdaLayerVersion
Environment:
Variables:
MANAGEMENT_ACCOUNT_ID: !Ref AWS::AccountId
ORGANIZATION_ID: !GetAtt Organization.OrganizationId
ADF_VERSION: !FindInMap ["Metadata", "ADF", "Version"]
ADF_LOG_LEVEL: !Ref LogLevel
ADF_PRIVILEGED_CROSS_ACCOUNT_ROLE_NAME: !Ref CrossAccountAccessRoleName
FunctionName: adf-account-management-create-account
Role: !GetAtt CreateAccountFunctionRole.Arn
Metadata:
BuildMethod: python3.12
CreateAccountFunctionRole:
Type: "AWS::IAM::Role"
Properties:
Path: "/adf/account-management/"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- lambda.amazonaws.com
Action: "sts:AssumeRole"
ManagedPolicyArns:
- !Ref LambdaLayerPolicy
- !Ref AccountProcessingLambdaBasePolicy
Policies:
- PolicyName: "adf-lambda-create-account-policy"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- "organizations:CreateAccount"
- "organizations:DescribeCreateAccountStatus"
Resource: "*"
RegisterAccountForSupportFunction:
Type: "AWS::Serverless::Function"
Properties:
Handler: register_account_for_support.lambda_handler
Description: ADF - Account Management - Register support level
CodeUri: lambda_codebase/account_processing
Tracing: Active
Layers:
- !Ref ADFSharedPythonLambdaLayerVersion
Environment:
Variables:
MANAGEMENT_ACCOUNT_ID: !Ref AWS::AccountId
ORGANIZATION_ID: !GetAtt Organization.OrganizationId
ADF_VERSION: !FindInMap ["Metadata", "ADF", "Version"]
ADF_LOG_LEVEL: !Ref LogLevel
FunctionName: adf-account-management-register-support-level
Role: !GetAtt RegisterAccountForSupportFunctionRole.Arn
Metadata:
BuildMethod: python3.12
RegisterAccountForSupportFunctionRole:
Type: "AWS::IAM::Role"
Properties:
Path: "/adf/account-management/"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- lambda.amazonaws.com
Action: "sts:AssumeRole"
ManagedPolicyArns:
- !Ref LambdaLayerPolicy
- !Ref AccountProcessingLambdaBasePolicy
Policies:
- PolicyName: "adf-lambda-support-access-policy"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- "support:DescribeSeverityLevels"
- "support:CreateCase"
Resource: "*"
ADFAccountBucket:
Type: "AWS::S3::Bucket"
DeletionPolicy: Retain
UpdateReplacePolicy: Retain
Properties:
AccessControl: BucketOwnerFullControl
OwnershipControls:
Rules:
- ObjectOwnership: BucketOwnerEnforced
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
VersioningConfiguration:
Status: Enabled
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
AccountManagementStateMachine:
Type: "AWS::StepFunctions::StateMachine"
Properties:
StateMachineName: "adf-account-management"
RoleArn: !GetAtt AccountManagementStateMachineExecutionRole.Arn
TracingConfiguration:
Enabled: true
DefinitionString: !Sub |-
{
"Comment": "Create account?",
"StartAt": "CreateAccountChoice",
"States": {
"CreateAccountChoice": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.needs_created",
"BooleanEquals": true,
"Comment": "Create Account",
"Next": "CreateAccount"
}
],
"Default": "ConfigureAccountRegions"
},
"ConfigureAccountAlias": {
"Type": "Task",
"Resource": "${AccountAliasConfigFunction.Arn}",
"Retry": [
{
"ErrorEquals": ["States.TaskFailed"],
"IntervalSeconds": 3,
"BackoffRate": 1.5,
"MaxAttempts": 10
}, {
"ErrorEquals": [
"Lambda.Unknown",
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException",
"Lambda.TooManyRequestsException"
],
"IntervalSeconds": 2,
"BackoffRate": 2,
"MaxAttempts": 6
}
],
"Next": "ConfigureAccountTags"
},
"CreateAccount": {
"Type": "Task",
"Resource": "${CreateAccountFunction.Arn}",
"Retry": [
{
"ErrorEquals": ["States.TaskFailed"],
"IntervalSeconds": 3,
"BackoffRate": 1.5,
"MaxAttempts": 10
}, {
"ErrorEquals": [
"Lambda.Unknown",
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException",
"Lambda.TooManyRequestsException"
],
"IntervalSeconds": 2,
"BackoffRate": 2,
"MaxAttempts": 6
}
],
"Next": "WaitFor10Seconds"
},
"WaitFor10Seconds": {
"Type": "Wait",
"Seconds": 10,
"Next": "ConfigureAccountSupport"
},
"ConfigureAccountSupport": {
"Type": "Task",
"Resource": "${RegisterAccountForSupportFunction.Arn}",
"Retry": [
{
"ErrorEquals": ["States.TaskFailed"],
"IntervalSeconds": 3,
"BackoffRate": 1.5,
"MaxAttempts": 10
}, {
"ErrorEquals": [
"Lambda.Unknown",
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException",
"Lambda.TooManyRequestsException"
],
"IntervalSeconds": 2,
"BackoffRate": 2,
"MaxAttempts": 6
}
],
"Next": "EnableBootstrappingJumpRole"
},
"EnableBootstrappingJumpRole": {
"Type": "Task",
"Resource": "${JumpRoleApplication.Outputs.ManagerFunctionArn}",
"TimeoutSeconds": 300,
"Retry": [
{
"ErrorEquals": [
"Lambda.Unknown",
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException",
"Lambda.TooManyRequestsException"
],
"IntervalSeconds": 2,
"BackoffRate": 2,
"MaxAttempts": 6
}
],
"Next": "WaitForRoleUpdateToApply"
},
"WaitForRoleUpdateToApply": {
"Type": "Wait",
"Seconds": 60,
"Next": "ConfigureAccountRegions"
},
"ConfigureAccountRegions": {
"Type": "Task",
"Resource": "${AccountRegionConfigFunction.Arn}",
"Retry": [
{
"ErrorEquals": [
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException",
"Lambda.TooManyRequestsException"
],
"IntervalSeconds": 2,
"MaxAttempts": 6,
"BackoffRate": 2
}
],
"Next": "AreRegionsConfigured"
},
"AreRegionsConfigured": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.all_regions_enabled",
"BooleanEquals": true,
"Next": "ConfigureAccountAlias"
}
],
"Default": "Wait 15 seconds"
},
"Wait 15 seconds": {
"Type": "Wait",
"Seconds": 15,
"Next": "ConfigureAccountRegions"
},
"ConfigureAccountTags": {
"Type": "Task",
"Resource": "${AccountTagConfigFunction.Arn}",
"Retry": [
{
"ErrorEquals": ["States.TaskFailed"],
"IntervalSeconds": 3,
"BackoffRate": 1.5,
"MaxAttempts": 10
}, {
"ErrorEquals": [
"Lambda.Unknown",
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException",
"Lambda.TooManyRequestsException"
],
"IntervalSeconds": 2,
"BackoffRate": 2,
"MaxAttempts": 6
}
],
"Next": "ConfigureAccountOU"
},
"ConfigureAccountOU": {