Skip to content

Commit

Permalink
Update invitation resource and docs, add user_type property, remove s…
Browse files Browse the repository at this point in the history
…end_invitation_message and add more tests
  • Loading branch information
manicminer committed Sep 2, 2021
1 parent c2f401d commit bf63cc0
Show file tree
Hide file tree
Showing 9 changed files with 306 additions and 127 deletions.
57 changes: 38 additions & 19 deletions docs/resources/invitation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ subcategory: "Invitations"

Manages an invitation of a guest user within Azure Active Directory.

-> **NOTE:** If you're authenticating using a Service Principal then it must have permissions to `User.ReadWrite.All` within the `Microsoft Graph` API.
## API Permissions

The following API permissions are required in order to use this resource.

When authenticated with a service principal, this resource requires one of the following application roles: `User.Invite.All`, `User.ReadWrite.All` or `Directory.ReadWrite.All`

When authenticated with a user principal, this resource requires one of the following directory roles: `Guest Inviter`, `User Administrator` or `Global Administrator`

## Example Usage

Expand All @@ -19,20 +25,30 @@ resource "azuread_invitation" "example" {
}
```

*Invitation with custom email*
*Invitation with standard message*

```terraform
resource "azuread_invitation" "example" {
user_email_address = "[email protected]"
redirect_url = "https://portal.azure.com"
user_message_info {
language = "en-US"
}
}
```

*Invitation with custom message and a CC recipient*

```terraform
resource "azuread_invitation" "example" {
user_display_name = "Bob Bobson"
user_email_address = "[email protected]"
redirect_url = "https://portal.azure.com"
send_invitation_message = true
user_message_info {
cc_recipients = ["[email protected]"]
customised_message_body = "Hello there! You are invited to join my Azure tenant !"
message_language = "en-US"
cc_recipients = ["[email protected]"]
customized_body = "Hello there! You are invited to join my Azure tenant!"
}
}
```
Expand All @@ -41,25 +57,28 @@ resource "azuread_invitation" "example" {

The following arguments are supported:

* `redirect_url` - (Required) URL the user should be redirected to once the invitation is redeemed.
* `send_invitation_message` - (Optional) If `true`, an email will be sent to the user being invited. Must be set to `true` if a `user_message_info` block is specified. Defaults to `false`.
* `user_display_name` - (Optional) Display name of the user being invited.
* `user_email_address` - (Required) Email address of the user being invited.
* `user_message_info` - (Optional) A `user_message_info` block as documented below, which configures the message being sent to the invited user. `send_invitation_message` must be set to `true` if this block is specified.
* `redirect_url` - (Required) The URL that the user should be redirected to once the invitation is redeemed.
* `user_display_name` - (Optional) The display name of the user being invited.
* `user_email_address` - (Required) The email address of the user being invited.
* `user_message` - (Optional) A `user_message` block as documented below, which configures the message being sent to the invited user. If this block is omitted, no message will be sent.
* `user_type` - (Optional) The user type of the user being invited. Must be one of `Guest` or `Member`. Only Global Administrators can invite users as members. Defaults to `Guest`.

---

`user_message_info` block supports the following:
`user_message` block supports the following:

* `cc_recipients` - (Optional) Additional recipients the invitation message should be sent to. Currently only 1 additional recipient is supported by Azure.
* `customised_message_body` - (Optional) Customised message body you want to send if you don't want the default message.
* `message_language` - (Optional) Language the message will be sent in. The value specified must be in ISO 639 format. Defaults to `en-US`.
* `cc_recipients` - (Optional) Email addresses of additional recipients the invitation message should be sent to. Only 1 additional recipient is currently supported by Azure.
* `customized_body` - (Optional) Customized message body you want to send if you don't want to send the default message. Cannot be specified with `language`.
* `language` - (Optional) The language you want to send the default message in. The value specified must be in ISO 639 format. Defaults to `en-US`. Cannot be specified with `customized_body`.


## Attributes Reference

In addition to all arguments above, the following attributes are exported:

* `id` - ID of the invitation.
* `redeem_url` - URL the user can use to redeem the invitation.
* `user_id` - Object ID of the invited user.
* `redeem_url` - The URL the user can use to redeem their invitation.
* `user_id` - Object ID of the invited user.

## Import

This resource does not support importing.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/hashicorp/terraform-plugin-sdk/v2 v2.7.0
github.com/hashicorp/yamux v0.0.0-20210316155119-a95892c5f864 // indirect
github.com/klauspost/compress v1.12.2 // indirect
github.com/manicminer/hamilton v0.26.0
github.com/manicminer/hamilton v0.27.0
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.4.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/manicminer/hamilton v0.26.0 h1:AJ8RrSAG8xkTBKC+hOeUijgVFXiXaqPBDs7oRP3O14o=
github.com/manicminer/hamilton v0.26.0/go.mod h1:QryxpD/4+cdKuXNi0UjLDvgxYdP0LLmYz7dYU7DAX4U=
github.com/manicminer/hamilton v0.27.0 h1:IRyrikO0lh9IAzI3XD2FjnoR7l24GGdhHt+2MXty7GI=
github.com/manicminer/hamilton v0.27.0/go.mod h1:QryxpD/4+cdKuXNi0UjLDvgxYdP0LLmYz7dYU7DAX4U=
github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
Expand Down
13 changes: 9 additions & 4 deletions internal/services/invitations/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ import (
)

type Client struct {
MsClient *msgraph.InvitationsClient
InvitationsClient *msgraph.InvitationsClient
UsersClient *msgraph.UsersClient
}

func NewClient(o *common.ClientOptions) *Client {
msClient := msgraph.NewInvitationsClient(o.TenantID)
o.ConfigureClient(&msClient.BaseClient)
invitationsClient := msgraph.NewInvitationsClient(o.TenantID)
o.ConfigureClient(&invitationsClient.BaseClient)

usersClient := msgraph.NewUsersClient(o.TenantID)
o.ConfigureClient(&usersClient.BaseClient)

return &Client{
MsClient: msClient,
InvitationsClient: invitationsClient,
UsersClient: usersClient,
}
}
Loading

0 comments on commit bf63cc0

Please sign in to comment.