-
Notifications
You must be signed in to change notification settings - Fork 9.2k
/
config.go
955 lines (900 loc) · 55.1 KB
/
config.go
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
package aws
import (
"fmt"
"log"
"strings"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/endpoints"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/service/accessanalyzer"
"github.com/aws/aws-sdk-go/service/acm"
"github.com/aws/aws-sdk-go/service/acmpca"
"github.com/aws/aws-sdk-go/service/amplify"
"github.com/aws/aws-sdk-go/service/apigateway"
"github.com/aws/aws-sdk-go/service/apigatewayv2"
"github.com/aws/aws-sdk-go/service/appconfig"
"github.com/aws/aws-sdk-go/service/applicationautoscaling"
"github.com/aws/aws-sdk-go/service/applicationinsights"
"github.com/aws/aws-sdk-go/service/appmesh"
"github.com/aws/aws-sdk-go/service/apprunner"
"github.com/aws/aws-sdk-go/service/appstream"
"github.com/aws/aws-sdk-go/service/appsync"
"github.com/aws/aws-sdk-go/service/athena"
"github.com/aws/aws-sdk-go/service/auditmanager"
"github.com/aws/aws-sdk-go/service/autoscaling"
"github.com/aws/aws-sdk-go/service/autoscalingplans"
"github.com/aws/aws-sdk-go/service/backup"
"github.com/aws/aws-sdk-go/service/batch"
"github.com/aws/aws-sdk-go/service/budgets"
"github.com/aws/aws-sdk-go/service/chime"
"github.com/aws/aws-sdk-go/service/cloud9"
"github.com/aws/aws-sdk-go/service/cloudformation"
"github.com/aws/aws-sdk-go/service/cloudfront"
"github.com/aws/aws-sdk-go/service/cloudhsmv2"
"github.com/aws/aws-sdk-go/service/cloudsearch"
"github.com/aws/aws-sdk-go/service/cloudtrail"
"github.com/aws/aws-sdk-go/service/cloudwatch"
"github.com/aws/aws-sdk-go/service/cloudwatchevents"
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
"github.com/aws/aws-sdk-go/service/codeartifact"
"github.com/aws/aws-sdk-go/service/codebuild"
"github.com/aws/aws-sdk-go/service/codecommit"
"github.com/aws/aws-sdk-go/service/codedeploy"
"github.com/aws/aws-sdk-go/service/codepipeline"
"github.com/aws/aws-sdk-go/service/codestarconnections"
"github.com/aws/aws-sdk-go/service/codestarnotifications"
"github.com/aws/aws-sdk-go/service/cognitoidentity"
"github.com/aws/aws-sdk-go/service/cognitoidentityprovider"
"github.com/aws/aws-sdk-go/service/configservice"
"github.com/aws/aws-sdk-go/service/connect"
"github.com/aws/aws-sdk-go/service/costandusagereportservice"
"github.com/aws/aws-sdk-go/service/databasemigrationservice"
"github.com/aws/aws-sdk-go/service/dataexchange"
"github.com/aws/aws-sdk-go/service/datapipeline"
"github.com/aws/aws-sdk-go/service/datasync"
"github.com/aws/aws-sdk-go/service/dax"
"github.com/aws/aws-sdk-go/service/detective"
"github.com/aws/aws-sdk-go/service/devicefarm"
"github.com/aws/aws-sdk-go/service/directconnect"
"github.com/aws/aws-sdk-go/service/directoryservice"
"github.com/aws/aws-sdk-go/service/dlm"
"github.com/aws/aws-sdk-go/service/docdb"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/ecr"
"github.com/aws/aws-sdk-go/service/ecrpublic"
"github.com/aws/aws-sdk-go/service/ecs"
"github.com/aws/aws-sdk-go/service/efs"
"github.com/aws/aws-sdk-go/service/eks"
"github.com/aws/aws-sdk-go/service/elasticache"
"github.com/aws/aws-sdk-go/service/elasticbeanstalk"
elasticsearch "github.com/aws/aws-sdk-go/service/elasticsearchservice"
"github.com/aws/aws-sdk-go/service/elastictranscoder"
"github.com/aws/aws-sdk-go/service/elb"
"github.com/aws/aws-sdk-go/service/elbv2"
"github.com/aws/aws-sdk-go/service/emr"
"github.com/aws/aws-sdk-go/service/emrcontainers"
"github.com/aws/aws-sdk-go/service/firehose"
"github.com/aws/aws-sdk-go/service/fms"
"github.com/aws/aws-sdk-go/service/forecastservice"
"github.com/aws/aws-sdk-go/service/fsx"
"github.com/aws/aws-sdk-go/service/gamelift"
"github.com/aws/aws-sdk-go/service/glacier"
"github.com/aws/aws-sdk-go/service/globalaccelerator"
"github.com/aws/aws-sdk-go/service/glue"
"github.com/aws/aws-sdk-go/service/greengrass"
"github.com/aws/aws-sdk-go/service/guardduty"
"github.com/aws/aws-sdk-go/service/iam"
"github.com/aws/aws-sdk-go/service/identitystore"
"github.com/aws/aws-sdk-go/service/imagebuilder"
"github.com/aws/aws-sdk-go/service/inspector"
"github.com/aws/aws-sdk-go/service/iot"
"github.com/aws/aws-sdk-go/service/iotanalytics"
"github.com/aws/aws-sdk-go/service/iotevents"
"github.com/aws/aws-sdk-go/service/kafka"
"github.com/aws/aws-sdk-go/service/kinesis"
"github.com/aws/aws-sdk-go/service/kinesisanalytics"
"github.com/aws/aws-sdk-go/service/kinesisanalyticsv2"
"github.com/aws/aws-sdk-go/service/kinesisvideo"
"github.com/aws/aws-sdk-go/service/kms"
"github.com/aws/aws-sdk-go/service/lakeformation"
"github.com/aws/aws-sdk-go/service/lambda"
"github.com/aws/aws-sdk-go/service/lexmodelbuildingservice"
"github.com/aws/aws-sdk-go/service/licensemanager"
"github.com/aws/aws-sdk-go/service/lightsail"
"github.com/aws/aws-sdk-go/service/locationservice"
"github.com/aws/aws-sdk-go/service/macie"
"github.com/aws/aws-sdk-go/service/macie2"
"github.com/aws/aws-sdk-go/service/managedblockchain"
"github.com/aws/aws-sdk-go/service/marketplacecatalog"
"github.com/aws/aws-sdk-go/service/mediaconnect"
"github.com/aws/aws-sdk-go/service/mediaconvert"
"github.com/aws/aws-sdk-go/service/medialive"
"github.com/aws/aws-sdk-go/service/mediapackage"
"github.com/aws/aws-sdk-go/service/mediastore"
"github.com/aws/aws-sdk-go/service/mediastoredata"
"github.com/aws/aws-sdk-go/service/mq"
"github.com/aws/aws-sdk-go/service/mwaa"
"github.com/aws/aws-sdk-go/service/neptune"
"github.com/aws/aws-sdk-go/service/networkfirewall"
"github.com/aws/aws-sdk-go/service/networkmanager"
"github.com/aws/aws-sdk-go/service/opsworks"
"github.com/aws/aws-sdk-go/service/organizations"
"github.com/aws/aws-sdk-go/service/outposts"
"github.com/aws/aws-sdk-go/service/personalize"
"github.com/aws/aws-sdk-go/service/pinpoint"
"github.com/aws/aws-sdk-go/service/pricing"
"github.com/aws/aws-sdk-go/service/prometheusservice"
"github.com/aws/aws-sdk-go/service/qldb"
"github.com/aws/aws-sdk-go/service/quicksight"
"github.com/aws/aws-sdk-go/service/ram"
"github.com/aws/aws-sdk-go/service/rds"
"github.com/aws/aws-sdk-go/service/redshift"
"github.com/aws/aws-sdk-go/service/resourcegroups"
"github.com/aws/aws-sdk-go/service/resourcegroupstaggingapi"
"github.com/aws/aws-sdk-go/service/route53"
"github.com/aws/aws-sdk-go/service/route53domains"
"github.com/aws/aws-sdk-go/service/route53recoverycontrolconfig"
"github.com/aws/aws-sdk-go/service/route53recoveryreadiness"
"github.com/aws/aws-sdk-go/service/route53resolver"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/aws/aws-sdk-go/service/s3control"
"github.com/aws/aws-sdk-go/service/s3outposts"
"github.com/aws/aws-sdk-go/service/sagemaker"
"github.com/aws/aws-sdk-go/service/schemas"
"github.com/aws/aws-sdk-go/service/secretsmanager"
"github.com/aws/aws-sdk-go/service/securityhub"
"github.com/aws/aws-sdk-go/service/serverlessapplicationrepository"
"github.com/aws/aws-sdk-go/service/servicecatalog"
"github.com/aws/aws-sdk-go/service/servicediscovery"
"github.com/aws/aws-sdk-go/service/servicequotas"
"github.com/aws/aws-sdk-go/service/ses"
"github.com/aws/aws-sdk-go/service/sfn"
"github.com/aws/aws-sdk-go/service/shield"
"github.com/aws/aws-sdk-go/service/signer"
"github.com/aws/aws-sdk-go/service/simpledb"
"github.com/aws/aws-sdk-go/service/sns"
"github.com/aws/aws-sdk-go/service/sqs"
"github.com/aws/aws-sdk-go/service/ssm"
"github.com/aws/aws-sdk-go/service/ssoadmin"
"github.com/aws/aws-sdk-go/service/storagegateway"
"github.com/aws/aws-sdk-go/service/sts"
"github.com/aws/aws-sdk-go/service/swf"
"github.com/aws/aws-sdk-go/service/synthetics"
"github.com/aws/aws-sdk-go/service/timestreamwrite"
"github.com/aws/aws-sdk-go/service/transfer"
"github.com/aws/aws-sdk-go/service/waf"
"github.com/aws/aws-sdk-go/service/wafregional"
"github.com/aws/aws-sdk-go/service/wafv2"
"github.com/aws/aws-sdk-go/service/worklink"
"github.com/aws/aws-sdk-go/service/workmail"
"github.com/aws/aws-sdk-go/service/workspaces"
"github.com/aws/aws-sdk-go/service/xray"
awsbase "github.com/hashicorp/aws-sdk-go-base"
"github.com/hashicorp/aws-sdk-go-base/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
"github.com/terraform-providers/terraform-provider-aws/version"
)
type Config struct {
AccessKey string
SecretKey string
CredsFilename string
Profile string
Token string
Region string
MaxRetries int
AssumeRoleARN string
AssumeRoleDurationSeconds int
AssumeRoleExternalID string
AssumeRolePolicy string
AssumeRolePolicyARNs []string
AssumeRoleSessionName string
AssumeRoleTags map[string]string
AssumeRoleTransitiveTagKeys []string
AllowedAccountIds []string
ForbiddenAccountIds []string
DefaultTagsConfig *keyvaluetags.DefaultConfig
Endpoints map[string]string
IgnoreTagsConfig *keyvaluetags.IgnoreConfig
Insecure bool
SkipCredsValidation bool
SkipGetEC2Platforms bool
SkipRegionValidation bool
SkipRequestingAccountId bool
SkipMetadataApiCheck bool
S3ForcePathStyle bool
terraformVersion string
}
type AWSClient struct {
accessanalyzerconn *accessanalyzer.AccessAnalyzer
accountid string
acmconn *acm.ACM
acmpcaconn *acmpca.ACMPCA
amplifyconn *amplify.Amplify
apigatewayconn *apigateway.APIGateway
apigatewayv2conn *apigatewayv2.ApiGatewayV2
appautoscalingconn *applicationautoscaling.ApplicationAutoScaling
appconfigconn *appconfig.AppConfig
applicationinsightsconn *applicationinsights.ApplicationInsights
appmeshconn *appmesh.AppMesh
apprunnerconn *apprunner.AppRunner
appstreamconn *appstream.AppStream
appsyncconn *appsync.AppSync
athenaconn *athena.Athena
auditmanagerconn *auditmanager.AuditManager
autoscalingconn *autoscaling.AutoScaling
autoscalingplansconn *autoscalingplans.AutoScalingPlans
backupconn *backup.Backup
batchconn *batch.Batch
budgetconn *budgets.Budgets
cfconn *cloudformation.CloudFormation
chimeconn *chime.Chime
cloud9conn *cloud9.Cloud9
cloudfrontconn *cloudfront.CloudFront
cloudhsmv2conn *cloudhsmv2.CloudHSMV2
cloudsearchconn *cloudsearch.CloudSearch
cloudtrailconn *cloudtrail.CloudTrail
cloudwatchconn *cloudwatch.CloudWatch
cloudwatcheventsconn *cloudwatchevents.CloudWatchEvents
cloudwatchlogsconn *cloudwatchlogs.CloudWatchLogs
codeartifactconn *codeartifact.CodeArtifact
codebuildconn *codebuild.CodeBuild
codecommitconn *codecommit.CodeCommit
codedeployconn *codedeploy.CodeDeploy
codepipelineconn *codepipeline.CodePipeline
codestarconnectionsconn *codestarconnections.CodeStarConnections
codestarnotificationsconn *codestarnotifications.CodeStarNotifications
cognitoconn *cognitoidentity.CognitoIdentity
cognitoidpconn *cognitoidentityprovider.CognitoIdentityProvider
configconn *configservice.ConfigService
connectconn *connect.Connect
costandusagereportconn *costandusagereportservice.CostandUsageReportService
dataexchangeconn *dataexchange.DataExchange
datapipelineconn *datapipeline.DataPipeline
datasyncconn *datasync.DataSync
daxconn *dax.DAX
DefaultTagsConfig *keyvaluetags.DefaultConfig
detectiveconn *detective.Detective
devicefarmconn *devicefarm.DeviceFarm
dlmconn *dlm.DLM
dmsconn *databasemigrationservice.DatabaseMigrationService
dnsSuffix string
docdbconn *docdb.DocDB
dsconn *directoryservice.DirectoryService
dxconn *directconnect.DirectConnect
dynamodbconn *dynamodb.DynamoDB
ec2conn *ec2.EC2
ecrconn *ecr.ECR
ecrpublicconn *ecrpublic.ECRPublic
ecsconn *ecs.ECS
efsconn *efs.EFS
eksconn *eks.EKS
elasticacheconn *elasticache.ElastiCache
elasticbeanstalkconn *elasticbeanstalk.ElasticBeanstalk
elastictranscoderconn *elastictranscoder.ElasticTranscoder
elbconn *elb.ELB
elbv2conn *elbv2.ELBV2
emrconn *emr.EMR
emrcontainersconn *emrcontainers.EMRContainers
esconn *elasticsearch.ElasticsearchService
firehoseconn *firehose.Firehose
fmsconn *fms.FMS
forecastconn *forecastservice.ForecastService
fsxconn *fsx.FSx
gameliftconn *gamelift.GameLift
glacierconn *glacier.Glacier
globalacceleratorconn *globalaccelerator.GlobalAccelerator
glueconn *glue.Glue
guarddutyconn *guardduty.GuardDuty
greengrassconn *greengrass.Greengrass
iamconn *iam.IAM
identitystoreconn *identitystore.IdentityStore
IgnoreTagsConfig *keyvaluetags.IgnoreConfig
imagebuilderconn *imagebuilder.Imagebuilder
inspectorconn *inspector.Inspector
iotconn *iot.IoT
iotanalyticsconn *iotanalytics.IoTAnalytics
ioteventsconn *iotevents.IoTEvents
kafkaconn *kafka.Kafka
kinesisanalyticsconn *kinesisanalytics.KinesisAnalytics
kinesisanalyticsv2conn *kinesisanalyticsv2.KinesisAnalyticsV2
kinesisconn *kinesis.Kinesis
kinesisvideoconn *kinesisvideo.KinesisVideo
kmsconn *kms.KMS
lakeformationconn *lakeformation.LakeFormation
lambdaconn *lambda.Lambda
lexmodelconn *lexmodelbuildingservice.LexModelBuildingService
licensemanagerconn *licensemanager.LicenseManager
lightsailconn *lightsail.Lightsail
locationconn *locationservice.LocationService
macieconn *macie.Macie
macie2conn *macie2.Macie2
managedblockchainconn *managedblockchain.ManagedBlockchain
marketplacecatalogconn *marketplacecatalog.MarketplaceCatalog
mediaconnectconn *mediaconnect.MediaConnect
mediaconvertconn *mediaconvert.MediaConvert
mediaconvertaccountconn *mediaconvert.MediaConvert
medialiveconn *medialive.MediaLive
mediapackageconn *mediapackage.MediaPackage
mediastoreconn *mediastore.MediaStore
mediastoredataconn *mediastoredata.MediaStoreData
mqconn *mq.MQ
mwaaconn *mwaa.MWAA
neptuneconn *neptune.Neptune
networkfirewallconn *networkfirewall.NetworkFirewall
networkmanagerconn *networkmanager.NetworkManager
opsworksconn *opsworks.OpsWorks
organizationsconn *organizations.Organizations
outpostsconn *outposts.Outposts
partition string
personalizeconn *personalize.Personalize
prometheusserviceconn *prometheusservice.PrometheusService
pinpointconn *pinpoint.Pinpoint
pricingconn *pricing.Pricing
qldbconn *qldb.QLDB
quicksightconn *quicksight.QuickSight
r53conn *route53.Route53
ramconn *ram.RAM
rdsconn *rds.RDS
redshiftconn *redshift.Redshift
region string
resourcegroupsconn *resourcegroups.ResourceGroups
resourcegroupstaggingapiconn *resourcegroupstaggingapi.ResourceGroupsTaggingAPI
reverseDnsPrefix string
route53domainsconn *route53domains.Route53Domains
route53recoverycontrolconfigconn *route53recoverycontrolconfig.Route53RecoveryControlConfig
route53recoveryreadinessconn *route53recoveryreadiness.Route53RecoveryReadiness
route53resolverconn *route53resolver.Route53Resolver
s3conn *s3.S3
s3connUriCleaningDisabled *s3.S3
s3controlconn *s3control.S3Control
s3outpostsconn *s3outposts.S3Outposts
sagemakerconn *sagemaker.SageMaker
scconn *servicecatalog.ServiceCatalog
schemasconn *schemas.Schemas
sdconn *servicediscovery.ServiceDiscovery
secretsmanagerconn *secretsmanager.SecretsManager
securityhubconn *securityhub.SecurityHub
serverlessapplicationrepositoryconn *serverlessapplicationrepository.ServerlessApplicationRepository
servicequotasconn *servicequotas.ServiceQuotas
sesconn *ses.SES
sfnconn *sfn.SFN
shieldconn *shield.Shield
signerconn *signer.Signer
simpledbconn *simpledb.SimpleDB
snsconn *sns.SNS
sqsconn *sqs.SQS
ssmconn *ssm.SSM
ssoadminconn *ssoadmin.SSOAdmin
storagegatewayconn *storagegateway.StorageGateway
stsconn *sts.STS
supportedplatforms []string
swfconn *swf.SWF
syntheticsconn *synthetics.Synthetics
terraformVersion string
timestreamwriteconn *timestreamwrite.TimestreamWrite
transferconn *transfer.Transfer
wafconn *waf.WAF
wafregionalconn *wafregional.WAFRegional
wafv2conn *wafv2.WAFV2
worklinkconn *worklink.WorkLink
workmailconn *workmail.WorkMail
workspacesconn *workspaces.WorkSpaces
xrayconn *xray.XRay
}
// PartitionHostname returns a hostname with the provider domain suffix for the partition
// e.g. PREFIX.amazonaws.com
// The prefix should not contain a trailing period.
func (client *AWSClient) PartitionHostname(prefix string) string {
return fmt.Sprintf("%s.%s", prefix, client.dnsSuffix)
}
// RegionalHostname returns a hostname with the provider domain suffix for the region and partition
// e.g. PREFIX.us-west-2.amazonaws.com
// The prefix should not contain a trailing period.
func (client *AWSClient) RegionalHostname(prefix string) string {
return fmt.Sprintf("%s.%s.%s", prefix, client.region, client.dnsSuffix)
}
// Client configures and returns a fully initialized AWSClient
func (c *Config) Client() (interface{}, error) {
// Get the auth and region. This can fail if keys/regions were not
// specified and we're attempting to use the environment.
if !c.SkipRegionValidation {
if err := awsbase.ValidateRegion(c.Region); err != nil {
return nil, err
}
}
awsbaseConfig := &awsbase.Config{
AccessKey: c.AccessKey,
AssumeRoleARN: c.AssumeRoleARN,
AssumeRoleDurationSeconds: c.AssumeRoleDurationSeconds,
AssumeRoleExternalID: c.AssumeRoleExternalID,
AssumeRolePolicy: c.AssumeRolePolicy,
AssumeRolePolicyARNs: c.AssumeRolePolicyARNs,
AssumeRoleSessionName: c.AssumeRoleSessionName,
AssumeRoleTags: c.AssumeRoleTags,
AssumeRoleTransitiveTagKeys: c.AssumeRoleTransitiveTagKeys,
CallerDocumentationURL: "https://registry.terraform.io/providers/hashicorp/aws",
CallerName: "Terraform AWS Provider",
CredsFilename: c.CredsFilename,
DebugLogging: logging.IsDebugOrHigher(),
IamEndpoint: c.Endpoints["iam"],
Insecure: c.Insecure,
MaxRetries: c.MaxRetries,
Profile: c.Profile,
Region: c.Region,
SecretKey: c.SecretKey,
SkipCredsValidation: c.SkipCredsValidation,
SkipMetadataApiCheck: c.SkipMetadataApiCheck,
SkipRequestingAccountId: c.SkipRequestingAccountId,
StsEndpoint: c.Endpoints["sts"],
Token: c.Token,
UserAgentProducts: []*awsbase.UserAgentProduct{
{Name: "APN", Version: "1.0"},
{Name: "HashiCorp", Version: "1.0"},
{Name: "Terraform", Version: c.terraformVersion, Extra: []string{"+https://www.terraform.io"}},
{Name: "terraform-provider-aws", Version: version.ProviderVersion, Extra: []string{"+https://registry.terraform.io/providers/hashicorp/aws"}},
},
}
sess, accountID, partition, err := awsbase.GetSessionWithAccountIDAndPartition(awsbaseConfig)
if err != nil {
return nil, fmt.Errorf("error configuring Terraform AWS Provider: %w", err)
}
if accountID == "" {
log.Printf("[WARN] AWS account ID not found for provider. See https://www.terraform.io/docs/providers/aws/index.html#skip_requesting_account_id for implications.")
}
if err := awsbase.ValidateAccountID(accountID, c.AllowedAccountIds, c.ForbiddenAccountIds); err != nil {
return nil, err
}
dnsSuffix := "amazonaws.com"
if p, ok := endpoints.PartitionForRegion(endpoints.DefaultPartitions(), c.Region); ok {
dnsSuffix = p.DNSSuffix()
}
client := &AWSClient{
accessanalyzerconn: accessanalyzer.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["accessanalyzer"])})),
accountid: accountID,
acmconn: acm.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["acm"])})),
acmpcaconn: acmpca.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["acmpca"])})),
amplifyconn: amplify.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["amplify"])})),
apigatewayconn: apigateway.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["apigateway"])})),
apigatewayv2conn: apigatewayv2.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["apigateway"])})),
appautoscalingconn: applicationautoscaling.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["applicationautoscaling"])})),
appconfigconn: appconfig.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["appconfig"])})),
applicationinsightsconn: applicationinsights.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["applicationinsights"])})),
appmeshconn: appmesh.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["appmesh"])})),
apprunnerconn: apprunner.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["apprunner"])})),
appstreamconn: appstream.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["appstream"])})),
appsyncconn: appsync.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["appsync"])})),
athenaconn: athena.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["athena"])})),
auditmanagerconn: auditmanager.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["auditmanager"])})),
autoscalingconn: autoscaling.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["autoscaling"])})),
autoscalingplansconn: autoscalingplans.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["autoscalingplans"])})),
backupconn: backup.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["backup"])})),
batchconn: batch.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["batch"])})),
budgetconn: budgets.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["budgets"])})),
cfconn: cloudformation.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["cloudformation"])})),
chimeconn: chime.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["chime"])})),
cloud9conn: cloud9.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["cloud9"])})),
cloudfrontconn: cloudfront.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["cloudfront"])})),
cloudhsmv2conn: cloudhsmv2.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["cloudhsm"])})),
cloudsearchconn: cloudsearch.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["cloudsearch"])})),
cloudtrailconn: cloudtrail.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["cloudtrail"])})),
cloudwatchconn: cloudwatch.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["cloudwatch"])})),
cloudwatcheventsconn: cloudwatchevents.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["cloudwatchevents"])})),
cloudwatchlogsconn: cloudwatchlogs.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["cloudwatchlogs"])})),
codeartifactconn: codeartifact.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["codeartifact"])})),
codebuildconn: codebuild.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["codebuild"])})),
codecommitconn: codecommit.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["codecommit"])})),
codedeployconn: codedeploy.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["codedeploy"])})),
codepipelineconn: codepipeline.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["codepipeline"])})),
codestarconnectionsconn: codestarconnections.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["codestarconnections"])})),
codestarnotificationsconn: codestarnotifications.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["codestarnotifications"])})),
cognitoconn: cognitoidentity.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["cognitoidentity"])})),
cognitoidpconn: cognitoidentityprovider.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["cognitoidp"])})),
configconn: configservice.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["configservice"])})),
connectconn: connect.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["connect"])})),
costandusagereportconn: costandusagereportservice.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["cur"])})),
dataexchangeconn: dataexchange.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["dataexchange"])})),
datapipelineconn: datapipeline.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["datapipeline"])})),
datasyncconn: datasync.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["datasync"])})),
daxconn: dax.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["dax"])})),
DefaultTagsConfig: c.DefaultTagsConfig,
detectiveconn: detective.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["detective"])})),
devicefarmconn: devicefarm.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["devicefarm"])})),
dlmconn: dlm.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["dlm"])})),
dmsconn: databasemigrationservice.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["dms"])})),
dnsSuffix: dnsSuffix,
docdbconn: docdb.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["docdb"])})),
dsconn: directoryservice.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["ds"])})),
dxconn: directconnect.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["directconnect"])})),
dynamodbconn: dynamodb.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["dynamodb"])})),
ec2conn: ec2.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["ec2"])})),
ecrconn: ecr.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["ecr"])})),
ecrpublicconn: ecrpublic.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["ecrpublic"])})),
ecsconn: ecs.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["ecs"])})),
efsconn: efs.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["efs"])})),
eksconn: eks.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["eks"])})),
elasticacheconn: elasticache.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["elasticache"])})),
elasticbeanstalkconn: elasticbeanstalk.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["elasticbeanstalk"])})),
elastictranscoderconn: elastictranscoder.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["elastictranscoder"])})),
elbconn: elb.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["elb"])})),
elbv2conn: elbv2.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["elb"])})),
emrconn: emr.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["emr"])})),
emrcontainersconn: emrcontainers.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["emrcontainers"])})),
esconn: elasticsearch.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["es"])})),
firehoseconn: firehose.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["firehose"])})),
fmsconn: fms.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["fms"])})),
forecastconn: forecastservice.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["forecast"])})),
fsxconn: fsx.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["fsx"])})),
gameliftconn: gamelift.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["gamelift"])})),
glacierconn: glacier.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["glacier"])})),
glueconn: glue.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["glue"])})),
guarddutyconn: guardduty.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["guardduty"])})),
greengrassconn: greengrass.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["greengrass"])})),
iamconn: iam.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["iam"])})),
identitystoreconn: identitystore.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["identitystore"])})),
IgnoreTagsConfig: c.IgnoreTagsConfig,
imagebuilderconn: imagebuilder.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["imagebuilder"])})),
inspectorconn: inspector.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["inspector"])})),
iotconn: iot.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["iot"])})),
iotanalyticsconn: iotanalytics.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["iotanalytics"])})),
ioteventsconn: iotevents.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["iotevents"])})),
kafkaconn: kafka.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["kafka"])})),
kinesisanalyticsconn: kinesisanalytics.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["kinesisanalytics"])})),
kinesisanalyticsv2conn: kinesisanalyticsv2.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["kinesisanalyticsv2"])})),
kinesisconn: kinesis.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["kinesis"])})),
kinesisvideoconn: kinesisvideo.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["kinesisvideo"])})),
kmsconn: kms.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["kms"])})),
lakeformationconn: lakeformation.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["lakeformation"])})),
lambdaconn: lambda.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["lambda"])})),
lexmodelconn: lexmodelbuildingservice.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["lexmodels"])})),
licensemanagerconn: licensemanager.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["licensemanager"])})),
lightsailconn: lightsail.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["lightsail"])})),
locationconn: locationservice.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["location"])})),
macieconn: macie.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["macie"])})),
macie2conn: macie2.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["macie2"])})),
managedblockchainconn: managedblockchain.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["managedblockchain"])})),
marketplacecatalogconn: marketplacecatalog.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["marketplacecatalog"])})),
mediaconnectconn: mediaconnect.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["mediaconnect"])})),
mediaconvertconn: mediaconvert.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["mediaconvert"])})),
medialiveconn: medialive.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["medialive"])})),
mediapackageconn: mediapackage.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["mediapackage"])})),
mediastoreconn: mediastore.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["mediastore"])})),
mediastoredataconn: mediastoredata.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["mediastoredata"])})),
mqconn: mq.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["mq"])})),
mwaaconn: mwaa.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["mwaa"])})),
neptuneconn: neptune.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["neptune"])})),
networkfirewallconn: networkfirewall.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["networkfirewall"])})),
networkmanagerconn: networkmanager.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["networkmanager"])})),
opsworksconn: opsworks.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["opsworks"])})),
organizationsconn: organizations.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["organizations"])})),
outpostsconn: outposts.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["outposts"])})),
partition: partition,
personalizeconn: personalize.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["personalize"])})),
prometheusserviceconn: prometheusservice.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["prometheusservice"])})),
pinpointconn: pinpoint.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["pinpoint"])})),
pricingconn: pricing.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["pricing"])})),
qldbconn: qldb.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["qldb"])})),
quicksightconn: quicksight.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["quicksight"])})),
ramconn: ram.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["ram"])})),
rdsconn: rds.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["rds"])})),
redshiftconn: redshift.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["redshift"])})),
region: c.Region,
resourcegroupsconn: resourcegroups.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["resourcegroups"])})),
resourcegroupstaggingapiconn: resourcegroupstaggingapi.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["resourcegroupstaggingapi"])})),
reverseDnsPrefix: ReverseDns(dnsSuffix),
route53domainsconn: route53domains.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["route53domains"])})),
route53recoverycontrolconfigconn: route53recoverycontrolconfig.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["route53recoverycontrolconfig"])})),
route53recoveryreadinessconn: route53recoveryreadiness.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["route53recoveryreadiness"])})),
route53resolverconn: route53resolver.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["route53resolver"])})),
s3controlconn: s3control.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["s3control"])})),
s3outpostsconn: s3outposts.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["s3outposts"])})),
sagemakerconn: sagemaker.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["sagemaker"])})),
scconn: servicecatalog.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["servicecatalog"])})),
schemasconn: schemas.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["schemas"])})),
sdconn: servicediscovery.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["servicediscovery"])})),
secretsmanagerconn: secretsmanager.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["secretsmanager"])})),
securityhubconn: securityhub.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["securityhub"])})),
serverlessapplicationrepositoryconn: serverlessapplicationrepository.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["serverlessrepo"])})),
servicequotasconn: servicequotas.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["servicequotas"])})),
sesconn: ses.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["ses"])})),
sfnconn: sfn.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["stepfunctions"])})),
signerconn: signer.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["signer"])})),
simpledbconn: simpledb.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["sdb"])})),
snsconn: sns.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["sns"])})),
sqsconn: sqs.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["sqs"])})),
ssmconn: ssm.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["ssm"])})),
ssoadminconn: ssoadmin.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["ssoadmin"])})),
storagegatewayconn: storagegateway.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["storagegateway"])})),
stsconn: sts.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["sts"])})),
swfconn: swf.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["swf"])})),
syntheticsconn: synthetics.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["synthetics"])})),
terraformVersion: c.terraformVersion,
timestreamwriteconn: timestreamwrite.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["timestreamwrite"])})),
transferconn: transfer.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["transfer"])})),
wafconn: waf.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["waf"])})),
wafregionalconn: wafregional.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["wafregional"])})),
wafv2conn: wafv2.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["wafv2"])})),
worklinkconn: worklink.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["worklink"])})),
workmailconn: workmail.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["workmail"])})),
workspacesconn: workspaces.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["workspaces"])})),
xrayconn: xray.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["xray"])})),
}
// "Global" services that require customizations
globalAcceleratorConfig := &aws.Config{
Endpoint: aws.String(c.Endpoints["globalaccelerator"]),
}
route53Config := &aws.Config{
Endpoint: aws.String(c.Endpoints["route53"]),
}
route53RecoveryControlConfigConfig := &aws.Config{
Endpoint: aws.String(c.Endpoints["route53recoverycontrolconfig"]),
}
route53RecoveryReadinessConfig := &aws.Config{
Endpoint: aws.String(c.Endpoints["route53recoveryreadiness"]),
}
shieldConfig := &aws.Config{
Endpoint: aws.String(c.Endpoints["shield"]),
}
// Services that require multiple client configurations
s3Config := &aws.Config{
Endpoint: aws.String(c.Endpoints["s3"]),
S3ForcePathStyle: aws.Bool(c.S3ForcePathStyle),
}
client.s3conn = s3.New(sess.Copy(s3Config))
s3Config.DisableRestProtocolURICleaning = aws.Bool(true)
client.s3connUriCleaningDisabled = s3.New(sess.Copy(s3Config))
// Force "global" services to correct regions
switch partition {
case endpoints.AwsPartitionID:
globalAcceleratorConfig.Region = aws.String(endpoints.UsWest2RegionID)
route53Config.Region = aws.String(endpoints.UsEast1RegionID)
route53RecoveryControlConfigConfig.Region = aws.String(endpoints.UsWest2RegionID)
route53RecoveryReadinessConfig.Region = aws.String(endpoints.UsWest2RegionID)
shieldConfig.Region = aws.String(endpoints.UsEast1RegionID)
case endpoints.AwsCnPartitionID:
// The AWS Go SDK is missing endpoint information for Route 53 in the AWS China partition.
// This can likely be removed in the future.
if aws.StringValue(route53Config.Endpoint) == "" {
route53Config.Endpoint = aws.String("https://api.route53.cn")
}
route53Config.Region = aws.String(endpoints.CnNorthwest1RegionID)
case endpoints.AwsUsGovPartitionID:
route53Config.Region = aws.String(endpoints.UsGovWest1RegionID)
}
client.globalacceleratorconn = globalaccelerator.New(sess.Copy(globalAcceleratorConfig))
client.r53conn = route53.New(sess.Copy(route53Config))
client.route53recoverycontrolconfigconn = route53recoverycontrolconfig.New(sess.Copy(route53RecoveryControlConfigConfig))
client.route53recoveryreadinessconn = route53recoveryreadiness.New(sess.Copy(route53RecoveryReadinessConfig))
client.shieldconn = shield.New(sess.Copy(shieldConfig))
client.apigatewayconn.Handlers.Retry.PushBack(func(r *request.Request) {
// Many operations can return an error such as:
// ConflictException: Unable to complete operation due to concurrent modification. Please try again later.
// Handle them all globally for the service client.
if tfawserr.ErrMessageContains(r.Error, apigateway.ErrCodeConflictException, "try again later") {
r.Retryable = aws.Bool(true)
}
})
// Workaround for https://github.com/aws/aws-sdk-go/issues/1472
client.appautoscalingconn.Handlers.Retry.PushBack(func(r *request.Request) {
if !strings.HasPrefix(r.Operation.Name, "Describe") && !strings.HasPrefix(r.Operation.Name, "List") {
return
}
if tfawserr.ErrCodeEquals(r.Error, applicationautoscaling.ErrCodeFailedResourceAccessException) {
r.Retryable = aws.Bool(true)
}
})
// StartDeployment operations can return a ConflictException
// if ongoing deployments are in-progress, thus we handle them
// here for the service client.
client.appconfigconn.Handlers.Retry.PushBack(func(r *request.Request) {
if r.Operation.Name == "StartDeployment" {
if tfawserr.ErrCodeEquals(r.Error, appconfig.ErrCodeConflictException) {
r.Retryable = aws.Bool(true)
}
}
})
client.appsyncconn.Handlers.Retry.PushBack(func(r *request.Request) {
if r.Operation.Name == "CreateGraphqlApi" {
if isAWSErr(r.Error, appsync.ErrCodeConcurrentModificationException, "a GraphQL API creation is already in progress") {
r.Retryable = aws.Bool(true)
}
}
})
client.cloudhsmv2conn.Handlers.Retry.PushBack(func(r *request.Request) {
if tfawserr.ErrMessageContains(r.Error, cloudhsmv2.ErrCodeCloudHsmInternalFailureException, "request was rejected because of an AWS CloudHSM internal failure") {
r.Retryable = aws.Bool(true)
}
})
client.configconn.Handlers.Retry.PushBack(func(r *request.Request) {
// When calling Config Organization Rules API actions immediately
// after Organization creation, the API can randomly return the
// OrganizationAccessDeniedException error for a few minutes, even
// after succeeding a few requests.
switch r.Operation.Name {
case "DeleteOrganizationConfigRule", "DescribeOrganizationConfigRules", "DescribeOrganizationConfigRuleStatuses", "PutOrganizationConfigRule":
if !isAWSErr(r.Error, configservice.ErrCodeOrganizationAccessDeniedException, "This action can be only made by AWS Organization's master account.") {
return
}
// We only want to retry briefly as the default max retry count would
// excessively retry when the error could be legitimate.
// We currently depend on the DefaultRetryer exponential backoff here.
// ~10 retries gives a fair backoff of a few seconds.
if r.RetryCount < 9 {
r.Retryable = aws.Bool(true)
} else {
r.Retryable = aws.Bool(false)
}
case "DeleteOrganizationConformancePack", "DescribeOrganizationConformancePacks", "DescribeOrganizationConformancePackStatuses", "PutOrganizationConformancePack":
if !tfawserr.ErrCodeEquals(r.Error, configservice.ErrCodeOrganizationAccessDeniedException) {
if r.Operation.Name == "DeleteOrganizationConformancePack" && tfawserr.ErrCodeEquals(err, configservice.ErrCodeResourceInUseException) {
r.Retryable = aws.Bool(true)
}
return
}
// We only want to retry briefly as the default max retry count would
// excessively retry when the error could be legitimate.
// We currently depend on the DefaultRetryer exponential backoff here.
// ~10 retries gives a fair backoff of a few seconds.
if r.RetryCount < 9 {
r.Retryable = aws.Bool(true)
} else {
r.Retryable = aws.Bool(false)
}
}
})
// See https://github.com/aws/aws-sdk-go/pull/1276
client.dynamodbconn.Handlers.Retry.PushBack(func(r *request.Request) {
if r.Operation.Name != "PutItem" && r.Operation.Name != "UpdateItem" && r.Operation.Name != "DeleteItem" {
return
}
if isAWSErr(r.Error, dynamodb.ErrCodeLimitExceededException, "Subscriber limit exceeded:") {
r.Retryable = aws.Bool(true)
}
})
client.ec2conn.Handlers.Retry.PushBack(func(r *request.Request) {
if r.Operation.Name == "CreateClientVpnEndpoint" {
if isAWSErr(r.Error, "OperationNotPermitted", "Endpoint cannot be created while another endpoint is being created") {
r.Retryable = aws.Bool(true)
}
}
if r.Operation.Name == "CreateVpnConnection" {
if isAWSErr(r.Error, "VpnConnectionLimitExceeded", "maximum number of mutating objects has been reached") {
r.Retryable = aws.Bool(true)
}
}
if r.Operation.Name == "CreateVpnGateway" {
if isAWSErr(r.Error, "VpnGatewayLimitExceeded", "maximum number of mutating objects has been reached") {
r.Retryable = aws.Bool(true)
}
}
if r.Operation.Name == "AttachVpnGateway" || r.Operation.Name == "DetachVpnGateway" {
if isAWSErr(r.Error, "InvalidParameterValue", "This call cannot be completed because there are pending VPNs or Virtual Interfaces") {
r.Retryable = aws.Bool(true)
}
}
})
client.fmsconn.Handlers.Retry.PushBack(func(r *request.Request) {
// Acceptance testing creates and deletes resources in quick succession.
// The FMS onboarding process into Organizations is opaque to consumers.
// Since we cannot reasonably check this status before receiving the error,
// set the operation as retryable.
switch r.Operation.Name {
case "AssociateAdminAccount":
if tfawserr.ErrMessageContains(r.Error, fms.ErrCodeInvalidOperationException, "Your AWS Organization is currently offboarding with AWS Firewall Manager. Please submit onboard request after offboarded.") {
r.Retryable = aws.Bool(true)
}
case "DisassociateAdminAccount":
if tfawserr.ErrMessageContains(r.Error, fms.ErrCodeInvalidOperationException, "Your AWS Organization is currently onboarding with AWS Firewall Manager and cannot be offboarded.") {
r.Retryable = aws.Bool(true)
}
}
})
client.kafkaconn.Handlers.Retry.PushBack(func(r *request.Request) {
if isAWSErr(r.Error, kafka.ErrCodeTooManyRequestsException, "Too Many Requests") {
r.Retryable = aws.Bool(true)
}
})
client.kinesisconn.Handlers.Retry.PushBack(func(r *request.Request) {
if r.Operation.Name == "CreateStream" {
if isAWSErr(r.Error, kinesis.ErrCodeLimitExceededException, "simultaneously be in CREATING or DELETING") {
r.Retryable = aws.Bool(true)
}
}
if r.Operation.Name == "CreateStream" || r.Operation.Name == "DeleteStream" {
if isAWSErr(r.Error, kinesis.ErrCodeLimitExceededException, "Rate exceeded for stream") {
r.Retryable = aws.Bool(true)
}
}
})
client.organizationsconn.Handlers.Retry.PushBack(func(r *request.Request) {
// Retry on the following error:
// ConcurrentModificationException: AWS Organizations can't complete your request because it conflicts with another attempt to modify the same entity. Try again later.
if isAWSErr(r.Error, organizations.ErrCodeConcurrentModificationException, "Try again later") {
r.Retryable = aws.Bool(true)
}
})
// Reference: https://github.com/hashicorp/terraform-provider-aws/issues/17996
client.securityhubconn.Handlers.Retry.PushBack(func(r *request.Request) {
switch r.Operation.Name {
case "EnableOrganizationAdminAccount":
if tfawserr.ErrCodeEquals(r.Error, securityhub.ErrCodeResourceConflictException) {
r.Retryable = aws.Bool(true)
}
}
})
// Reference: https://github.com/hashicorp/terraform-provider-aws/issues/19215
client.ssoadminconn.Handlers.Retry.PushBack(func(r *request.Request) {
if r.Operation.Name == "AttachManagedPolicyToPermissionSet" || r.Operation.Name == "DetachManagedPolicyFromPermissionSet" {
if tfawserr.ErrCodeEquals(r.Error, ssoadmin.ErrCodeConflictException) {
r.Retryable = aws.Bool(true)
}
}
})
client.storagegatewayconn.Handlers.Retry.PushBack(func(r *request.Request) {
// InvalidGatewayRequestException: The specified gateway proxy network connection is busy.
if isAWSErr(r.Error, storagegateway.ErrCodeInvalidGatewayRequestException, "The specified gateway proxy network connection is busy") {
r.Retryable = aws.Bool(true)
}
})
client.wafv2conn.Handlers.Retry.PushBack(func(r *request.Request) {
if isAWSErr(r.Error, wafv2.ErrCodeWAFInternalErrorException, "Retry your request") {
r.Retryable = aws.Bool(true)
}
if isAWSErr(r.Error, wafv2.ErrCodeWAFServiceLinkedRoleErrorException, "Retry") {
r.Retryable = aws.Bool(true)
}
if r.Operation.Name == "CreateIPSet" || r.Operation.Name == "CreateRegexPatternSet" ||
r.Operation.Name == "CreateRuleGroup" || r.Operation.Name == "CreateWebACL" {
// WAFv2 supports tag on create which can result in the below error codes according to the documentation
if isAWSErr(r.Error, wafv2.ErrCodeWAFTagOperationException, "Retry your request") {
r.Retryable = aws.Bool(true)
}
if isAWSErr(err, wafv2.ErrCodeWAFTagOperationInternalErrorException, "Retry your request") {
r.Retryable = aws.Bool(true)
}
}
})
if !c.SkipGetEC2Platforms {
supportedPlatforms, err := GetSupportedEC2Platforms(client.ec2conn)
if err != nil {
// We intentionally fail *silently* because there's a chance
// user just doesn't have ec2:DescribeAccountAttributes permissions
log.Printf("[WARN] Unable to get supported EC2 platforms: %s", err)
} else {
client.supportedplatforms = supportedPlatforms
}
}
return client, nil
}
func hasEc2Classic(platforms []string) bool {
for _, p := range platforms {
if p == "EC2" {
return true
}
}
return false
}
func GetSupportedEC2Platforms(conn *ec2.EC2) ([]string, error) {
attrName := "supported-platforms"
input := ec2.DescribeAccountAttributesInput{
AttributeNames: []*string{aws.String(attrName)},
}
attributes, err := conn.DescribeAccountAttributes(&input)
if err != nil {
return nil, err
}
var platforms []string
for _, attr := range attributes.AccountAttributes {
if *attr.AttributeName == attrName {
for _, v := range attr.AttributeValues {
platforms = append(platforms, *v.AttributeValue)
}
break
}
}
if len(platforms) == 0 {
return nil, fmt.Errorf("No EC2 platforms detected")
}
return platforms, nil
}