Skip to content

Commit

Permalink
Add possibility to set usage location on user (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
landro authored and katbyte committed Oct 11, 2019
1 parent 1436e3a commit 824f29b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions azuread/data_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ func dataUser() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"usage_location": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -90,6 +95,7 @@ func dataSourceUserRead(d *schema.ResourceData, meta interface{}) error {
d.Set("display_name", user.DisplayName)
d.Set("mail", user.Mail)
d.Set("mail_nickname", user.MailNickname)
d.Set("usage_location", user.UsageLocation)

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

"usage_location": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "A two letter country code (ISO standard 3166). " +
"Required for users that will be assigned licenses due to legal requirement to check for availability of services in countries. " +
"Examples include: `NO`, `JP`, and `GB`. Not nullable.",
},
},
}
}
Expand Down Expand Up @@ -105,6 +114,10 @@ func resourceUserCreate(d *schema.ResourceData, meta interface{}) error {
UserPrincipalName: &upn,
}

if v, ok := d.GetOk("usage_location"); ok {
userCreateParameters.UsageLocation = p.String(v.(string))
}

user, err := client.Create(ctx, userCreateParameters)
if err != nil {
return fmt.Errorf("Error creating User (%q): %+v", upn, err)
Expand Down Expand Up @@ -146,6 +159,7 @@ func resourceUserRead(d *schema.ResourceData, meta interface{}) error {
d.Set("mail_nickname", user.MailNickname)
d.Set("account_enabled", user.AccountEnabled)
d.Set("object_id", user.ObjectID)
d.Set("usage_location", user.UsageLocation)
return nil
}

Expand Down Expand Up @@ -182,6 +196,11 @@ func resourceUserUpdate(d *schema.ResourceData, meta interface{}) error {
userUpdateParameters.PasswordProfile = passwordProfile
}

if d.HasChange("usage_location") {
usageLocation := d.Get("usage_location").(string)
userUpdateParameters.UsageLocation = p.String(usageLocation)
}

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 @@ -203,6 +203,7 @@ resource "azuread_user" "test" {
account_enabled = false
password = "%[2]s"
force_password_change = true
usage_location = "NO"
}
`, id, password)
}
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/user.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ The following attributes are exported:
* `display_name` - The Display Name of the Azure AD User.
* `mail` - The primary email address of the Azure AD User.
* `mail_nickname` - The email alias of the Azure AD User.
* `usage_location` - The usage location of the Azure AD User.
1 change: 1 addition & 0 deletions website/docs/r/user.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ The following arguments are supported:
* `mail_nickname`- (Optional) The mail alias for the user. Defaults to the user name part of the User Principal Name.
* `password` - (Required) The password for the User. The password must satisfy minimum requirements as specified by the password policy. The maximum length is 256 characters.
* `force_password_change` - (Optional) `true` if the User is forced to change the password during the next sign-in. Defaults to `false`.
* `usage_location` - (Optional) The usage location of the User. Required for users that will be assigned licenses due to legal requirement to check for availability of services in countries. The usage location is a two letter country code (ISO standard 3166). Examples include: `NO`, `JP`, and `GB`. Cannot be reset to null once set.

## Attributes Reference

Expand Down

0 comments on commit 824f29b

Please sign in to comment.