Skip to content

Commit

Permalink
Add 'acctest.PreCheckInspector2'.
Browse files Browse the repository at this point in the history
  • Loading branch information
ewbankkit committed Oct 23, 2023
1 parent a5af669 commit 1547c50
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 48 deletions.
17 changes: 17 additions & 0 deletions internal/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (

"github.com/YakDriver/regexache"
ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
"github.com/aws/aws-sdk-go-v2/service/inspector2"
inspector2types "github.com/aws/aws-sdk-go-v2/service/inspector2/types"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/aws/endpoints"
Expand All @@ -41,6 +43,7 @@ import (
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/envvar"
"github.com/hashicorp/terraform-provider-aws/internal/errs"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
"github.com/hashicorp/terraform-provider-aws/internal/provider"
tfacmpca "github.com/hashicorp/terraform-provider-aws/internal/service/acmpca"
Expand Down Expand Up @@ -919,6 +922,20 @@ func PreCheckPartitionNot(t *testing.T, partitions ...string) {
}
}

func PreCheckInspector2(ctx context.Context, t *testing.T) {
conn := Provider.Meta().(*conns.AWSClient).Inspector2Client(ctx)

_, err := conn.ListDelegatedAdminAccounts(ctx, &inspector2.ListDelegatedAdminAccountsInput{})

if errs.IsA[*inspector2types.AccessDeniedException](err) {
t.Skipf("Amazon Inspector not available: %s", err)
}

if err != nil {
t.Fatalf("listing Inspector2 delegated administrators: %s", err)
}
}

func PreCheckOrganizationsAccount(ctx context.Context, t *testing.T) {
_, err := tforganizations.FindOrganization(ctx, Provider.Meta().(*conns.AWSClient).OrganizationsConn(ctx))

Expand Down
29 changes: 0 additions & 29 deletions internal/service/inspector2/acc_test.go

This file was deleted.

4 changes: 2 additions & 2 deletions internal/service/inspector2/delegated_admin_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func testAccDelegatedAdminAccount_basic(t *testing.T) {
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.Inspector2EndpointID)
testAccPreCheck(ctx, t)
acctest.PreCheckInspector2(ctx, t)
acctest.PreCheckOrganizationManagementAccount(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.Inspector2EndpointID),
Expand Down Expand Up @@ -79,7 +79,7 @@ func testAccDelegatedAdminAccount_disappears(t *testing.T) {
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.Inspector2EndpointID)
testAccPreCheck(ctx, t)
acctest.PreCheckInspector2(ctx, t)
acctest.PreCheckOrganizationManagementAccount(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.Inspector2EndpointID),
Expand Down
22 changes: 11 additions & 11 deletions internal/service/inspector2/enabler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func testAccEnabler_basic(t *testing.T) {
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.Inspector2EndpointID)
testAccPreCheck(ctx, t)
acctest.PreCheckInspector2(ctx, t)
acctest.PreCheckOrganizationManagementAccount(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.Inspector2EndpointID),
Expand Down Expand Up @@ -67,7 +67,7 @@ func testAccEnabler_accountID(t *testing.T) {
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.Inspector2EndpointID)
testAccPreCheck(ctx, t)
acctest.PreCheckInspector2(ctx, t)
acctest.PreCheckOrganizationManagementAccount(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.Inspector2EndpointID),
Expand Down Expand Up @@ -100,7 +100,7 @@ func testAccEnabler_disappears(t *testing.T) {
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.Inspector2EndpointID)
testAccPreCheck(ctx, t)
acctest.PreCheckInspector2(ctx, t)
acctest.PreCheckOrganizationManagementAccount(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.Inspector2EndpointID),
Expand Down Expand Up @@ -131,7 +131,7 @@ func testAccEnabler_updateResourceTypes(t *testing.T) {
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.Inspector2EndpointID)
testAccPreCheck(ctx, t)
acctest.PreCheckInspector2(ctx, t)
acctest.PreCheckOrganizationManagementAccount(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.Inspector2EndpointID),
Expand Down Expand Up @@ -187,7 +187,7 @@ func testAccEnabler_updateResourceTypes_disjoint(t *testing.T) {
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.Inspector2EndpointID)
testAccPreCheck(ctx, t)
acctest.PreCheckInspector2(ctx, t)
acctest.PreCheckOrganizationManagementAccount(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.Inspector2EndpointID),
Expand Down Expand Up @@ -230,7 +230,7 @@ func testAccEnabler_lambda(t *testing.T) {
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.Inspector2EndpointID)
testAccPreCheck(ctx, t)
acctest.PreCheckInspector2(ctx, t)
acctest.PreCheckOrganizationManagementAccount(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.Inspector2EndpointID),
Expand Down Expand Up @@ -264,7 +264,7 @@ func testAccEnabler_memberAccount_basic(t *testing.T) {
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.Inspector2EndpointID)
testAccPreCheck(ctx, t)
acctest.PreCheckInspector2(ctx, t)
acctest.PreCheckOrganizationManagementAccount(ctx, t)
acctest.PreCheckAlternateAccount(t)
},
Expand Down Expand Up @@ -299,7 +299,7 @@ func testAccEnabler_memberAccount_disappearsMemberAssociation(t *testing.T) {
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.Inspector2EndpointID)
testAccPreCheck(ctx, t)
acctest.PreCheckInspector2(ctx, t)
acctest.PreCheckOrganizationManagementAccount(ctx, t)
acctest.PreCheckAlternateAccount(t)
},
Expand Down Expand Up @@ -331,7 +331,7 @@ func testAccEnabler_memberAccount_multiple(t *testing.T) {
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.Inspector2EndpointID)
testAccPreCheck(ctx, t)
acctest.PreCheckInspector2(ctx, t)
acctest.PreCheckOrganizationManagementAccount(ctx, t)
acctest.PreCheckAlternateAccount(t)
acctest.PreCheckThirdAccount(t)
Expand Down Expand Up @@ -371,7 +371,7 @@ func testAccEnabler_memberAccount_updateMemberAccounts(t *testing.T) {
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.Inspector2EndpointID)
testAccPreCheck(ctx, t)
acctest.PreCheckInspector2(ctx, t)
acctest.PreCheckOrganizationManagementAccount(ctx, t)
acctest.PreCheckAlternateAccount(t)
acctest.PreCheckThirdAccount(t)
Expand Down Expand Up @@ -439,7 +439,7 @@ func testAccEnabler_memberAccount_updateMemberAccountsAndScanTypes(t *testing.T)
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.Inspector2EndpointID)
testAccPreCheck(ctx, t)
acctest.PreCheckInspector2(ctx, t)
acctest.PreCheckOrganizationManagementAccount(ctx, t)
acctest.PreCheckAlternateAccount(t)
acctest.PreCheckThirdAccount(t)
Expand Down
4 changes: 2 additions & 2 deletions internal/service/inspector2/member_association_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func testAccMemberAssociation_basic(t *testing.T) {
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.Inspector2EndpointID)
testAccPreCheck(ctx, t)
acctest.PreCheckInspector2(ctx, t)
acctest.PreCheckOrganizationManagementAccount(ctx, t)
acctest.PreCheckAlternateAccount(t)
},
Expand Down Expand Up @@ -61,7 +61,7 @@ func testAccMemberAssociation_disappears(t *testing.T) {
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.Inspector2EndpointID)
testAccPreCheck(ctx, t)
acctest.PreCheckInspector2(ctx, t)
acctest.PreCheckOrganizationManagementAccount(ctx, t)
acctest.PreCheckAlternateAccount(t)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func testAccOrganizationConfiguration_basic(t *testing.T) {
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.Inspector2EndpointID)
testAccPreCheck(ctx, t)
acctest.PreCheckInspector2(ctx, t)
acctest.PreCheckOrganizationManagementAccount(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.Inspector2EndpointID),
Expand All @@ -57,7 +57,7 @@ func testAccOrganizationConfiguration_disappears(t *testing.T) {
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.Inspector2EndpointID)
testAccPreCheck(ctx, t)
acctest.PreCheckInspector2(ctx, t)
acctest.PreCheckOrganizationManagementAccount(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.Inspector2EndpointID),
Expand All @@ -84,7 +84,7 @@ func testAccOrganizationConfiguration_ec2ECR(t *testing.T) {
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.Inspector2EndpointID)
testAccPreCheck(ctx, t)
acctest.PreCheckInspector2(ctx, t)
acctest.PreCheckOrganizationManagementAccount(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.Inspector2EndpointID),
Expand All @@ -111,7 +111,7 @@ func testAccOrganizationConfiguration_lambda(t *testing.T) {
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.Inspector2EndpointID)
testAccPreCheck(ctx, t)
acctest.PreCheckInspector2(ctx, t)
acctest.PreCheckOrganizationManagementAccount(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.Inspector2EndpointID),
Expand Down

0 comments on commit 1547c50

Please sign in to comment.