Skip to content

Commit

Permalink
Merge pull request #77 from hashicorp/user_null_fields
Browse files Browse the repository at this point in the history
Fix bug when removing user attributes
  • Loading branch information
koikonom authored Jan 21, 2021
2 parents e8f0f66 + 0e325de commit 7e3a96e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ad/internal/winrmhelper/winrm_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,13 @@ func (u *User) ModifyUser(d *schema.ResourceData, client *winrm.Client) error {

for k, param := range strKeyMap {
if d.HasChange(k) {
value := d.Get(k).(string)
cmds = append(cmds, fmt.Sprintf("-%s %q", param, value))
value := SanitiseTFInput(d, k)
if value == "" {
value = "$null"
} else {
value = fmt.Sprintf(`"%s"`, value)
}
cmds = append(cmds, fmt.Sprintf(`-%s %s`, param, value))
}
}

Expand Down
48 changes: 48 additions & 0 deletions ad/resource_ad_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ func TestAccUser_basic(t *testing.T) {
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"initial_password"},
},
{
Config: testAccUserConfigAttributes("dc=yourdomain,dc=com", "testuser", "thu2too'W?ieJ}a^g0zo"),
Check: resource.ComposeTestCheckFunc(
testAccUserExists("ad_user.a", "dc=yourdomain,dc=com", "testuser", true),
),
},
{
Config: testAccUserConfigBasic("dc=yourdomain,dc=com", "testuser", "thu2too'W?ieJ}a^g0zo"),
Check: resource.ComposeTestCheckFunc(
testAccUserExists("ad_user.a", "dc=yourdomain,dc=com", "testuser", true),
),
},
},
})
}
Expand Down Expand Up @@ -212,6 +224,42 @@ func testAccUserConfigBasic(domain, username, password string) string {

}

func testAccUserConfigAttributes(domain, username, password string) string {
return fmt.Sprintf(`%s
resource "ad_user" "a" {%s
city = "City"
company = "Company"
country = "us"
department = "Department"
description = "Description"
division = "Division"
email_address = "[email protected]"
employee_id = "id"
employee_number = "number"
fax = "Fax"
given_name = "GivenName"
home_directory = "HomeDirectory"
home_drive = "HomeDrive"
home_phone = "HomePhone"
home_page = "HomePage"
initials = "Initia"
mobile_phone = "MobilePhone"
office = "Office"
office_phone = "OfficePhone"
organization = "Organization"
other_name = "OtherName"
po_box = "POBox"
postal_code = "PostalCode"
state = "State"
street_address = "StreetAddress"
surname = "Surname"
title = "Title"
smart_card_logon_required = false
trusted_for_delegation = true
}`, defaultVariablesSection(domain, username, password), defaultUserSection(""))

}

func testAccUserConfigCustomAttributes(domain, username, password, customAttributes string) string {
return fmt.Sprintf(`%s
resource "ad_user" "a" {%s
Expand Down

0 comments on commit 7e3a96e

Please sign in to comment.