Skip to content

Commit

Permalink
fix panic from removed not block (#26724)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephybun authored Jul 22, 2024
1 parent 3150cc2 commit 5a4cc53
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 30 deletions.
42 changes: 23 additions & 19 deletions internal/services/consumption/consumption_budget_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,17 +700,19 @@ func expandConsumptionBudgetFilter(i []interface{}) *budgets.BudgetFilter {

filter := budgets.BudgetFilter{}

notBlock := input["not"].([]interface{})
if len(notBlock) != 0 && notBlock[0] != nil {
not := notBlock[0].(map[string]interface{})
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{}))
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]
if len(dimensions) != 0 {
filter.Not = &dimensions[0]
} else if len(tags) != 0 {
filter.Not = &tags[0]
}
}
}

Expand Down Expand Up @@ -754,19 +756,21 @@ func flattenConsumptionBudgetFilter(input *budgets.BudgetFilter) []interface{} {

filterBlock := make(map[string]interface{})

notBlock := 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 != 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 input.Not.Tags != nil {
notBlock["tag"] = []interface{}{flattenConsumptionBudgetComparisonExpression(input.Not.Tags)}
}

if len(notBlock) != 0 {
filterBlock["not"] = []interface{}{notBlock}
if len(notBlock) != 0 {
filterBlock["not"] = []interface{}{notBlock}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,9 @@ resource "azurerm_consumption_budget_resource_group" "test" {
name = "acctestconsumptionbudgetresourcegroup-%d"
resource_group_id = azurerm_resource_group.test.id
// Changed the amount from 1000 to 2000
amount = 2000
time_grain = "Monthly"
// Removed end_date
time_period {
start_date = "%s"
}
Expand All @@ -396,16 +394,13 @@ resource "azurerm_consumption_budget_resource_group" "test" {
]
}
// Added tag: zip
tag {
name = "zip"
values = [
"zap",
"zop",
]
}
// Removed not block
}
notification {
Expand All @@ -417,7 +412,6 @@ resource "azurerm_consumption_budget_resource_group" "test" {
threshold_type = "Forecasted"
contact_emails = [
// Added [email protected]
"[email protected]",
"[email protected]",
"[email protected]",
Expand All @@ -426,22 +420,18 @@ resource "azurerm_consumption_budget_resource_group" "test" {
contact_groups = [
azurerm_monitor_action_group.test.id,
]
// Removed contact_roles
}
notification {
// Set enabled to true
enabled = true
threshold = 100.0
// Changed from EqualTo to GreaterThanOrEqualTo
operator = "GreaterThanOrEqualTo"
operator = "GreaterThanOrEqualTo"
contact_emails = [
"[email protected]",
"[email protected]",
]
// Added contact_groups
contact_groups = [
azurerm_monitor_action_group.test.id,
]
Expand Down

0 comments on commit 5a4cc53

Please sign in to comment.