Skip to content

Commit

Permalink
Merge pull request #30862 from huetterma/b-aws_ce_cost_category-neste…
Browse files Browse the repository at this point in the history
…d-operands-closes-30810

AWS_CE_COST_CATEGORY: be able to use nested operands like you can via aws api
  • Loading branch information
ewbankkit committed Apr 19, 2024
2 parents 4cabfb5 + 1d00481 commit 6e64c8e
Show file tree
Hide file tree
Showing 7 changed files with 316 additions and 341 deletions.
3 changes: 3 additions & 0 deletions .changelog/30862.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_ce_cost_category: Allow up to 3 levels of `and`, not` and `or` operand nesting for the `rule` argument
```
12 changes: 8 additions & 4 deletions internal/service/ce/anomaly_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ import (
"github.com/hashicorp/terraform-provider-aws/names"
)

const (
anomalySubscriptionRootElementSchemaLevel = 2
)

// @SDKResource("aws_ce_anomaly_subscription", name="Anomaly Subscription")
// @Tags(identifierAttribute="id")
func resourceAnomalySubscription() *schema.Resource {
Expand Down Expand Up @@ -96,7 +100,7 @@ func resourceAnomalySubscription() *schema.Resource {
MaxItems: 1,
Computed: true,
Optional: true,
Elem: elemExpression(),
Elem: expressionElem(anomalySubscriptionRootElementSchemaLevel),
},
},

Expand Down Expand Up @@ -124,7 +128,7 @@ func resourceAnomalySubscriptionCreate(ctx context.Context, d *schema.ResourceDa
}

if v, ok := d.GetOk("threshold_expression"); ok {
input.AnomalySubscription.ThresholdExpression = expandCostExpression(v.([]interface{})[0].(map[string]interface{}))
input.AnomalySubscription.ThresholdExpression = expandExpression(v.([]interface{})[0].(map[string]interface{}))
}

output, err := conn.CreateAnomalySubscription(ctx, input)
Expand Down Expand Up @@ -160,7 +164,7 @@ func resourceAnomalySubscriptionRead(ctx context.Context, d *schema.ResourceData
d.Set("monitor_arn_list", subscription.MonitorArnList)
d.Set("name", subscription.SubscriptionName)
d.Set("subscriber", flattenSubscribers(subscription.Subscribers))
if err := d.Set("threshold_expression", []interface{}{flattenCostCategoryRuleExpression(subscription.ThresholdExpression)}); err != nil {
if err := d.Set("threshold_expression", []interface{}{flattenExpression(subscription.ThresholdExpression)}); err != nil {
return sdkdiag.AppendErrorf(diags, "setting threshold_expression: %s", err)
}

Expand Down Expand Up @@ -190,7 +194,7 @@ func resourceAnomalySubscriptionUpdate(ctx context.Context, d *schema.ResourceDa
}

if d.HasChange("threshold_expression") {
input.ThresholdExpression = expandCostExpression(d.Get("threshold_expression").([]interface{})[0].(map[string]interface{}))
input.ThresholdExpression = expandExpression(d.Get("threshold_expression").([]interface{})[0].(map[string]interface{}))
}

_, err := conn.UpdateAnomalySubscription(ctx, input)
Expand Down
Loading

0 comments on commit 6e64c8e

Please sign in to comment.