@@ -13,6 +13,7 @@ import (
1313
1414 "github.com/go-ldap/ldap/v3"
1515 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
16+ "golang.org/x/text/encoding/unicode"
1617)
1718
1819func resourceLDAPObject () * schema.Resource {
@@ -133,7 +134,8 @@ func resourceLDAPObjectCreate(d *schema.ResourceData, meta interface{}) error {
133134 // each map should only have one entry (see resource declaration)
134135 for name , value := range attribute .(map [string ]interface {}) {
135136 log .Printf ("[DEBUG] ldap_object::create - %q has attribute[%v] => %v (%T)" , dn , name , value , value )
136- m [name ] = append (m [name ], value .(string ))
137+ v := toAttributeValue (name , value .(string ))
138+ m [name ] = append (m [name ], v )
137139 }
138140 }
139141 // now loop through the map and add attributes with theys value(s)
@@ -373,7 +375,8 @@ func computeAndAddDeltas(modify *ldap.ModifyRequest, os, ns *schema.Set) error {
373375 for _ , m := range ns .List () {
374376 for mk , mv := range m .(map [string ]interface {}) {
375377 if k == mk {
376- values = append (values , mv .(string ))
378+ v := toAttributeValue (k , mv .(string ))
379+ values = append (values , v )
377380 }
378381 }
379382 }
@@ -394,7 +397,8 @@ func computeAndAddDeltas(modify *ldap.ModifyRequest, os, ns *schema.Set) error {
394397 for _ , m := range ns .List () {
395398 for mk , mv := range m .(map [string ]interface {}) {
396399 if k == mk {
397- values = append (values , mv .(string ))
400+ v := toAttributeValue (k , mv .(string ))
401+ values = append (values , v )
398402 }
399403 }
400404 }
@@ -403,3 +407,12 @@ func computeAndAddDeltas(modify *ldap.ModifyRequest, os, ns *schema.Set) error {
403407 }
404408 return nil
405409}
410+
411+ func toAttributeValue (name , value string ) string {
412+ if name == "unicodePwd" {
413+ utf16 := unicode .UTF16 (unicode .LittleEndian , unicode .IgnoreBOM )
414+ pwdEncoded , _ := utf16 .NewEncoder ().String ("\" " + value + "\" " )
415+ return pwdEncoded
416+ }
417+ return value
418+ }
0 commit comments