diff --git a/.changelog/40521.txt b/.changelog/40521.txt new file mode 100644 index 00000000000..afb7dfc00ca --- /dev/null +++ b/.changelog/40521.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_ce_cost_category: Change `rule` from `TypeSet` to `TypeList` as order is significant +``` diff --git a/internal/service/ce/anomaly_monitor_test.go b/internal/service/ce/anomaly_monitor_test.go index 0243a1dade0..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) }, + 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) }, + 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) }, + 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) }, + 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) }, + 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 66ff8d74d25..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) }, + 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) }, + 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) }, + 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) }, + 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) }, + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckPayerAccount(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); 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.go b/internal/service/ce/cost_category.go index 1b3c48d0182..64124ac44df 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)), } @@ -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)), } 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 dc72865dfef..337533f642e 100644 --- a/internal/service/ce/cost_category_test.go +++ b/internal/service/ce/cost_category_test.go @@ -30,18 +30,22 @@ 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), 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, acctest.CtRulePound, "3"), + resource.TestCheckResourceAttr(resourceName, "rule.0.value", "production"), + resource.TestCheckResourceAttr(resourceName, "rule.1.value", "staging"), + resource.TestCheckResourceAttr(resourceName, "rule.2.value", "testing"), ), }, { @@ -66,7 +70,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 +107,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 +131,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 +166,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 +194,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 +229,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,14 +268,15 @@ 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) _, 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") } 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{