Skip to content

Commit

Permalink
azuread_user support for immutable_id property
Browse files Browse the repository at this point in the history
  • Loading branch information
derek-burdick committed Jan 17, 2020
1 parent eb8953c commit 0acf730
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions azuread/data_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func dataSourceUserRead(d *schema.ResourceData, meta interface{}) error {
d.Set("mail", user.Mail)
d.Set("mail_nickname", user.MailNickname)
d.Set("usage_location", user.UsageLocation)
d.Set("immutable_id", user.ImmutableID)

return nil
}
17 changes: 17 additions & 0 deletions azuread/resource_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ func resourceUser() *schema.Resource {
Computed: true,
},

"immutable_id": {
Type: schema.TypeString,
Optional: true,
},

"object_id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -97,6 +102,11 @@ func resourceUserCreate(d *schema.ResourceData, meta interface{}) error {
accountEnabled := d.Get("account_enabled").(bool)
password := d.Get("password").(string)
forcePasswordChange := d.Get("force_password_change").(bool)
immutableID := d.Get("immutable_id").(string)
var pImmutableID *string
if immutableID != "" {
pImmutableID = &immutableID
}

//default mail nickname to the first part of the UPN (matches the portal)
if mailNickName == "" {
Expand All @@ -112,6 +122,7 @@ func resourceUserCreate(d *schema.ResourceData, meta interface{}) error {
Password: &password,
},
UserPrincipalName: &upn,
ImmutableID: pImmutableID,
}

if v, ok := d.GetOk("usage_location"); ok {
Expand Down Expand Up @@ -160,6 +171,7 @@ func resourceUserRead(d *schema.ResourceData, meta interface{}) error {
d.Set("account_enabled", user.AccountEnabled)
d.Set("object_id", user.ObjectID)
d.Set("usage_location", user.UsageLocation)
d.Set("immutable_id", user.ImmutableID)
return nil
}

Expand Down Expand Up @@ -201,6 +213,11 @@ func resourceUserUpdate(d *schema.ResourceData, meta interface{}) error {
userUpdateParameters.UsageLocation = p.String(usageLocation)
}

if d.HasChange("immutable_id") {
immutableID := d.Get("immutable_id").(string)
userUpdateParameters.ImmutableID = p.String(immutableID)
}

if _, err := client.Update(ctx, d.Id(), userUpdateParameters); err != nil {
return fmt.Errorf("Error updating User with ID %q: %+v", d.Id(), err)
}
Expand Down
1 change: 1 addition & 0 deletions azuread/resource_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ resource "azuread_user" "test" {
password = "%[2]s"
force_password_change = true
usage_location = "NO"
immutable_id = "%[1]d"
}
`, id, password)
}
Expand Down

0 comments on commit 0acf730

Please sign in to comment.