Skip to content

Commit

Permalink
fix: Workaround for weird terraform behavior to fix boolean custom_fi…
Browse files Browse the repository at this point in the history
…elds
  • Loading branch information
Jochen Dick committed Jan 19, 2021
1 parent dbb7ef9 commit f9fe60c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion netbox/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package netbox

import (
"fmt"

netboxclient "github.com/netbox-community/go-netbox/netbox/client"
"github.com/netbox-community/go-netbox/netbox/client/virtualization"
"github.com/netbox-community/go-netbox/netbox/models"
Expand Down Expand Up @@ -194,6 +193,12 @@ func convertCustomFieldsFromTerraformToAPIUpdate(stateCustomFields, resourceCust
// then we override the values that still exist in the terraform code with their respective value
for key, value := range resourceCustomFields.(map[string]interface{}) {
toReturn[key] = value
// https://github.com/smutel/terraform-provider-netbox/issues/32
// under certain circumstances terraform puts empty string into `resourceCustomFields` when parent block is removed
// we simply replace these occurences with `nil` to not negatively affect the boolean field where empty string is equal to false
if value == "" {
toReturn[key] = nil
}

// special handling for booleans, as they are the only parameter not supplied as string to netbox
if value == "true" {
Expand Down

0 comments on commit f9fe60c

Please sign in to comment.