Skip to content

Commit

Permalink
cleanup diff method
Browse files Browse the repository at this point in the history
  • Loading branch information
smashi committed Jun 1, 2023
1 parent 482412c commit cdb51d4
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions myrasec/resource_myrasec_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,37 +379,24 @@ func resourceMyrasecSettings() *schema.Resource {
}

func resourceCustomizeDiff(ctx context.Context, d *schema.ResourceDiff, m interface{}) error {
currentlySetAttributes := d.Get("available_attributes").(*schema.Set)
availableAttributes := []string{}

availableAttribtues := []string{}
resource := resourceMyrasecSettings()
for name, attr := range resource.Schema {
if attr.Type == schema.TypeBool {
notSet := d.GetRawConfig().GetAttr(name).IsNull()
isNullValue := d.GetRawConfig().GetAttr(name).IsNull()

inList := isInList(name, currentlySetAttributes.List())
if (inList && !notSet) || (!notSet && !inList) {
availableAttribtues = append(availableAttribtues, name)
} else {
log.Println("not in list")
if !isNullValue {
availableAttributes = append(availableAttributes, name)
}
}
}

d.SetNew("available_attributes", availableAttribtues)
d.SetNew("available_attributes", availableAttributes)

return nil
}

func isInList(value string, list []interface{}) bool {
for _, item := range list {
if item.(string) == value {
return true
}
}
return false
}

// resourceMyrasecSettingsCreate ...
func resourceMyrasecSettingsCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*myrasec.API)
Expand Down

0 comments on commit cdb51d4

Please sign in to comment.