Skip to content

Commit

Permalink
Merge pull request hashicorp#38529 from acwwat/td-aws_ce-add_payer_pr…
Browse files Browse the repository at this point in the history
…echeck

chore: Add payer account precheck for CE tests
  • Loading branch information
jar-b authored Jul 29, 2024
2 parents 46ebf64 + 90fa9c8 commit 9d23db3
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
33 changes: 33 additions & 0 deletions internal/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/aws/aws-sdk-go-v2/service/acmpca"
acmpcatypes "github.com/aws/aws-sdk-go-v2/service/acmpca/types"
"github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider"
"github.com/aws/aws-sdk-go-v2/service/costexplorer"
"github.com/aws/aws-sdk-go-v2/service/directoryservice"
dstypes "github.com/aws/aws-sdk-go-v2/service/directoryservice/types"
ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
Expand Down Expand Up @@ -1009,6 +1010,38 @@ func PreCheckCognitoIdentityProvider(ctx context.Context, t *testing.T) {
}
}

func PreCheckCECostAllocationTagPayerAccount(ctx context.Context, t *testing.T) {
t.Helper()

conn := Provider.Meta().(*conns.AWSClient).CEClient(ctx)

_, err := conn.ListCostAllocationTags(ctx, &costexplorer.ListCostAllocationTagsInput{})

if errs.MessageContains(err, "AccessDeniedException", "Linked account doesn't have access to") {
t.Skip("skipping tests; this AWS account must be a payer account")
}

if err != nil {
t.Fatalf("listing Cost Explorer Cost Allocation Tags: %s", err)
}
}

func PreCheckCECostCategoryPayerAccount(ctx context.Context, t *testing.T) {
t.Helper()

conn := Provider.Meta().(*conns.AWSClient).CEClient(ctx)

_, err := conn.ListCostCategoryDefinitions(ctx, &costexplorer.ListCostCategoryDefinitionsInput{})

if errs.MessageContains(err, "AccessDeniedException", "Linked account doesn't have access to") {
t.Skip("skipping tests; this AWS account must be a payer account")
}

if err != nil {
t.Fatalf("listing Cost Explorer Cost Categories: %s", err)
}
}

func PreCheckInspector2(ctx context.Context, t *testing.T) {
t.Helper()

Expand Down
4 changes: 2 additions & 2 deletions internal/service/ce/cost_allocation_tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestAccCECostAllocationTag_basic(t *testing.T) {
rName := "Tag01"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckCECostAllocationTagPayerAccount(ctx, t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckCostAllocationTagDestroy(ctx),
ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID),
Expand Down Expand Up @@ -71,7 +71,7 @@ func TestAccCECostAllocationTag_disappears(t *testing.T) {
rName := "Tag02"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckCECostAllocationTagPayerAccount(ctx, t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckCostAllocationTagDestroy(ctx),
ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID),
Expand Down
2 changes: 1 addition & 1 deletion internal/service/ce/cost_category_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestAccCECostCategoryDataSource_basic(t *testing.T) {
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckCECostCategoryPayerAccount(ctx, t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID),
Steps: []resource.TestStep{
Expand Down
14 changes: 7 additions & 7 deletions internal/service/ce/cost_category_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestAccCECostCategory_basic(t *testing.T) {
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckCECostCategoryPayerAccount(ctx, t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckCostCategoryDestroy(ctx),
ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID),
Expand Down Expand Up @@ -64,7 +64,7 @@ func TestAccCECostCategory_effectiveStart(t *testing.T) {
firstOfLastMonth := firstDayOfMonth(now.AddDate(0, -1, 0))

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckCECostCategoryPayerAccount(ctx, t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckCostCategoryDestroy(ctx),
ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID),
Expand Down Expand Up @@ -101,7 +101,7 @@ func TestAccCECostCategory_disappears(t *testing.T) {
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckCECostCategoryPayerAccount(ctx, t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckCostCategoryDestroy(ctx),
ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID),
Expand All @@ -125,7 +125,7 @@ func TestAccCECostCategory_complete(t *testing.T) {
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckCECostCategoryPayerAccount(ctx, t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckCostCategoryDestroy(ctx),
ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID),
Expand Down Expand Up @@ -160,7 +160,7 @@ func TestAccCECostCategory_notWithAnd(t *testing.T) {
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckCECostCategoryPayerAccount(ctx, t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckCostCategoryDestroy(ctx),
ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID),
Expand Down Expand Up @@ -188,7 +188,7 @@ func TestAccCECostCategory_splitCharge(t *testing.T) {
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckCECostCategoryPayerAccount(ctx, t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckCostCategoryDestroy(ctx),
ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID),
Expand Down Expand Up @@ -223,7 +223,7 @@ func TestAccCECostCategory_tags(t *testing.T) {
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckCECostCategoryPayerAccount(ctx, t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckCostCategoryDestroy(ctx),
ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID),
Expand Down

0 comments on commit 9d23db3

Please sign in to comment.