From eb34f96ea17913ec029db0935ab57c04ff91b1f8 Mon Sep 17 00:00:00 2001 From: teowa <104055472+teowa@users.noreply.github.com> Date: Thu, 26 Sep 2024 05:51:35 +0000 Subject: [PATCH 1/7] fix comsumption issue --- .../consumption/consumption_budget_base.go | 115 +----------------- 1 file changed, 2 insertions(+), 113 deletions(-) diff --git a/internal/services/consumption/consumption_budget_base.go b/internal/services/consumption/consumption_budget_base.go index 66352fad38fc..f716446b8b94 100644 --- a/internal/services/consumption/consumption_budget_base.go +++ b/internal/services/consumption/consumption_budget_base.go @@ -12,7 +12,6 @@ import ( "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-sdk/resource-manager/consumption/2019-10-01/budgets" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" - "github.com/hashicorp/terraform-provider-azurerm/internal/features" "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" "github.com/hashicorp/terraform-provider-azurerm/internal/services/consumption/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -159,7 +158,7 @@ func (br consumptionBudgetBaseResource) arguments(fields map[string]*pluginsdk.S Type: pluginsdk.TypeString, Optional: true, Default: string(budgets.ThresholdTypeActual), - ForceNew: true, // TODO: remove this when the above issue is fixed + // ForceNew: true, // TODO: remove this when the above issue is fixed ValidateFunc: validation.StringInSlice([]string{ string(budgets.ThresholdTypeActual), "Forecasted", @@ -244,82 +243,6 @@ func (br consumptionBudgetBaseResource) arguments(fields map[string]*pluginsdk.S }, } - if !features.FourPointOhBeta() { - output["filter"].Elem.(*pluginsdk.Resource).Schema["not"] = &pluginsdk.Schema{ - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Deprecated: "This property has been deprecated as the API no longer supports it and will be removed in version 4.0 of the provider.", - AtLeastOneOf: []string{"filter.0.dimension", "filter.0.tag", "filter.0.not"}, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "dimension": { - Type: pluginsdk.TypeList, - MaxItems: 1, - Optional: true, - ExactlyOneOf: []string{"filter.0.not.0.tag"}, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "name": { - Type: pluginsdk.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice(getDimensionNames(), false), - }, - "operator": { - Type: pluginsdk.TypeString, - Optional: true, - Default: "In", - ValidateFunc: validation.StringInSlice([]string{ - "In", - }, false), - }, - "values": { - Type: pluginsdk.TypeList, - MinItems: 1, - Required: true, - Elem: &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - ValidateFunc: validation.StringIsNotEmpty, - }, - }, - }, - }, - }, - "tag": { - Type: pluginsdk.TypeList, - MaxItems: 1, - Optional: true, - ExactlyOneOf: []string{"filter.0.not.0.dimension"}, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "name": { - Type: pluginsdk.TypeString, - Required: true, - }, - "operator": { - Type: pluginsdk.TypeString, - Optional: true, - Default: "In", - ValidateFunc: validation.StringInSlice([]string{ - "In", - }, false), - }, - "values": { - Type: pluginsdk.TypeList, - Required: true, - Elem: &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - ValidateFunc: validation.StringIsNotEmpty, - }, - }, - }, - }, - }, - }, - }, - } - } - // Consumption Budgets for Management Groups have a different notification schema, // here we override the notification schema in the base resource for k, v := range fields { @@ -384,7 +307,7 @@ func (br consumptionBudgetBaseResource) readFunc(scopeFieldName string) sdk.Reso } metadata.ResourceData.Set("name", id.BudgetName) - //lintignore:R001 + // lintignore:R001 metadata.ResourceData.Set(scopeFieldName, id.Scope) if model := resp.Model; model != nil { @@ -700,22 +623,6 @@ func expandConsumptionBudgetFilter(i []interface{}) *budgets.BudgetFilter { filter := budgets.BudgetFilter{} - if !features.FourPointOhBeta() { - notBlock := input["not"].([]interface{}) - if len(notBlock) != 0 && notBlock[0] != nil { - not := notBlock[0].(map[string]interface{}) - - tags := expandConsumptionBudgetFilterTag(not["tag"].([]interface{})) - dimensions := expandConsumptionBudgetFilterDimensions(not["dimension"].([]interface{})) - - if len(dimensions) != 0 { - filter.Not = &dimensions[0] - } else if len(tags) != 0 { - filter.Not = &tags[0] - } - } - } - tags := expandConsumptionBudgetFilterTag(input["tag"].(*pluginsdk.Set).List()) dimensions := expandConsumptionBudgetFilterDimensions(input["dimension"].(*pluginsdk.Set).List()) @@ -756,24 +663,6 @@ func flattenConsumptionBudgetFilter(input *budgets.BudgetFilter) []interface{} { filterBlock := make(map[string]interface{}) - if !features.FourPointOhBeta() { - notBlock := make(map[string]interface{}) - - if input.Not != nil { - if input.Not.Dimensions != nil { - notBlock["dimension"] = []interface{}{flattenConsumptionBudgetComparisonExpression(input.Not.Dimensions)} - } - - if input.Not.Tags != nil { - notBlock["tag"] = []interface{}{flattenConsumptionBudgetComparisonExpression(input.Not.Tags)} - } - - if len(notBlock) != 0 { - filterBlock["not"] = []interface{}{notBlock} - } - } - } - if input.And != nil { for _, v := range *input.And { if v.Dimensions != nil { From 35155dba82380c84a7c6e090690b8068e505d803 Mon Sep 17 00:00:00 2001 From: teowa <104055472+teowa@users.noreply.github.com> Date: Thu, 26 Sep 2024 09:45:46 +0000 Subject: [PATCH 2/7] remove forcenew for threshold_type --- internal/services/consumption/consumption_budget_base.go | 4 ---- .../consumption_budget_management_group_resource.go | 4 ---- .../consumption_budget_resource_group_resource_test.go | 4 +--- .../docs/r/consumption_budget_management_group.html.markdown | 2 +- .../docs/r/consumption_budget_resource_group.html.markdown | 2 +- website/docs/r/consumption_budget_subscription.html.markdown | 2 +- 6 files changed, 4 insertions(+), 14 deletions(-) diff --git a/internal/services/consumption/consumption_budget_base.go b/internal/services/consumption/consumption_budget_base.go index f716446b8b94..f696549427a2 100644 --- a/internal/services/consumption/consumption_budget_base.go +++ b/internal/services/consumption/consumption_budget_base.go @@ -151,14 +151,10 @@ func (br consumptionBudgetBaseResource) arguments(fields map[string]*pluginsdk.S Required: true, ValidateFunc: validation.IntBetween(0, 1000), }, - // Issue: https://github.com/Azure/azure-rest-api-specs/issues/16240 - // Toggling between these two values doesn't work at the moment and also doesn't throw an error - // but it seems unlikely that a user would switch the threshold_type of their budgets frequently "threshold_type": { Type: pluginsdk.TypeString, Optional: true, Default: string(budgets.ThresholdTypeActual), - // ForceNew: true, // TODO: remove this when the above issue is fixed ValidateFunc: validation.StringInSlice([]string{ string(budgets.ThresholdTypeActual), "Forecasted", diff --git a/internal/services/consumption/consumption_budget_management_group_resource.go b/internal/services/consumption/consumption_budget_management_group_resource.go index d3703daab6b9..2895b985ae13 100644 --- a/internal/services/consumption/consumption_budget_management_group_resource.go +++ b/internal/services/consumption/consumption_budget_management_group_resource.go @@ -54,14 +54,10 @@ func (r ManagementGroupConsumptionBudget) Arguments() map[string]*pluginsdk.Sche Required: true, ValidateFunc: validation.IntBetween(0, 1000), }, - // Issue: https://github.com/Azure/azure-rest-api-specs/issues/16240 - // Toggling between these two values doesn't work at the moment and also doesn't throw an error - // but it seems unlikely that a user would switch the threshold_type of their budgets frequently "threshold_type": { Type: pluginsdk.TypeString, Optional: true, Default: string(budgets.ThresholdTypeActual), - ForceNew: true, // TODO: remove this when the above issue is fixed ValidateFunc: validation.StringInSlice([]string{ string(budgets.ThresholdTypeActual), "Forecasted", diff --git a/internal/services/consumption/consumption_budget_resource_group_resource_test.go b/internal/services/consumption/consumption_budget_resource_group_resource_test.go index a0eb6810140f..93500da662d4 100644 --- a/internal/services/consumption/consumption_budget_resource_group_resource_test.go +++ b/internal/services/consumption/consumption_budget_resource_group_resource_test.go @@ -407,9 +407,7 @@ resource "azurerm_consumption_budget_resource_group" "test" { enabled = true threshold = 90.0 operator = "EqualTo" - // We don't update the value of threshold_type because toggling between the two seems to be broken - // See the comment on threshold_type in the schema for more details - threshold_type = "Forecasted" + threshold_type = "Actual" contact_emails = [ "baz@example.com", diff --git a/website/docs/r/consumption_budget_management_group.html.markdown b/website/docs/r/consumption_budget_management_group.html.markdown index 31dbdb2cd9c6..2a606f399f54 100644 --- a/website/docs/r/consumption_budget_management_group.html.markdown +++ b/website/docs/r/consumption_budget_management_group.html.markdown @@ -112,7 +112,7 @@ A `notification` block supports the following: * `contact_emails` - (Required) Specifies a list of email addresses to send the budget notification to when the threshold is exceeded. -* `threshold_type` - (Optional) The type of threshold for the notification. This determines whether the notification is triggered by forecasted costs or actual costs. The allowed values are `Actual` and `Forecasted`. Default is `Actual`. Changing this forces a new resource to be created. +* `threshold_type` - (Optional) The type of threshold for the notification. This determines whether the notification is triggered by forecasted costs or actual costs. The allowed values are `Actual` and `Forecasted`. Default is `Actual`. * `enabled` - (Optional) Should the notification be enabled? Defaults to `true`. diff --git a/website/docs/r/consumption_budget_resource_group.html.markdown b/website/docs/r/consumption_budget_resource_group.html.markdown index 3f9700574558..45231361aad5 100644 --- a/website/docs/r/consumption_budget_resource_group.html.markdown +++ b/website/docs/r/consumption_budget_resource_group.html.markdown @@ -120,7 +120,7 @@ A `notification` block supports the following: * `threshold` - (Required) Threshold value associated with a notification. Notification is sent when the cost exceeded the threshold. It is always percent and has to be between 0 and 1000. -* `threshold_type` - (Optional) The type of threshold for the notification. This determines whether the notification is triggered by forecasted costs or actual costs. The allowed values are `Actual` and `Forecasted`. Default is `Actual`. Changing this forces a new resource to be created. +* `threshold_type` - (Optional) The type of threshold for the notification. This determines whether the notification is triggered by forecasted costs or actual costs. The allowed values are `Actual` and `Forecasted`. Default is `Actual`. * `contact_emails` - (Optional) Specifies a list of email addresses to send the budget notification to when the threshold is exceeded. diff --git a/website/docs/r/consumption_budget_subscription.html.markdown b/website/docs/r/consumption_budget_subscription.html.markdown index 17c20a26f1c0..2fcc3027873b 100644 --- a/website/docs/r/consumption_budget_subscription.html.markdown +++ b/website/docs/r/consumption_budget_subscription.html.markdown @@ -124,7 +124,7 @@ A `notification` block supports the following: * `threshold` - (Required) Threshold value associated with a notification. Notification is sent when the cost exceeded the threshold. It is always percent and has to be between 0 and 1000. -* `threshold_type` - (Optional) The type of threshold for the notification. This determines whether the notification is triggered by forecasted costs or actual costs. The allowed values are `Actual` and `Forecasted`. Default is `Actual`. Changing this forces a new resource to be created. +* `threshold_type` - (Optional) The type of threshold for the notification. This determines whether the notification is triggered by forecasted costs or actual costs. The allowed values are `Actual` and `Forecasted`. Default is `Actual`. * `contact_emails` - (Optional) Specifies a list of email addresses to send the budget notification to when the threshold is exceeded. From 4b8157e9e4861da4f7e76e8ea3dcf0113d901d03 Mon Sep 17 00:00:00 2001 From: teowa <104055472+teowa@users.noreply.github.com> Date: Thu, 26 Sep 2024 10:00:38 +0000 Subject: [PATCH 3/7] terrafmt --- .../consumption_budget_resource_group_resource_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/services/consumption/consumption_budget_resource_group_resource_test.go b/internal/services/consumption/consumption_budget_resource_group_resource_test.go index 93500da662d4..235f8229e2db 100644 --- a/internal/services/consumption/consumption_budget_resource_group_resource_test.go +++ b/internal/services/consumption/consumption_budget_resource_group_resource_test.go @@ -404,9 +404,9 @@ resource "azurerm_consumption_budget_resource_group" "test" { } notification { - enabled = true - threshold = 90.0 - operator = "EqualTo" + enabled = true + threshold = 90.0 + operator = "EqualTo" threshold_type = "Actual" contact_emails = [ From f4153e3ae830e55f43015863220649766813ebbf Mon Sep 17 00:00:00 2001 From: teowa <104055472+teowa@users.noreply.github.com> Date: Fri, 27 Sep 2024 06:13:48 +0000 Subject: [PATCH 4/7] link issue --- internal/services/consumption/consumption_budget_base.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/services/consumption/consumption_budget_base.go b/internal/services/consumption/consumption_budget_base.go index f696549427a2..a6994bcea0b8 100644 --- a/internal/services/consumption/consumption_budget_base.go +++ b/internal/services/consumption/consumption_budget_base.go @@ -151,6 +151,7 @@ func (br consumptionBudgetBaseResource) arguments(fields map[string]*pluginsdk.S Required: true, ValidateFunc: validation.IntBetween(0, 1000), }, + // Issue: https://github.com/Azure/azure-rest-api-specs/issues/16240 "threshold_type": { Type: pluginsdk.TypeString, Optional: true, From 28f2fb671ce601f624e00e87f21ddd6b74b8948c Mon Sep 17 00:00:00 2001 From: teowa <104055472+teowa@users.noreply.github.com> Date: Mon, 21 Oct 2024 08:10:08 +0000 Subject: [PATCH 5/7] skip delete error on 404 --- internal/services/consumption/consumption_budget_base.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/services/consumption/consumption_budget_base.go b/internal/services/consumption/consumption_budget_base.go index a6994bcea0b8..cf1f45ac61a8 100644 --- a/internal/services/consumption/consumption_budget_base.go +++ b/internal/services/consumption/consumption_budget_base.go @@ -338,8 +338,10 @@ func (br consumptionBudgetBaseResource) deleteFunc() sdk.ResourceFunc { return err } - if _, err = client.Delete(ctx, *id); err != nil { - return fmt.Errorf("deleting %s: %+v", *id, err) + if resp, err := client.Delete(ctx, *id); err != nil { + if !response.WasNotFound(resp.HttpResponse) { + return fmt.Errorf("deleting %s: %+v", *id, err) + } } return nil From d95a6b02d27a132264859ef2a89b037e63ed3116 Mon Sep 17 00:00:00 2001 From: teowa <104055472+teowa@users.noreply.github.com> Date: Wed, 23 Oct 2024 02:40:38 +0000 Subject: [PATCH 6/7] remove linked issue --- internal/services/consumption/consumption_budget_base.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/services/consumption/consumption_budget_base.go b/internal/services/consumption/consumption_budget_base.go index cf1f45ac61a8..6f4cb586deb6 100644 --- a/internal/services/consumption/consumption_budget_base.go +++ b/internal/services/consumption/consumption_budget_base.go @@ -151,7 +151,6 @@ func (br consumptionBudgetBaseResource) arguments(fields map[string]*pluginsdk.S Required: true, ValidateFunc: validation.IntBetween(0, 1000), }, - // Issue: https://github.com/Azure/azure-rest-api-specs/issues/16240 "threshold_type": { Type: pluginsdk.TypeString, Optional: true, From e13dc705266aaffe809640d9e588ca12c575d43c Mon Sep 17 00:00:00 2001 From: teowa <104055472+teowa@users.noreply.github.com> Date: Thu, 24 Oct 2024 09:06:51 +0000 Subject: [PATCH 7/7] remove _disappear test and revert skipping 404 in deleting --- .../consumption/consumption_budget_base.go | 6 ++--- ...ion_budget_resource_group_resource_test.go | 25 ------------------- 2 files changed, 2 insertions(+), 29 deletions(-) diff --git a/internal/services/consumption/consumption_budget_base.go b/internal/services/consumption/consumption_budget_base.go index 6f4cb586deb6..dd4975bb2753 100644 --- a/internal/services/consumption/consumption_budget_base.go +++ b/internal/services/consumption/consumption_budget_base.go @@ -337,10 +337,8 @@ func (br consumptionBudgetBaseResource) deleteFunc() sdk.ResourceFunc { return err } - if resp, err := client.Delete(ctx, *id); err != nil { - if !response.WasNotFound(resp.HttpResponse) { - return fmt.Errorf("deleting %s: %+v", *id, err) - } + if _, err := client.Delete(ctx, *id); err != nil { + return fmt.Errorf("deleting %s: %+v", *id, err) } return nil diff --git a/internal/services/consumption/consumption_budget_resource_group_resource_test.go b/internal/services/consumption/consumption_budget_resource_group_resource_test.go index 235f8229e2db..70d6a81adbb2 100644 --- a/internal/services/consumption/consumption_budget_resource_group_resource_test.go +++ b/internal/services/consumption/consumption_budget_resource_group_resource_test.go @@ -111,18 +111,6 @@ func TestAccConsumptionBudgetResourceGroup_completeUpdate(t *testing.T) { }) } -func TestAccConsumptionBudgetResourceGroup_disappears(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_consumption_budget_resource_group", "test") - r := ConsumptionBudgetResourceGroupResource{} - - data.ResourceTest(t, r, []acceptance.TestStep{ - data.DisappearsStep(acceptance.DisappearsStepData{ - Config: r.basic, - TestResource: r, - }), - }) -} - func (ConsumptionBudgetResourceGroupResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { id, err := budgets.ParseScopedBudgetID(state.ID) if err != nil { @@ -437,16 +425,3 @@ resource "azurerm_consumption_budget_resource_group" "test" { } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, consumptionBudgetTestStartDate().Format(time.RFC3339)) } - -func (t ConsumptionBudgetResourceGroupResource) Destroy(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { - id, err := budgets.ParseScopedBudgetID(state.ID) - if err != nil { - return nil, err - } - - if _, err = client.Consumption.BudgetsClient.Delete(ctx, *id); err != nil { - return nil, fmt.Errorf("deleting %s: %+v", *id, err) - } - - return utils.Bool(true), nil -}