Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed deprecated field threshold from resource aws_ce_anomaly_subscription #30374

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/30374.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:breaking-change
resource/aws_ce_anomaly_subscription: The `threshold` attribute has been removed
```
16 changes: 0 additions & 16 deletions internal/service/ce/anomaly_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,6 @@ func ResourceAnomalySubscription() *schema.Resource {
},
},
},
"threshold": {
Type: schema.TypeFloat,
Optional: true,
Computed: true,
ValidateFunc: validation.FloatAtLeast(0.0),
Deprecated: "use threshold_expression instead",
},
"threshold_expression": {
Type: schema.TypeList,
MaxItems: 1,
Expand Down Expand Up @@ -117,10 +110,6 @@ func resourceAnomalySubscriptionCreate(ctx context.Context, d *schema.ResourceDa
input.AnomalySubscription.AccountId = aws.String(v.(string))
}

if v, ok := d.GetOk("threshold"); ok {
input.AnomalySubscription.Threshold = aws.Float64(v.(float64)) //nolint:staticcheck // see https://github.com/hashicorp/terraform-provider-aws/issues/30326
}

if v, ok := d.GetOk("threshold_expression"); ok {
input.AnomalySubscription.ThresholdExpression = expandCostExpression(v.([]interface{})[0].(map[string]interface{}))
}
Expand Down Expand Up @@ -160,7 +149,6 @@ func resourceAnomalySubscriptionRead(ctx context.Context, d *schema.ResourceData
d.Set("frequency", subscription.Frequency)
d.Set("monitor_arn_list", subscription.MonitorArnList)
d.Set("subscriber", flattenAnomalySubscriptionSubscribers(subscription.Subscribers))
d.Set("threshold", subscription.Threshold) //nolint:staticcheck // see https://github.com/hashicorp/terraform-provider-aws/issues/30326
d.Set("name", subscription.SubscriptionName)

if err = d.Set("threshold_expression", []interface{}{flattenCostCategoryRuleExpression(subscription.ThresholdExpression)}); err != nil {
Expand Down Expand Up @@ -190,10 +178,6 @@ func resourceAnomalySubscriptionUpdate(ctx context.Context, d *schema.ResourceDa
input.Subscribers = expandAnomalySubscriptionSubscribers(d.Get("subscriber").(*schema.Set).List())
}

if d.HasChange("threshold") {
input.Threshold = aws.Float64(d.Get("threshold").(float64)) //nolint:staticcheck // see https://github.com/hashicorp/terraform-provider-aws/issues/30326
}

if d.HasChange("threshold_expression") {
input.ThresholdExpression = expandCostExpression(d.Get("threshold_expression").([]interface{})[0].(map[string]interface{}))
}
Expand Down
167 changes: 50 additions & 117 deletions internal/service/ce/anomaly_subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,38 +44,6 @@ func TestAccCEAnomalySubscription_basic(t *testing.T) {
resource.TestCheckResourceAttrSet(resourceName, "monitor_arn_list.#"),
resource.TestCheckResourceAttr(resourceName, "subscriber.0.type", "EMAIL"),
resource.TestCheckResourceAttr(resourceName, "subscriber.0.address", address),
resource.TestCheckResourceAttr(resourceName, "threshold", "100"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccCEAnomalySubscription_thresholdExpression(t *testing.T) {
ctx := acctest.Context(t)
var subscription costexplorer.AnomalySubscription
resourceName := "aws_ce_anomaly_subscription.test"
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
domain := acctest.RandomDomainName()
address := acctest.RandomEmailAddress(domain)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckAnomalySubscriptionDestroy(ctx),
ErrorCheck: acctest.ErrorCheck(t, costexplorer.EndpointsID),
Steps: []resource.TestStep{
{
Config: testAccAnomalySubscriptionConfig_thresholdExpression(rName, address),
Check: resource.ComposeTestCheckFunc(
testAccCheckAnomalySubscriptionExists(ctx, resourceName, &subscription),
resource.TestCheckResourceAttr(resourceName, "name", rName),
// resource.TestCheckResourceAttr(resourceName, "threshold", "100"),
),
},
{
Expand Down Expand Up @@ -257,43 +225,6 @@ func TestAccCEAnomalySubscription_Subscriber(t *testing.T) {
})
}

func TestAccCEAnomalySubscription_Threshold(t *testing.T) {
ctx := acctest.Context(t)
var subscription costexplorer.AnomalySubscription
resourceName := "aws_ce_anomaly_subscription.test"
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
domain := acctest.RandomDomainName()
address := acctest.RandomEmailAddress(domain)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckAnomalySubscriptionDestroy(ctx),
ErrorCheck: acctest.ErrorCheck(t, costexplorer.EndpointsID),
Steps: []resource.TestStep{
{
Config: testAccAnomalySubscriptionConfig_threshold(rName, 100, address),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAnomalySubscriptionExists(ctx, resourceName, &subscription),
resource.TestCheckResourceAttr(resourceName, "threshold", "100"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccAnomalySubscriptionConfig_threshold(rName, 200, address),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAnomalySubscriptionExists(ctx, resourceName, &subscription),
resource.TestCheckResourceAttr(resourceName, "threshold", "200"),
),
},
},
})
}

func TestAccCEAnomalySubscription_Tags(t *testing.T) {
ctx := acctest.Context(t)
var subscription costexplorer.AnomalySubscription
Expand Down Expand Up @@ -426,27 +357,6 @@ func testAccAnomalySubscriptionConfig_basic(rName string, address string) string
return acctest.ConfigCompose(
testAccAnomalySubscriptionConfigBase(rName),
fmt.Sprintf(`
resource "aws_ce_anomaly_subscription" "test" {
name = %[1]q
threshold = 100
frequency = "DAILY"

monitor_arn_list = [
aws_ce_anomaly_monitor.test.arn,
]

subscriber {
type = "EMAIL"
address = %[2]q
}
}
`, rName, address))
}

func testAccAnomalySubscriptionConfig_thresholdExpression(rName string, address string) string {
return acctest.ConfigCompose(
testAccAnomalySubscriptionConfigBase(rName),
fmt.Sprintf(`
resource "aws_ce_anomaly_subscription" "test" {
name = %[1]q
frequency = "DAILY"
Expand Down Expand Up @@ -499,17 +409,25 @@ resource "aws_ce_anomaly_monitor" "test2" {

resource "aws_ce_anomaly_subscription" "test" {
name = %[1]q
threshold = 100
frequency = "WEEKLY"

monitor_arn_list = [
aws_ce_anomaly_monitor.test.arn,
aws_ce_anomaly_monitor.test2.arn,
]

subscriber {
type = "EMAIL"
address = %[3]q
}

threshold_expression {
dimension {
key = "ANOMALY_TOTAL_IMPACT_ABSOLUTE"
values = ["100.0"]
match_options = ["GREATER_THAN_OR_EQUAL"]
}
}
}
`, rName, rName2, address))
}
Expand All @@ -520,7 +438,6 @@ func testAccAnomalySubscriptionConfig_frequency(rName string, rFrequency string,
fmt.Sprintf(`
resource "aws_ce_anomaly_subscription" "test" {
name = %[1]q
threshold = 100
frequency = %[2]q

monitor_arn_list = [
Expand All @@ -531,6 +448,14 @@ resource "aws_ce_anomaly_subscription" "test" {
type = "EMAIL"
address = %[3]q
}

threshold_expression {
dimension {
key = "ANOMALY_TOTAL_IMPACT_ABSOLUTE"
values = ["100.0"]
match_options = ["GREATER_THAN_OR_EQUAL"]
}
}
}
`, rName, rFrequency, address))
}
Expand All @@ -541,7 +466,6 @@ func testAccAnomalySubscriptionConfig_subscriber2(rName string, address1 string,
fmt.Sprintf(`
resource "aws_ce_anomaly_subscription" "test" {
name = %[1]q
threshold = 100
frequency = "WEEKLY"

monitor_arn_list = [
Expand All @@ -552,10 +476,19 @@ resource "aws_ce_anomaly_subscription" "test" {
type = "EMAIL"
address = %[2]q
}

subscriber {
type = "EMAIL"
address = %[3]q
}

threshold_expression {
dimension {
key = "ANOMALY_TOTAL_IMPACT_ABSOLUTE"
values = ["100.0"]
match_options = ["GREATER_THAN_OR_EQUAL"]
}
}
}
`, rName, address1, address2))
}
Expand Down Expand Up @@ -637,7 +570,6 @@ resource "aws_sns_topic_policy" "test" {

resource "aws_ce_anomaly_subscription" "test" {
name = %[1]q
threshold = 100000000
frequency = "IMMEDIATE"

monitor_arn_list = [
Expand All @@ -649,41 +581,27 @@ resource "aws_ce_anomaly_subscription" "test" {
address = aws_sns_topic.test.arn
}

threshold_expression {
dimension {
key = "ANOMALY_TOTAL_IMPACT_ABSOLUTE"
values = ["100.0"]
match_options = ["GREATER_THAN_OR_EQUAL"]
}
}

depends_on = [
aws_sns_topic_policy.test,
]
}
`, rName))
}

func testAccAnomalySubscriptionConfig_threshold(rName string, rThreshold int, address string) string {
return acctest.ConfigCompose(
testAccAnomalySubscriptionConfigBase(rName),
fmt.Sprintf(`
resource "aws_ce_anomaly_subscription" "test" {
name = %[1]q
threshold = %[2]d
frequency = "WEEKLY"

monitor_arn_list = [
aws_ce_anomaly_monitor.test.arn,
]

subscriber {
type = "EMAIL"
address = %[3]q
}
}
`, rName, rThreshold, address))
}

func testAccAnomalySubscriptionConfig_tags1(rName string, tagKey1, tagValue1 string, address string) string {
return acctest.ConfigCompose(
testAccAnomalySubscriptionConfigBase(rName),
fmt.Sprintf(`
resource "aws_ce_anomaly_subscription" "test" {
name = %[1]q
threshold = 100
frequency = "DAILY"

monitor_arn_list = [
Expand All @@ -695,6 +613,14 @@ resource "aws_ce_anomaly_subscription" "test" {
address = %[4]q
}

threshold_expression {
dimension {
key = "ANOMALY_TOTAL_IMPACT_ABSOLUTE"
values = ["100.0"]
match_options = ["GREATER_THAN_OR_EQUAL"]
}
}

tags = {
%[2]q = %[3]q
}
Expand All @@ -708,7 +634,6 @@ func testAccAnomalySubscriptionConfig_tags2(rName, tagKey1, tagValue1, tagKey2,
fmt.Sprintf(`
resource "aws_ce_anomaly_subscription" "test" {
name = %[1]q
threshold = 100
frequency = "DAILY"

monitor_arn_list = [
Expand All @@ -720,6 +645,14 @@ resource "aws_ce_anomaly_subscription" "test" {
address = %[6]q
}

threshold_expression {
dimension {
key = "ANOMALY_TOTAL_IMPACT_ABSOLUTE"
values = ["100.0"]
match_options = ["GREATER_THAN_OR_EQUAL"]
}
}

tags = {
%[2]q = %[3]q
%[4]q = %[5]q
Expand Down
5 changes: 5 additions & 0 deletions website/docs/guides/version-5-upgrade.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Upgrade topics:
- [Data Source: aws_redshift_service_account](#data-source-aws_redshift_service_account)
- [Data Source: aws_subnet_ids](#data-source-aws_subnet_ids)
- [Resource: aws_acmpca_certificate_authority](#resource-aws_acmpca_certificate_authority)
- [Resource: aws_ce_anomaly_subscription](#resource-aws_ce_anomaly_subscription)

<!-- /TOC -->

Expand Down Expand Up @@ -76,6 +77,10 @@ provider "aws" {

The `status` attribute is superfluous and sometimes incorrect. It has been removed.

## Resource: aws_ce_anomaly_subscription

The `threshold` attribute has been removed.

## Data Source: aws_redshift_service_account

[AWS document](https://docs.aws.amazon.com/redshift/latest/mgmt/db-auditing.html#db-auditing-bucket-permissions) that [a service principal name](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_principal.html#principal-services) be used instead of AWS account ID in any relevant IAM policy.
Expand Down