From 1547c5087e13eeed7f656c93ce546da3d3107c07 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 23 Oct 2023 11:22:37 -0400 Subject: [PATCH] Add 'acctest.PreCheckInspector2'. --- internal/acctest/acctest.go | 17 +++++++++++ internal/service/inspector2/acc_test.go | 29 ------------------- .../delegated_admin_account_test.go | 4 +-- internal/service/inspector2/enabler_test.go | 22 +++++++------- .../inspector2/member_association_test.go | 4 +-- .../organization_configuration_test.go | 8 ++--- 6 files changed, 36 insertions(+), 48 deletions(-) delete mode 100644 internal/service/inspector2/acc_test.go diff --git a/internal/acctest/acctest.go b/internal/acctest/acctest.go index 9f151c73a12..77b29874192 100644 --- a/internal/acctest/acctest.go +++ b/internal/acctest/acctest.go @@ -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" @@ -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" @@ -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)) diff --git a/internal/service/inspector2/acc_test.go b/internal/service/inspector2/acc_test.go deleted file mode 100644 index 62ceafe4f96..00000000000 --- a/internal/service/inspector2/acc_test.go +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package inspector2_test - -import ( - "context" - "testing" - - "github.com/aws/aws-sdk-go-v2/service/inspector2" - "github.com/aws/aws-sdk-go-v2/service/inspector2/types" - "github.com/hashicorp/terraform-provider-aws/internal/acctest" - "github.com/hashicorp/terraform-provider-aws/internal/conns" - "github.com/hashicorp/terraform-provider-aws/internal/errs" -) - -func testAccPreCheck(ctx context.Context, t *testing.T) { - conn := acctest.Provider.Meta().(*conns.AWSClient).Inspector2Client(ctx) - - _, err := conn.ListDelegatedAdminAccounts(ctx, &inspector2.ListDelegatedAdminAccountsInput{}) - - if errs.IsA[*types.AccessDeniedException](err) { - t.Skipf("skipping acceptance testing: %s", err) - } - - if err != nil { - t.Fatalf("unexpected PreCheck error: %s", err) - } -} diff --git a/internal/service/inspector2/delegated_admin_account_test.go b/internal/service/inspector2/delegated_admin_account_test.go index adf3ad3dd03..9cfdb5f905b 100644 --- a/internal/service/inspector2/delegated_admin_account_test.go +++ b/internal/service/inspector2/delegated_admin_account_test.go @@ -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), @@ -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), diff --git a/internal/service/inspector2/enabler_test.go b/internal/service/inspector2/enabler_test.go index db3898ab31d..e16da5d37e4 100644 --- a/internal/service/inspector2/enabler_test.go +++ b/internal/service/inspector2/enabler_test.go @@ -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), @@ -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), @@ -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), @@ -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), @@ -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), @@ -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), @@ -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) }, @@ -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) }, @@ -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) @@ -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) @@ -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) diff --git a/internal/service/inspector2/member_association_test.go b/internal/service/inspector2/member_association_test.go index 2908f133ac4..320d4b384fc 100644 --- a/internal/service/inspector2/member_association_test.go +++ b/internal/service/inspector2/member_association_test.go @@ -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) }, @@ -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) }, diff --git a/internal/service/inspector2/organization_configuration_test.go b/internal/service/inspector2/organization_configuration_test.go index e9e9389771c..ce25b150978 100644 --- a/internal/service/inspector2/organization_configuration_test.go +++ b/internal/service/inspector2/organization_configuration_test.go @@ -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), @@ -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), @@ -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), @@ -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),