Skip to content

Commit

Permalink
fix: Changing the signature isEmpty + fixing the result for boolean v…
Browse files Browse the repository at this point in the history
…alues
  • Loading branch information
vaerh committed May 11, 2023
1 parent 7984574 commit aedc90e
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions routeros/mikrotik_serialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,29 @@ func GetMetadata(s map[string]*schema.Schema) *MikrotikItemMetadata {
return meta
}

func isEmpty(propName string, s map[string]*schema.Schema, d *schema.ResourceData) bool {
func isEmpty(propName string, schemaProp *schema.Schema, d *schema.ResourceData) bool {
v := d.Get(propName)
switch s[propName].Type {
switch schemaProp.Type {
case schema.TypeString:
if s[propName].Default != nil {
return v.(string) == "" && s[propName].Default.(string) == ""
if schemaProp.Default != nil {
return v.(string) == "" && schemaProp.Default.(string) == ""
}
return v.(string) == ""
case schema.TypeInt:
return !d.HasChange(propName)
case schema.TypeBool:
if s[propName].Default != nil {
return s[propName].Default.(bool) == v.(bool)
if schemaProp.Default != nil {
return schemaProp.Default.(bool) == v.(bool)
}
return v.(bool)
return !v.(bool) // false == isEmpty
case schema.TypeList:
return len(v.([]interface{})) == 0
case schema.TypeSet:
return v.(*schema.Set).Len() == 0
case schema.TypeMap:
return len(v.(map[string]interface{})) == 0
default:
panic("[isEmpty] wrong resource type: " + s[propName].Type.String())
panic("[isEmpty] wrong resource type: " + schemaProp.Type.String())
}
}

Expand Down Expand Up @@ -164,7 +164,8 @@ func TerraformResourceDataToMikrotik(s map[string]*schema.Schema, d *schema.Reso
# (22 unchanged attributes hidden)
}
*/
if terraformMetadata.Optional && !d.HasChange(terraformSnakeName) && isEmpty(terraformSnakeName, s, d) {
if terraformMetadata.Optional && !d.HasChange(terraformSnakeName) &&
isEmpty(terraformSnakeName, s[terraformSnakeName], d) {
continue
}

Expand Down

0 comments on commit aedc90e

Please sign in to comment.