From beaf23843aceed3200b1f32cafa5acf7ea96bd3b Mon Sep 17 00:00:00 2001 From: OmnipotentOwl <1769881+OmnipotentOwl@users.noreply.github.com> Date: Wed, 7 Jul 2021 15:03:12 -0400 Subject: [PATCH 1/2] Add Test Cases to validate issue around numeric boolean parsing. --- .../automation/automation_variable_test.go | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/azurerm/internal/services/automation/automation_variable_test.go b/azurerm/internal/services/automation/automation_variable_test.go index 9445011c9c3a..5a7184fe0367 100644 --- a/azurerm/internal/services/automation/automation_variable_test.go +++ b/azurerm/internal/services/automation/automation_variable_test.go @@ -33,7 +33,7 @@ func TestParseAzureRmAutomationVariableValue(t *testing.T) { Expect: func(v interface{}) bool { return v.(string) == "Test String" }, }, { - Name: "integer variable", + Name: "integer variable 135", Resource: "azurerm_automation_variable_int", Value: "135", HasError: false, @@ -41,13 +41,45 @@ func TestParseAzureRmAutomationVariableValue(t *testing.T) { Expect: func(v interface{}) bool { return v.(int32) == 135 }, }, { - Name: "boolean variable", + Name: "integer variable 0", + Resource: "azurerm_automation_variable_int", + Value: "0", + HasError: false, + ExpectValue: 0, + Expect: func(v interface{}) bool { return v.(int32) == 0 }, + }, + { + Name: "integer variable 1", + Resource: "azurerm_automation_variable_int", + Value: "1", + HasError: false, + ExpectValue: 1, + Expect: func(v interface{}) bool { return v.(int32) == 1 }, + }, + { + Name: "integer variable 2", + Resource: "azurerm_automation_variable_int", + Value: "2", + HasError: false, + ExpectValue: 2, + Expect: func(v interface{}) bool { return v.(int32) == 2 }, + }, + { + Name: "boolean variable true", Resource: "azurerm_automation_variable_bool", Value: "true", HasError: false, ExpectValue: true, Expect: func(v interface{}) bool { return v.(bool) == true }, }, + { + Name: "boolean variable false", + Resource: "azurerm_automation_variable_bool", + Value: "false", + HasError: false, + ExpectValue: false, + Expect: func(v interface{}) bool { return v.(bool) == false }, + }, { Name: "datetime variable", Resource: "azurerm_automation_variable_datetime", From e291d12cdf433576adc199ead85f269687032132 Mon Sep 17 00:00:00 2001 From: OmnipotentOwl <1769881+OmnipotentOwl@users.noreply.github.com> Date: Wed, 7 Jul 2021 15:03:53 -0400 Subject: [PATCH 2/2] Update parsing logic to run numeric before boolean --- azurerm/internal/services/automation/automation_variable.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azurerm/internal/services/automation/automation_variable.go b/azurerm/internal/services/automation/automation_variable.go index 4c63e9d70127..e93f11470ff7 100644 --- a/azurerm/internal/services/automation/automation_variable.go +++ b/azurerm/internal/services/automation/automation_variable.go @@ -40,11 +40,11 @@ func ParseAzureAutomationVariableValue(resource string, input *string) (interfac } } else if value, err = strconv.Unquote(*input); err == nil { actualResource = "azurerm_automation_variable_string" - } else if value, err = strconv.ParseBool(*input); err == nil { - actualResource = "azurerm_automation_variable_bool" } else if value, err = strconv.ParseInt(*input, 10, 32); err == nil { value = int32(value.(int64)) actualResource = "azurerm_automation_variable_int" + } else if value, err = strconv.ParseBool(*input); err == nil { + actualResource = "azurerm_automation_variable_bool" } if actualResource != resource {