Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add azuread_invitation resource #445

Merged
merged 7 commits into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .teamcity/components/project.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var services = mapOf(
"applications" to "Applications",
"domains" to "Domains",
"groups" to "Groups",
"invitations" to "Invitations",
"serviceprincipals" to "Service Principals",
"users" to "Users"
)
Expand Down
84 changes: 84 additions & 0 deletions docs/resources/invitation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
subcategory: "Invitations"
---

# Resource: azuread_invitation

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

## 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

*Basic example*

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

*Invitation with standard message*

```terraform
resource "azuread_invitation" "example" {
user_email_address = "[email protected]"
redirect_url = "https://portal.azure.com"

message {
language = "en-US"
}
}
```

*Invitation with custom message body and an additional recipient*

```terraform
resource "azuread_invitation" "example" {
user_display_name = "Bob Bobson"
user_email_address = "[email protected]"
redirect_url = "https://portal.azure.com"

message {
additional_recipients = ["[email protected]"]
body = "Hello there! You are invited to join my Azure tenant!"
}
}
```

## Argument Reference

The following arguments are supported:

* `message` - (Optional) A `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.
* `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_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`.

---

`message` block supports the following:

* `additional_recipients` - (Optional) Email addresses of additional recipients the invitation message should be sent to. Only 1 additional recipient is currently supported by Azure.
* `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 `body`.


## Attributes Reference

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

* `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
3 changes: 3 additions & 0 deletions internal/clients/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
applications "github.com/hashicorp/terraform-provider-azuread/internal/services/applications/client"
domains "github.com/hashicorp/terraform-provider-azuread/internal/services/domains/client"
groups "github.com/hashicorp/terraform-provider-azuread/internal/services/groups/client"
invitations "github.com/hashicorp/terraform-provider-azuread/internal/services/invitations/client"
serviceprincipals "github.com/hashicorp/terraform-provider-azuread/internal/services/serviceprincipals/client"
users "github.com/hashicorp/terraform-provider-azuread/internal/services/users/client"
)
Expand All @@ -29,6 +30,7 @@ type Client struct {
Applications *applications.Client
Domains *domains.Client
Groups *groups.Client
Invitations *invitations.Client
ServicePrincipals *serviceprincipals.Client
Users *users.Client
}
Expand All @@ -39,6 +41,7 @@ func (client *Client) build(ctx context.Context, o *common.ClientOptions) error
client.Applications = applications.NewClient(o)
client.Domains = domains.NewClient(o)
client.Groups = groups.NewClient(o)
client.Invitations = invitations.NewClient(o)
client.ServicePrincipals = serviceprincipals.NewClient(o)
client.Users = users.NewClient(o)

Expand Down
2 changes: 2 additions & 0 deletions internal/provider/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/hashicorp/terraform-provider-azuread/internal/services/applications"
"github.com/hashicorp/terraform-provider-azuread/internal/services/domains"
"github.com/hashicorp/terraform-provider-azuread/internal/services/groups"
"github.com/hashicorp/terraform-provider-azuread/internal/services/invitations"
"github.com/hashicorp/terraform-provider-azuread/internal/services/serviceprincipals"
"github.com/hashicorp/terraform-provider-azuread/internal/services/users"
)
Expand All @@ -13,6 +14,7 @@ func SupportedServices() []ServiceRegistration {
applications.Registration{},
domains.Registration{},
groups.Registration{},
invitations.Registration{},
serviceprincipals.Registration{},
users.Registration{},
}
Expand Down
25 changes: 25 additions & 0 deletions internal/services/invitations/client/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package client

import (
"github.com/manicminer/hamilton/msgraph"

"github.com/hashicorp/terraform-provider-azuread/internal/common"
)

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

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

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

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