Skip to content
Open
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
28 changes: 23 additions & 5 deletions citrixadc/resource_citrixadc_systemuser.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package citrixadc

import (
"strings"

"github.com/citrix/adc-nitro-go/resource/config/system"
"github.com/citrix/adc-nitro-go/service"

"github.com/hashicorp/terraform-plugin-sdk/helper/hashcode"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"

"bytes"
"crypto/sha512"
"encoding/hex"
"fmt"
"log"
"strconv"
Expand Down Expand Up @@ -40,10 +44,11 @@ func resourceCitrixAdcSystemuser() *schema.Resource {
Computed: true,
},
"password": {
Type: schema.TypeString,
Optional: true,
Computed: false,
Sensitive: true,
Type: schema.TypeString,
Optional: true,
Computed: false,
Sensitive: true,
DiffSuppressFunc: ignoreHashMatch,
},
"hashedpassword": {
Type: schema.TypeString,
Expand Down Expand Up @@ -90,6 +95,18 @@ func resourceCitrixAdcSystemuser() *schema.Resource {
}
}

func hashPassword(password string) string {
hash := sha512.Sum512([]byte(password))
return hex.EncodeToString(hash[:])
}

func ignoreHashMatch(k, old, new string, d *schema.ResourceData) bool {
oldStr := strings.ToLower(old)
newStr := strings.ToLower(hashPassword(new))
log.Printf("[DEBUG] comparing old value: %s with new value %s", oldStr, newStr)
return oldStr == newStr
}

func createSystemuserFunc(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] citrixadc-provider: In createSystemuserFunc")
client := meta.(*NetScalerNitroClient).client
Expand Down Expand Up @@ -120,7 +137,7 @@ func createSystemuserFunc(d *schema.ResourceData, meta interface{}) error {
}

d.SetId(username)

d.Set("password", hashPassword(d.Get("password").(string)))
err = readSystemuserFunc(d, meta)
if err != nil {
log.Printf("[ERROR] netscaler-provider: ?? we just created this systemuser but we can't read it ?? %s", username)
Expand Down Expand Up @@ -224,6 +241,7 @@ func updateSystemuserFunc(d *schema.ResourceData, meta interface{}) error {
return err
}
}
d.Set("password", hashPassword(d.Get("password").(string)))
return readSystemuserFunc(d, meta)
}

Expand Down