Skip to content

Commit 1076f59

Browse files
authored
Merge pull request #28499 from hashicorp/td-apiclient-accessors
Use accessor methods for AWS SDK API clients
2 parents 88f09f9 + 6b954b4 commit 1076f59

File tree

2,766 files changed

+9483
-8253
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,766 files changed

+9483
-8253
lines changed

docs/retries-and-waiters.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ function ExampleThingCreate(d *schema.ResourceData, meta interface{}) error {
278278
}
279279

280280
function ExampleThingRead(d *schema.ResourceData, meta interface{}) error {
281-
conn := meta.(*AWSClient).exampleconn
281+
conn := meta.(*AWSClient).ExampleConn()
282282

283283
input := &example.OperationInput{/* ... */}
284284

docs/running-and-writing-acceptance-tests.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ When executing the test, the following steps are taken for each `TestStep`:
250250
return fmt.Errorf("Not found: %s", n)
251251
}
252252
253-
conn := acctest.Provider.Meta().(*conns.AWSClient).CloudWatchConn
253+
conn := acctest.Provider.Meta().(*conns.AWSClient).CloudWatchConn()
254254
params := cloudwatch.GetDashboardInput{
255255
DashboardName: aws.String(rs.Primary.ID),
256256
}
@@ -286,7 +286,7 @@ When executing the test, the following steps are taken for each `TestStep`:
286286
287287
```go
288288
func testAccCheckDashboardDestroy(s *terraform.State) error {
289-
conn := acctest.Provider.Meta().(*conns.AWSClient).CloudWatchConn
289+
conn := acctest.Provider.Meta().(*conns.AWSClient).CloudWatchConn()
290290
291291
for _, rs := range s.RootModule().Resources {
292292
if rs.Type != "aws_cloudwatch_dashboard" {
@@ -604,7 +604,7 @@ func TestAccExampleThing_basic(t *testing.T) {
604604
}
605605

606606
func testAccPreCheckExample(t *testing.T) {
607-
conn := acctest.Provider.Meta().(*conns.AWSClient).ExampleConn
607+
conn := acctest.Provider.Meta().(*conns.AWSClient).ExampleConn()
608608
input := &example.ListThingsInput{}
609609
_, err := conn.ListThings(input)
610610
if testAccPreCheckSkipError(err) {
@@ -1218,7 +1218,7 @@ func sweepThings(region string) error {
12181218
return fmt.Errorf("getting client: %w", err)
12191219
}
12201220

1221-
conn := client.(*conns.AWSClient).ExampleConn
1221+
conn := client.(*conns.AWSClient).ExampleConn()
12221222
sweepResources := make([]sweep.Sweepable, 0)
12231223
var errs *multierror.Error
12241224

@@ -1284,7 +1284,7 @@ func sweepThings(region string) error {
12841284
return fmt.Errorf("getting client: %w", err)
12851285
}
12861286

1287-
conn := client.(*conns.AWSClient).ExampleConn
1287+
conn := client.(*conns.AWSClient).ExampleConn()
12881288
sweepResources := make([]sweep.Sweepable, 0)
12891289
var errs *multierror.Error
12901290

internal/acctest/acctest.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ func PreCheckPartitionNot(t *testing.T, partitions ...string) {
753753
}
754754

755755
func PreCheckOrganizationsAccount(t *testing.T) {
756-
_, err := tforganizations.FindOrganization(Provider.Meta().(*conns.AWSClient).OrganizationsConn)
756+
_, err := tforganizations.FindOrganization(Provider.Meta().(*conns.AWSClient).OrganizationsConn())
757757

758758
if tfresource.NotFound(err) {
759759
return
@@ -767,7 +767,7 @@ func PreCheckOrganizationsAccount(t *testing.T) {
767767
}
768768

769769
func PreCheckOrganizationsEnabled(t *testing.T) {
770-
_, err := tforganizations.FindOrganization(Provider.Meta().(*conns.AWSClient).OrganizationsConn)
770+
_, err := tforganizations.FindOrganization(Provider.Meta().(*conns.AWSClient).OrganizationsConn())
771771

772772
if tfresource.NotFound(err) {
773773
t.Skip("this AWS account must be an existing member of an AWS Organization")
@@ -779,13 +779,13 @@ func PreCheckOrganizationsEnabled(t *testing.T) {
779779
}
780780

781781
func PreCheckOrganizationManagementAccount(t *testing.T) {
782-
organization, err := tforganizations.FindOrganization(Provider.Meta().(*conns.AWSClient).OrganizationsConn)
782+
organization, err := tforganizations.FindOrganization(Provider.Meta().(*conns.AWSClient).OrganizationsConn())
783783

784784
if err != nil {
785785
t.Fatalf("error describing AWS Organization: %s", err)
786786
}
787787

788-
callerIdentity, err := tfsts.FindCallerIdentity(context.Background(), Provider.Meta().(*conns.AWSClient).STSConn)
788+
callerIdentity, err := tfsts.FindCallerIdentity(context.Background(), Provider.Meta().(*conns.AWSClient).STSConn())
789789

790790
if err != nil {
791791
t.Fatalf("error getting current identity: %s", err)
@@ -797,7 +797,7 @@ func PreCheckOrganizationManagementAccount(t *testing.T) {
797797
}
798798

799799
func PreCheckSSOAdminInstances(t *testing.T) {
800-
conn := Provider.Meta().(*conns.AWSClient).SSOAdminConn
800+
conn := Provider.Meta().(*conns.AWSClient).SSOAdminConn()
801801
input := &ssoadmin.ListInstancesInput{}
802802
var instances []*ssoadmin.InstanceMetadata
803803

@@ -825,7 +825,7 @@ func PreCheckSSOAdminInstances(t *testing.T) {
825825
}
826826

827827
func PreCheckHasIAMRole(t *testing.T, roleName string) {
828-
conn := Provider.Meta().(*conns.AWSClient).IAMConn
828+
conn := Provider.Meta().(*conns.AWSClient).IAMConn()
829829

830830
input := &iam.GetRoleInput{
831831
RoleName: aws.String(roleName),
@@ -844,7 +844,7 @@ func PreCheckHasIAMRole(t *testing.T, roleName string) {
844844
}
845845

846846
func PreCheckIAMServiceLinkedRole(t *testing.T, pathPrefix string) {
847-
conn := Provider.Meta().(*conns.AWSClient).IAMConn
847+
conn := Provider.Meta().(*conns.AWSClient).IAMConn()
848848

849849
input := &iam.ListRolesInput{
850850
PathPrefix: aws.String(pathPrefix),
@@ -1349,7 +1349,7 @@ func RandomEmailAddress(domainName string) string {
13491349
}
13501350

13511351
func PreCheckOutpostsOutposts(t *testing.T) {
1352-
conn := Provider.Meta().(*conns.AWSClient).OutpostsConn
1352+
conn := Provider.Meta().(*conns.AWSClient).OutpostsConn()
13531353

13541354
input := &outposts.ListOutpostsInput{}
13551355

@@ -1418,7 +1418,7 @@ func ACMCertificateRandomSubDomain(rootDomain string) string {
14181418

14191419
func CheckACMPCACertificateAuthorityActivateRootCA(certificateAuthority *acmpca.CertificateAuthority) resource.TestCheckFunc {
14201420
return func(s *terraform.State) error {
1421-
conn := Provider.Meta().(*conns.AWSClient).ACMPCAConn
1421+
conn := Provider.Meta().(*conns.AWSClient).ACMPCAConn()
14221422

14231423
if v := aws.StringValue(certificateAuthority.Type); v != acmpca.CertificateAuthorityTypeRoot {
14241424
return fmt.Errorf("attempting to activate ACM PCA %s Certificate Authority", v)
@@ -1484,7 +1484,7 @@ func CheckACMPCACertificateAuthorityActivateRootCA(certificateAuthority *acmpca.
14841484

14851485
func CheckACMPCACertificateAuthorityActivateSubordinateCA(rootCertificateAuthority, certificateAuthority *acmpca.CertificateAuthority) resource.TestCheckFunc {
14861486
return func(s *terraform.State) error {
1487-
conn := Provider.Meta().(*conns.AWSClient).ACMPCAConn
1487+
conn := Provider.Meta().(*conns.AWSClient).ACMPCAConn()
14881488

14891489
if v := aws.StringValue(certificateAuthority.Type); v != acmpca.CertificateAuthorityTypeSubordinate {
14901490
return fmt.Errorf("attempting to activate ACM PCA %s Certificate Authority", v)
@@ -1553,7 +1553,7 @@ func CheckACMPCACertificateAuthorityActivateSubordinateCA(rootCertificateAuthori
15531553

15541554
func CheckACMPCACertificateAuthorityDisableCA(certificateAuthority *acmpca.CertificateAuthority) resource.TestCheckFunc {
15551555
return func(s *terraform.State) error {
1556-
conn := Provider.Meta().(*conns.AWSClient).ACMPCAConn
1556+
conn := Provider.Meta().(*conns.AWSClient).ACMPCAConn()
15571557

15581558
_, err := conn.UpdateCertificateAuthority(&acmpca.UpdateCertificateAuthorityInput{
15591559
CertificateAuthorityArn: certificateAuthority.Arn,
@@ -1575,7 +1575,7 @@ func CheckACMPCACertificateAuthorityExists(n string, certificateAuthority *acmpc
15751575
return fmt.Errorf("no ACM PCA Certificate Authority ID is set")
15761576
}
15771577

1578-
conn := Provider.Meta().(*conns.AWSClient).ACMPCAConn
1578+
conn := Provider.Meta().(*conns.AWSClient).ACMPCAConn()
15791579

15801580
input := &acmpca.DescribeCertificateAuthorityInput{
15811581
CertificateAuthorityArn: aws.String(rs.Primary.ID),
@@ -1605,7 +1605,7 @@ func PreCheckAPIGatewayTypeEDGE(t *testing.T) {
16051605
}
16061606

16071607
func PreCheckDirectoryService(t *testing.T) {
1608-
conn := Provider.Meta().(*conns.AWSClient).DSConn
1608+
conn := Provider.Meta().(*conns.AWSClient).DSConn()
16091609

16101610
input := &directoryservice.DescribeDirectoriesInput{}
16111611

@@ -1624,7 +1624,7 @@ func PreCheckDirectoryService(t *testing.T) {
16241624
// and we do not have a good read-only way to determine this situation. Here we
16251625
// opt to perform a creation that will fail so we can determine Simple AD support.
16261626
func PreCheckDirectoryServiceSimpleDirectory(t *testing.T) {
1627-
conn := Provider.Meta().(*conns.AWSClient).DSConn
1627+
conn := Provider.Meta().(*conns.AWSClient).DSConn()
16281628

16291629
input := &directoryservice.CreateDirectoryInput{
16301630
Name: aws.String("corp.example.com"),
@@ -1986,7 +1986,7 @@ func CheckVPCExists(n string, v *ec2.Vpc) resource.TestCheckFunc {
19861986
return fmt.Errorf("no VPC ID is set")
19871987
}
19881988

1989-
conn := Provider.Meta().(*conns.AWSClient).EC2Conn
1989+
conn := Provider.Meta().(*conns.AWSClient).EC2Conn()
19901990

19911991
output, err := tfec2.FindVPCByID(conn, rs.Primary.ID)
19921992

internal/acctest/provider_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ func testAccCheckSTSRegion(t *testing.T, p **schema.Provider, expectedRegion str
595595
return fmt.Errorf("provider not initialized")
596596
}
597597

598-
stsRegion := aws.StringValue((*p).Meta().(*conns.AWSClient).STSConn.Config.Region)
598+
stsRegion := aws.StringValue((*p).Meta().(*conns.AWSClient).STSConn().Config.Region)
599599

600600
if stsRegion != expectedRegion {
601601
return fmt.Errorf("expected STS Region (%s), got: %s", expectedRegion, stsRegion)

internal/conns/awsclient.go

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package conns
33
import (
44
"context"
55
"fmt"
6+
7+
"github.com/aws/aws-sdk-go/service/s3"
68
)
79

810
// InitContext creates context.
@@ -23,3 +25,7 @@ func (client *AWSClient) PartitionHostname(prefix string) string {
2325
func (client *AWSClient) RegionalHostname(prefix string) string {
2426
return fmt.Sprintf("%s.%s.%s", prefix, client.Region, client.DNSSuffix)
2527
}
28+
29+
func (client *AWSClient) S3ConnURICleaningDisabled() *s3.S3 {
30+
return client.s3ConnURICleaningDisabled
31+
}

0 commit comments

Comments
 (0)