From 3ae5a06a5d2d128c2d9f2aabb908d0d86e0087b0 Mon Sep 17 00:00:00 2001 From: Andrew Tulloch Date: Wed, 11 Dec 2024 09:52:00 +0000 Subject: [PATCH 01/11] Add test for rule ordering, change TypeSet to TypeList to support ordering --- internal/service/ce/cost_category.go | 4 ++-- internal/service/ce/cost_category_test.go | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/service/ce/cost_category.go b/internal/service/ce/cost_category.go index 1b3c48d0182..b1e1f8c6559 100644 --- a/internal/service/ce/cost_category.go +++ b/internal/service/ce/cost_category.go @@ -72,7 +72,7 @@ func resourceCostCategory() *schema.Resource { ValidateFunc: validation.StringLenBetween(1, 50), }, names.AttrRule: { - Type: schema.TypeSet, + Type: schema.TypeList, Required: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -305,7 +305,7 @@ func resourceCostCategoryCreate(ctx context.Context, d *schema.ResourceData, met input := &costexplorer.CreateCostCategoryDefinitionInput{ Name: aws.String(name), ResourceTags: getTagsIn(ctx), - Rules: expandCostCategoryRules(d.Get(names.AttrRule).(*schema.Set).List()), + Rules: expandCostCategoryRules(d.Get(names.AttrRule).([]interface{})), RuleVersion: awstypes.CostCategoryRuleVersion(d.Get("rule_version").(string)), } diff --git a/internal/service/ce/cost_category_test.go b/internal/service/ce/cost_category_test.go index dc72865dfef..7953bdf0928 100644 --- a/internal/service/ce/cost_category_test.go +++ b/internal/service/ce/cost_category_test.go @@ -42,6 +42,9 @@ func TestAccCECostCategory_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, names.AttrName, rName), resource.TestCheckResourceAttrSet(resourceName, "effective_start"), acctest.MatchResourceAttrGlobalARN(ctx, resourceName, names.AttrARN, "ce", regexache.MustCompile(`costcategory/.+$`)), + resource.TestCheckResourceAttr(resourceName, "rule.0.value", "production"), + resource.TestCheckResourceAttr(resourceName, "rule.1.value", "staging"), + resource.TestCheckResourceAttr(resourceName, "rule.2.value", "testing"), ), }, { From 81f298231fd6d139ea45227526d52a29d45d97ab Mon Sep 17 00:00:00 2001 From: Andrew Tulloch Date: Wed, 11 Dec 2024 09:57:18 +0000 Subject: [PATCH 02/11] Change type when reading --- internal/service/ce/cost_category.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/ce/cost_category.go b/internal/service/ce/cost_category.go index b1e1f8c6559..64124ac44df 100644 --- a/internal/service/ce/cost_category.go +++ b/internal/service/ce/cost_category.go @@ -375,7 +375,7 @@ func resourceCostCategoryUpdate(ctx context.Context, d *schema.ResourceData, met input := &costexplorer.UpdateCostCategoryDefinitionInput{ CostCategoryArn: aws.String(d.Id()), EffectiveStart: aws.String(d.Get("effective_start").(string)), - Rules: expandCostCategoryRules(d.Get(names.AttrRule).(*schema.Set).List()), + Rules: expandCostCategoryRules(d.Get(names.AttrRule).([]interface{})), RuleVersion: awstypes.CostCategoryRuleVersion(d.Get("rule_version").(string)), } From 0cc80ec93a0f180a4d77dde1591084b3e309e3b7 Mon Sep 17 00:00:00 2001 From: Andrew Tulloch Date: Wed, 11 Dec 2024 09:59:44 +0000 Subject: [PATCH 03/11] Changelog --- .changelog/40521.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/40521.txt diff --git a/.changelog/40521.txt b/.changelog/40521.txt new file mode 100644 index 00000000000..253bb6ced45 --- /dev/null +++ b/.changelog/40521.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_ce_cost_category: Fix ordering of rules by changing `rule` from Set to List. +```% From 5847b5926731fcba54ae6724c54a55b55479a532 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 11 Dec 2024 10:48:33 -0500 Subject: [PATCH 04/11] r/aws_ce_anomaly_monitor: Skip acceptance tests raising 'ValidationException: Linked accounts can only create AWS Services monitor'. --- internal/service/ce/anomaly_monitor_test.go | 10 +++++----- internal/service/ce/cost_category_test.go | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/internal/service/ce/anomaly_monitor_test.go b/internal/service/ce/anomaly_monitor_test.go index 0243a1dade0..79386f5c480 100644 --- a/internal/service/ce/anomaly_monitor_test.go +++ b/internal/service/ce/anomaly_monitor_test.go @@ -27,7 +27,7 @@ func TestAccCEAnomalyMonitor_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); testAccPreCheckCostCategoryPayerAccount(ctx, t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAnomalyMonitorDestroy(ctx), ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID), @@ -58,7 +58,7 @@ func TestAccCEAnomalyMonitor_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); testAccPreCheckCostCategoryPayerAccount(ctx, t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAnomalyMonitorDestroy(ctx), ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID), @@ -83,7 +83,7 @@ func TestAccCEAnomalyMonitor_update(t *testing.T) { rName2 := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckCostCategoryPayerAccount(ctx, t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAnomalyMonitorDestroy(ctx), ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID), @@ -118,7 +118,7 @@ func TestAccCEAnomalyMonitor_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); testAccPreCheckCostCategoryPayerAccount(ctx, t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAnomalyMonitorDestroy(ctx), ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID), @@ -167,7 +167,7 @@ func TestAccCEAnomalyMonitor_Dimensional(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); testAccPreCheckCostCategoryPayerAccount(ctx, t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAnomalyMonitorDestroy(ctx), ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID), diff --git a/internal/service/ce/cost_category_test.go b/internal/service/ce/cost_category_test.go index dc72865dfef..6df8a46f9e2 100644 --- a/internal/service/ce/cost_category_test.go +++ b/internal/service/ce/cost_category_test.go @@ -271,7 +271,8 @@ func testAccPreCheckCostCategoryPayerAccount(ctx context.Context, t *testing.T) _, err := conn.ListCostCategoryDefinitions(ctx, &costexplorer.ListCostCategoryDefinitionsInput{}) - if tfawserr.ErrMessageContains(err, "AccessDeniedException", "Linked account doesn't have access to") { + if tfawserr.ErrMessageContains(err, "AccessDeniedException", "Linked account doesn't have access to") || + tfawserr.ErrMessageContains(err, "ValidationException", "Linked accounts can only create") { t.Skip("skipping tests; this AWS account must be a payer account") } From 184c2ed74153a5bcbe2df070ed15f9e3607142b9 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 11 Dec 2024 10:50:22 -0500 Subject: [PATCH 05/11] r/aws_ce_anomaly_subscription: Skip acceptance tests raising 'ValidationException: Linked accounts can only create AWS Services monitor'. --- internal/service/ce/anomaly_subscription_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/service/ce/anomaly_subscription_test.go b/internal/service/ce/anomaly_subscription_test.go index 66ff8d74d25..7dff2579e6c 100644 --- a/internal/service/ce/anomaly_subscription_test.go +++ b/internal/service/ce/anomaly_subscription_test.go @@ -29,7 +29,7 @@ func TestAccCEAnomalySubscription_basic(t *testing.T) { address := acctest.RandomEmailAddress(domain) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckCostCategoryPayerAccount(ctx, t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAnomalySubscriptionDestroy(ctx), ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID), @@ -65,7 +65,7 @@ func TestAccCEAnomalySubscription_disappears(t *testing.T) { address := acctest.RandomEmailAddress(domain) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckCostCategoryPayerAccount(ctx, t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAnomalySubscriptionDestroy(ctx), ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID), @@ -91,7 +91,7 @@ func TestAccCEAnomalySubscription_Frequency(t *testing.T) { address := acctest.RandomEmailAddress(domain) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckCostCategoryPayerAccount(ctx, t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAnomalySubscriptionDestroy(ctx), ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID), @@ -129,7 +129,7 @@ func TestAccCEAnomalySubscription_MonitorARNList(t *testing.T) { address := acctest.RandomEmailAddress(domain) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckCostCategoryPayerAccount(ctx, t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAnomalySubscriptionDestroy(ctx), ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID), @@ -168,7 +168,7 @@ func TestAccCEAnomalySubscription_Subscriber(t *testing.T) { address2 := acctest.RandomEmailAddress(domain) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckCostCategoryPayerAccount(ctx, t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAnomalySubscriptionDestroy(ctx), ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID), @@ -226,7 +226,7 @@ func TestAccCEAnomalySubscription_Subscriber(t *testing.T) { }) } -func TestAccCEAnomalySubscription_Tags(t *testing.T) { +func TestAccCEAnomalySubscription_tags(t *testing.T) { ctx := acctest.Context(t) var subscription awstypes.AnomalySubscription resourceName := "aws_ce_anomaly_subscription.test" @@ -235,7 +235,7 @@ func TestAccCEAnomalySubscription_Tags(t *testing.T) { address := acctest.RandomEmailAddress(domain) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckCostCategoryPayerAccount(ctx, t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAnomalySubscriptionDestroy(ctx), ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID), From 6e76a21453601f06c226aa6e0800456534f2fc6a Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 11 Dec 2024 10:52:10 -0500 Subject: [PATCH 06/11] r/aws_ce_cost_allocation_tag: Skip acceptance tests raising 'ValidationException: Linked accounts can only create AWS Services monitor'. --- internal/service/ce/anomaly_monitor_test.go | 10 ++++----- .../service/ce/anomaly_subscription_test.go | 12 +++++----- .../service/ce/cost_allocation_tag_test.go | 22 ++----------------- .../ce/cost_category_data_source_test.go | 2 +- internal/service/ce/cost_category_test.go | 16 +++++++------- 5 files changed, 22 insertions(+), 40 deletions(-) diff --git a/internal/service/ce/anomaly_monitor_test.go b/internal/service/ce/anomaly_monitor_test.go index 79386f5c480..1f7ea05c970 100644 --- a/internal/service/ce/anomaly_monitor_test.go +++ b/internal/service/ce/anomaly_monitor_test.go @@ -27,7 +27,7 @@ func TestAccCEAnomalyMonitor_basic(t *testing.T) { rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckCostCategoryPayerAccount(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckPayerAccount(ctx, t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAnomalyMonitorDestroy(ctx), ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID), @@ -58,7 +58,7 @@ func TestAccCEAnomalyMonitor_disappears(t *testing.T) { rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckCostCategoryPayerAccount(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckPayerAccount(ctx, t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAnomalyMonitorDestroy(ctx), ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID), @@ -83,7 +83,7 @@ func TestAccCEAnomalyMonitor_update(t *testing.T) { rName2 := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckCostCategoryPayerAccount(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckPayerAccount(ctx, t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAnomalyMonitorDestroy(ctx), ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID), @@ -118,7 +118,7 @@ func TestAccCEAnomalyMonitor_tags(t *testing.T) { rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckCostCategoryPayerAccount(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckPayerAccount(ctx, t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAnomalyMonitorDestroy(ctx), ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID), @@ -167,7 +167,7 @@ func TestAccCEAnomalyMonitor_Dimensional(t *testing.T) { rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckCostCategoryPayerAccount(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckPayerAccount(ctx, t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAnomalyMonitorDestroy(ctx), ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID), diff --git a/internal/service/ce/anomaly_subscription_test.go b/internal/service/ce/anomaly_subscription_test.go index 7dff2579e6c..356cd00ebf4 100644 --- a/internal/service/ce/anomaly_subscription_test.go +++ b/internal/service/ce/anomaly_subscription_test.go @@ -29,7 +29,7 @@ func TestAccCEAnomalySubscription_basic(t *testing.T) { address := acctest.RandomEmailAddress(domain) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckCostCategoryPayerAccount(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckPayerAccount(ctx, t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAnomalySubscriptionDestroy(ctx), ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID), @@ -65,7 +65,7 @@ func TestAccCEAnomalySubscription_disappears(t *testing.T) { address := acctest.RandomEmailAddress(domain) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckCostCategoryPayerAccount(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckPayerAccount(ctx, t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAnomalySubscriptionDestroy(ctx), ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID), @@ -91,7 +91,7 @@ func TestAccCEAnomalySubscription_Frequency(t *testing.T) { address := acctest.RandomEmailAddress(domain) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckCostCategoryPayerAccount(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckPayerAccount(ctx, t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAnomalySubscriptionDestroy(ctx), ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID), @@ -129,7 +129,7 @@ func TestAccCEAnomalySubscription_MonitorARNList(t *testing.T) { address := acctest.RandomEmailAddress(domain) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckCostCategoryPayerAccount(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckPayerAccount(ctx, t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAnomalySubscriptionDestroy(ctx), ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID), @@ -168,7 +168,7 @@ func TestAccCEAnomalySubscription_Subscriber(t *testing.T) { address2 := acctest.RandomEmailAddress(domain) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckCostCategoryPayerAccount(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckPayerAccount(ctx, t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAnomalySubscriptionDestroy(ctx), ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID), @@ -235,7 +235,7 @@ func TestAccCEAnomalySubscription_tags(t *testing.T) { address := acctest.RandomEmailAddress(domain) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckCostCategoryPayerAccount(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckPayerAccount(ctx, t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAnomalySubscriptionDestroy(ctx), ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID), diff --git a/internal/service/ce/cost_allocation_tag_test.go b/internal/service/ce/cost_allocation_tag_test.go index dc26a701b82..b669943b26a 100644 --- a/internal/service/ce/cost_allocation_tag_test.go +++ b/internal/service/ce/cost_allocation_tag_test.go @@ -8,9 +8,7 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go-v2/service/costexplorer" awstypes "github.com/aws/aws-sdk-go-v2/service/costexplorer/types" - "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-aws/internal/acctest" @@ -26,7 +24,7 @@ func TestAccCECostAllocationTag_basic(t *testing.T) { rName := "Tag01" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckCostAllocationTagPayerAccount(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckPayerAccount(ctx, t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckCostAllocationTagDestroy(ctx), ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID), @@ -73,7 +71,7 @@ func TestAccCECostAllocationTag_disappears(t *testing.T) { rName := "Tag02" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckCostAllocationTagPayerAccount(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckPayerAccount(ctx, t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckCostAllocationTagDestroy(ctx), ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID), @@ -90,22 +88,6 @@ func TestAccCECostAllocationTag_disappears(t *testing.T) { }) } -func testAccPreCheckCostAllocationTagPayerAccount(ctx context.Context, t *testing.T) { - t.Helper() - - conn := acctest.Provider.Meta().(*conns.AWSClient).CEClient(ctx) - - _, err := conn.ListCostAllocationTags(ctx, &costexplorer.ListCostAllocationTagsInput{}) - - if tfawserr.ErrMessageContains(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 testAccCheckCostAllocationTagExists(ctx context.Context, n string, v *awstypes.CostAllocationTag) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] diff --git a/internal/service/ce/cost_category_data_source_test.go b/internal/service/ce/cost_category_data_source_test.go index 531fd639115..418288fece8 100644 --- a/internal/service/ce/cost_category_data_source_test.go +++ b/internal/service/ce/cost_category_data_source_test.go @@ -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); testAccPreCheckCostCategoryPayerAccount(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckPayerAccount(ctx, t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID), Steps: []resource.TestStep{ diff --git a/internal/service/ce/cost_category_test.go b/internal/service/ce/cost_category_test.go index 6df8a46f9e2..fe84cc28528 100644 --- a/internal/service/ce/cost_category_test.go +++ b/internal/service/ce/cost_category_test.go @@ -30,7 +30,7 @@ func TestAccCECostCategory_basic(t *testing.T) { rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckCostCategoryPayerAccount(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckPayerAccount(ctx, t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckCostCategoryDestroy(ctx), ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID), @@ -66,7 +66,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); testAccPreCheckCostCategoryPayerAccount(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckPayerAccount(ctx, t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckCostCategoryDestroy(ctx), ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID), @@ -103,7 +103,7 @@ func TestAccCECostCategory_disappears(t *testing.T) { rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckCostCategoryPayerAccount(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckPayerAccount(ctx, t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckCostCategoryDestroy(ctx), ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID), @@ -127,7 +127,7 @@ func TestAccCECostCategory_complete(t *testing.T) { rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckCostCategoryPayerAccount(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckPayerAccount(ctx, t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckCostCategoryDestroy(ctx), ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID), @@ -162,7 +162,7 @@ func TestAccCECostCategory_notWithAnd(t *testing.T) { rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckCostCategoryPayerAccount(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckPayerAccount(ctx, t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckCostCategoryDestroy(ctx), ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID), @@ -190,7 +190,7 @@ func TestAccCECostCategory_splitCharge(t *testing.T) { rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckCostCategoryPayerAccount(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckPayerAccount(ctx, t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckCostCategoryDestroy(ctx), ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID), @@ -225,7 +225,7 @@ func TestAccCECostCategory_tags(t *testing.T) { rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckCostCategoryPayerAccount(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckPayerAccount(ctx, t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckCostCategoryDestroy(ctx), ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID), @@ -264,7 +264,7 @@ func TestAccCECostCategory_tags(t *testing.T) { }) } -func testAccPreCheckCostCategoryPayerAccount(ctx context.Context, t *testing.T) { +func testAccPreCheckPayerAccount(ctx context.Context, t *testing.T) { t.Helper() conn := acctest.Provider.Meta().(*conns.AWSClient).CEClient(ctx) From 786075e6cf1724c2a079a983d76c0a177f2c2490 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 11 Dec 2024 10:53:13 -0500 Subject: [PATCH 07/11] d/aws_ce_tags: Skip acceptance tests raising 'ValidationException: Linked accounts can only create AWS Services monitor'. --- internal/service/ce/tags_data_source_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/service/ce/tags_data_source_test.go b/internal/service/ce/tags_data_source_test.go index 12d9f1c916b..26f875d36bc 100644 --- a/internal/service/ce/tags_data_source_test.go +++ b/internal/service/ce/tags_data_source_test.go @@ -29,7 +29,7 @@ func TestAccCETagsDataSource_basic(t *testing.T) { endDate := currentTime.Format(formatDate) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckPayerAccount(ctx, t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID), Steps: []resource.TestStep{ @@ -58,7 +58,7 @@ func TestAccCETagsDataSource_filter(t *testing.T) { endDate := currentTime.Format(formatDate) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckPayerAccount(ctx, t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, ErrorCheck: acctest.ErrorCheck(t, names.CEServiceID), Steps: []resource.TestStep{ From c3900a87f0f9390c7151d58a28087ac172834c8b Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 11 Dec 2024 10:55:05 -0500 Subject: [PATCH 08/11] Acceptance test output: % make testacc TESTARGS='-run=TestAccCE' PKG=ce make: Verifying source code with gofmt... ==> Checking that code complies with gofmt requirements... TF_ACC=1 go1.23.3 test ./internal/service/ce/... -v -count 1 -parallel 20 -run=TestAccCE -timeout 360m 2024/12/11 10:53:53 Initializing Terraform AWS Provider... === RUN TestAccCEAnomalyMonitor_basic === PAUSE TestAccCEAnomalyMonitor_basic === RUN TestAccCEAnomalyMonitor_disappears === PAUSE TestAccCEAnomalyMonitor_disappears === RUN TestAccCEAnomalyMonitor_update === PAUSE TestAccCEAnomalyMonitor_update === RUN TestAccCEAnomalyMonitor_tags === PAUSE TestAccCEAnomalyMonitor_tags === RUN TestAccCEAnomalyMonitor_Dimensional === PAUSE TestAccCEAnomalyMonitor_Dimensional === RUN TestAccCEAnomalySubscription_basic === PAUSE TestAccCEAnomalySubscription_basic === RUN TestAccCEAnomalySubscription_disappears === PAUSE TestAccCEAnomalySubscription_disappears === RUN TestAccCEAnomalySubscription_Frequency === PAUSE TestAccCEAnomalySubscription_Frequency === RUN TestAccCEAnomalySubscription_MonitorARNList === PAUSE TestAccCEAnomalySubscription_MonitorARNList === RUN TestAccCEAnomalySubscription_Subscriber === PAUSE TestAccCEAnomalySubscription_Subscriber === RUN TestAccCEAnomalySubscription_tags === PAUSE TestAccCEAnomalySubscription_tags === RUN TestAccCECostAllocationTag_basic === PAUSE TestAccCECostAllocationTag_basic === RUN TestAccCECostAllocationTag_disappears === PAUSE TestAccCECostAllocationTag_disappears === RUN TestAccCECostCategoryDataSource_basic === PAUSE TestAccCECostCategoryDataSource_basic === RUN TestAccCECostCategory_basic === PAUSE TestAccCECostCategory_basic === RUN TestAccCECostCategory_effectiveStart === PAUSE TestAccCECostCategory_effectiveStart === RUN TestAccCECostCategory_disappears === PAUSE TestAccCECostCategory_disappears === RUN TestAccCECostCategory_complete === PAUSE TestAccCECostCategory_complete === RUN TestAccCECostCategory_notWithAnd === PAUSE TestAccCECostCategory_notWithAnd === RUN TestAccCECostCategory_splitCharge === PAUSE TestAccCECostCategory_splitCharge === RUN TestAccCECostCategory_tags === PAUSE TestAccCECostCategory_tags === RUN TestAccCETagsDataSource_basic === PAUSE TestAccCETagsDataSource_basic === RUN TestAccCETagsDataSource_filter === PAUSE TestAccCETagsDataSource_filter === CONT TestAccCEAnomalyMonitor_basic === CONT TestAccCECostAllocationTag_disappears === CONT TestAccCECostCategory_notWithAnd === CONT TestAccCECostCategory_effectiveStart === CONT TestAccCECostCategory_complete === CONT TestAccCECostCategory_disappears === CONT TestAccCECostCategory_basic === CONT TestAccCEAnomalySubscription_disappears === CONT TestAccCECostAllocationTag_basic === CONT TestAccCEAnomalySubscription_tags === CONT TestAccCEAnomalySubscription_Subscriber === CONT TestAccCEAnomalySubscription_MonitorARNList === CONT TestAccCEAnomalySubscription_Frequency === CONT TestAccCECostCategoryDataSource_basic === CONT TestAccCEAnomalyMonitor_tags === CONT TestAccCEAnomalySubscription_basic === CONT TestAccCEAnomalyMonitor_Dimensional === CONT TestAccCETagsDataSource_basic === CONT TestAccCETagsDataSource_filter === CONT TestAccCEAnomalyMonitor_update === NAME TestAccCECostAllocationTag_disappears cost_allocation_tag_test.go:74: skipping tests; this AWS account must be a payer account === NAME TestAccCECostCategoryDataSource_basic cost_category_data_source_test.go:24: skipping tests; this AWS account must be a payer account --- SKIP: TestAccCECostAllocationTag_disappears (0.60s) === CONT TestAccCECostCategory_tags --- SKIP: TestAccCECostCategoryDataSource_basic (0.60s) === CONT TestAccCECostCategory_splitCharge === NAME TestAccCEAnomalyMonitor_Dimensional anomaly_monitor_test.go:170: skipping tests; this AWS account must be a payer account === NAME TestAccCECostCategory_complete cost_category_test.go:130: skipping tests; this AWS account must be a payer account --- SKIP: TestAccCEAnomalyMonitor_Dimensional (0.60s) === NAME TestAccCECostCategory_disappears cost_category_test.go:106: skipping tests; this AWS account must be a payer account --- SKIP: TestAccCECostCategory_complete (0.60s) --- SKIP: TestAccCECostCategory_disappears (0.60s) === CONT TestAccCEAnomalyMonitor_disappears === NAME TestAccCECostCategory_effectiveStart cost_category_test.go:69: skipping tests; this AWS account must be a payer account --- SKIP: TestAccCECostCategory_effectiveStart (0.61s) === NAME TestAccCEAnomalySubscription_Subscriber anomaly_subscription_test.go:171: skipping tests; this AWS account must be a payer account --- SKIP: TestAccCEAnomalySubscription_Subscriber (0.61s) === NAME TestAccCECostCategory_basic cost_category_test.go:33: skipping tests; this AWS account must be a payer account --- SKIP: TestAccCECostCategory_basic (0.61s) === NAME TestAccCEAnomalyMonitor_update anomaly_monitor_test.go:86: skipping tests; this AWS account must be a payer account --- SKIP: TestAccCEAnomalyMonitor_update (0.62s) === NAME TestAccCEAnomalySubscription_disappears anomaly_subscription_test.go:68: skipping tests; this AWS account must be a payer account --- SKIP: TestAccCEAnomalySubscription_disappears (0.62s) === NAME TestAccCECostAllocationTag_basic cost_allocation_tag_test.go:27: skipping tests; this AWS account must be a payer account --- SKIP: TestAccCECostAllocationTag_basic (0.62s) === NAME TestAccCEAnomalyMonitor_tags anomaly_monitor_test.go:121: skipping tests; this AWS account must be a payer account --- SKIP: TestAccCEAnomalyMonitor_tags (0.62s) === NAME TestAccCEAnomalyMonitor_basic anomaly_monitor_test.go:30: skipping tests; this AWS account must be a payer account --- SKIP: TestAccCEAnomalyMonitor_basic (0.62s) === NAME TestAccCEAnomalySubscription_Frequency anomaly_subscription_test.go:94: skipping tests; this AWS account must be a payer account --- SKIP: TestAccCEAnomalySubscription_Frequency (0.62s) === NAME TestAccCEAnomalySubscription_MonitorARNList anomaly_subscription_test.go:132: skipping tests; this AWS account must be a payer account --- SKIP: TestAccCEAnomalySubscription_MonitorARNList (0.62s) === NAME TestAccCECostCategory_notWithAnd cost_category_test.go:165: skipping tests; this AWS account must be a payer account --- SKIP: TestAccCECostCategory_notWithAnd (0.62s) === NAME TestAccCETagsDataSource_basic tags_data_source_test.go:32: skipping tests; this AWS account must be a payer account --- SKIP: TestAccCETagsDataSource_basic (0.62s) === NAME TestAccCEAnomalySubscription_tags anomaly_subscription_test.go:238: skipping tests; this AWS account must be a payer account --- SKIP: TestAccCEAnomalySubscription_tags (0.62s) === NAME TestAccCEAnomalySubscription_basic anomaly_subscription_test.go:32: skipping tests; this AWS account must be a payer account --- SKIP: TestAccCEAnomalySubscription_basic (0.63s) === NAME TestAccCETagsDataSource_filter tags_data_source_test.go:61: skipping tests; this AWS account must be a payer account --- SKIP: TestAccCETagsDataSource_filter (0.63s) === NAME TestAccCECostCategory_splitCharge cost_category_test.go:193: skipping tests; this AWS account must be a payer account --- SKIP: TestAccCECostCategory_splitCharge (0.10s) === NAME TestAccCEAnomalyMonitor_disappears anomaly_monitor_test.go:61: skipping tests; this AWS account must be a payer account --- SKIP: TestAccCEAnomalyMonitor_disappears (0.10s) === NAME TestAccCECostCategory_tags cost_category_test.go:228: skipping tests; this AWS account must be a payer account --- SKIP: TestAccCECostCategory_tags (0.12s) PASS ok github.com/hashicorp/terraform-provider-aws/internal/service/ce 5.950s From 0d3feec7663578a44fedcfdf56dddcb1da11c589 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 11 Dec 2024 10:57:53 -0500 Subject: [PATCH 09/11] Tweak CHANGELOG entry. --- .changelog/40521.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changelog/40521.txt b/.changelog/40521.txt index 253bb6ced45..afb7dfc00ca 100644 --- a/.changelog/40521.txt +++ b/.changelog/40521.txt @@ -1,3 +1,3 @@ ```release-note:bug -resource/aws_ce_cost_category: Fix ordering of rules by changing `rule` from Set to List. -```% +resource/aws_ce_cost_category: Change `rule` from `TypeSet` to `TypeList` as order is significant +``` From c8fcc033f69a15e22577a63bc558a976557e6bf1 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 11 Dec 2024 10:59:34 -0500 Subject: [PATCH 10/11] Tweak 'TestAccCECostCategory_basic'. --- internal/service/ce/cost_category_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/service/ce/cost_category_test.go b/internal/service/ce/cost_category_test.go index b9dc61fe2f3..0b9eded6dd1 100644 --- a/internal/service/ce/cost_category_test.go +++ b/internal/service/ce/cost_category_test.go @@ -37,11 +37,12 @@ func TestAccCECostCategory_basic(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccCostCategoryConfig_basic(rName), - Check: resource.ComposeTestCheckFunc( + Check: resource.ComposeAggregateTestCheckFunc( testAccCheckCostCategoryExists(ctx, resourceName, &output), - resource.TestCheckResourceAttr(resourceName, names.AttrName, rName), - resource.TestCheckResourceAttrSet(resourceName, "effective_start"), acctest.MatchResourceAttrGlobalARN(ctx, resourceName, names.AttrARN, "ce", regexache.MustCompile(`costcategory/.+$`)), + resource.TestCheckResourceAttrSet(resourceName, "effective_start"), + resource.TestCheckResourceAttr(resourceName, names.AttrName, rName), + resource.TestCheckResourceAttr(resourceName, "rule.#", "3"), resource.TestCheckResourceAttr(resourceName, "rule.0.value", "production"), resource.TestCheckResourceAttr(resourceName, "rule.1.value", "staging"), resource.TestCheckResourceAttr(resourceName, "rule.2.value", "testing"), From 4d5ebc798fdcdd053f42e1a8ce0790dc0b49cf53 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 11 Dec 2024 11:29:05 -0500 Subject: [PATCH 11/11] Fix semgrep 'ci.literal-RulePound-string-test-constant'. --- internal/service/ce/cost_category_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/ce/cost_category_test.go b/internal/service/ce/cost_category_test.go index 0b9eded6dd1..337533f642e 100644 --- a/internal/service/ce/cost_category_test.go +++ b/internal/service/ce/cost_category_test.go @@ -42,7 +42,7 @@ func TestAccCECostCategory_basic(t *testing.T) { acctest.MatchResourceAttrGlobalARN(ctx, resourceName, names.AttrARN, "ce", regexache.MustCompile(`costcategory/.+$`)), resource.TestCheckResourceAttrSet(resourceName, "effective_start"), resource.TestCheckResourceAttr(resourceName, names.AttrName, rName), - resource.TestCheckResourceAttr(resourceName, "rule.#", "3"), + resource.TestCheckResourceAttr(resourceName, acctest.CtRulePound, "3"), resource.TestCheckResourceAttr(resourceName, "rule.0.value", "production"), resource.TestCheckResourceAttr(resourceName, "rule.1.value", "staging"), resource.TestCheckResourceAttr(resourceName, "rule.2.value", "testing"),