From f9fe60ce9f421ae3234468ef8533e71c0e13a60a Mon Sep 17 00:00:00 2001 From: Jochen Dick Date: Tue, 5 Jan 2021 10:27:55 +0100 Subject: [PATCH] fix: Workaround for weird terraform behavior to fix boolean custom_fields --- netbox/util.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/netbox/util.go b/netbox/util.go index 605fcefc9..bce78ced1 100644 --- a/netbox/util.go +++ b/netbox/util.go @@ -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" @@ -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" {