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

Fix azurerm_automation_variable type parsing logic #12511

Merged
merged 2 commits into from
Jul 8, 2021
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
4 changes: 2 additions & 2 deletions azurerm/internal/services/automation/automation_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
36 changes: 34 additions & 2 deletions azurerm/internal/services/automation/automation_variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,53 @@ 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,
ExpectValue: 135,
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",
Expand Down