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 1 commit
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
Prev Previous commit
Tidy up some property names
  • Loading branch information
manicminer committed Sep 2, 2021
commit c8809c933e056824590d22b7ac0e69664366056e
20 changes: 10 additions & 10 deletions docs/resources/invitation.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ resource "azuread_invitation" "example" {
user_email_address = "jdoe@hashicorp.com"
redirect_url = "https://portal.azure.com"

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

*Invitation with custom message and a CC recipient*
*Invitation with custom message body and an additional recipient*

```terraform
resource "azuread_invitation" "example" {
user_display_name = "Bob Bobson"
user_email_address = "bbobson@hashicorp.com"
redirect_url = "https://portal.azure.com"

user_message_info {
cc_recipients = ["aaliceberg@hashicorp.com"]
customized_body = "Hello there! You are invited to join my Azure tenant!"
message {
additional_recipients = ["aaliceberg@hashicorp.com"]
body = "Hello there! You are invited to join my Azure tenant!"
}
}
```
Expand All @@ -57,19 +57,19 @@ resource "azuread_invitation" "example" {

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_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` block supports the following:
`message` block supports the following:

* `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`.
* `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
Expand Down
18 changes: 9 additions & 9 deletions internal/services/invitations/invitation_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ func invitationResource() *schema.Resource {
ValidateDiagFunc: validate.NoEmptyStrings,
},

"user_message": {
"message": {
Description: "Customize the message sent to the invited user",
Type: schema.TypeList,
Optional: true,
ForceNew: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cc_recipients": {
"additional_recipients": {
Description: "Email addresses of additional recipients the invitation message should be sent to",
Type: schema.TypeList,
Optional: true,
Expand All @@ -78,19 +78,19 @@ func invitationResource() *schema.Resource {
},
},

"customized_body": {
"body": {
Description: "Customized message body you want to send if you don't want to send the default message",
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"user_message.0.language"},
ConflictsWith: []string{"message.0.language"},
ValidateDiagFunc: validate.NoEmptyStrings,
},

"language": {
Description: "The language you want to send the default message in",
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"user_message.0.customized_body"},
ConflictsWith: []string{"message.0.body"},
ValidateDiagFunc: validate.ISO639Language,
},
},
Expand Down Expand Up @@ -137,7 +137,7 @@ func invitationResourceCreate(ctx context.Context, d *schema.ResourceData, meta
properties.InvitedUserDisplayName = utils.String(v.(string))
}

if v, ok := d.GetOk("user_message"); ok {
if v, ok := d.GetOk("message"); ok {
properties.SendInvitationMessage = utils.Bool(true)
properties.InvitedUserMessageInfo = expandInvitedUserMessageInfo(v.([]interface{}))
}
Expand Down Expand Up @@ -247,11 +247,11 @@ func expandInvitedUserMessageInfo(in []interface{}) *msgraph.InvitedUserMessageI
result := msgraph.InvitedUserMessageInfo{}
config := in[0].(map[string]interface{})

ccRecipients := config["cc_recipients"].([]interface{})
messageBody := config["customized_body"].(string)
additionalRecipients := config["additional_recipients"].([]interface{})
messageBody := config["body"].(string)
messageLanguage := config["language"].(string)

result.CCRecipients = expandRecipients(ccRecipients)
result.CCRecipients = expandRecipients(additionalRecipients)
result.CustomizedMessageBody = &messageBody
result.MessageLanguage = &messageLanguage

Expand Down
24 changes: 12 additions & 12 deletions internal/services/invitations/invitation_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestAccInvitation_message(t *testing.T) {
check.That(data.ResourceName).Key("user_display_name").HasValue("Test user"),
check.That(data.ResourceName).Key("user_email_address").HasValue(fmt.Sprintf("acctest-user-%s@test.com", data.RandomString)),
check.That(data.ResourceName).Key("user_id").Exists(),
check.That(data.ResourceName).Key("user_message.#").HasValue("1"),
check.That(data.ResourceName).Key("message.#").HasValue("1"),
check.That(data.ResourceName).Key("user_type").HasValue("Guest"),
),
},
Expand All @@ -91,10 +91,10 @@ func TestAccInvitation_messageWithCustomizedBody(t *testing.T) {
check.That(data.ResourceName).Key("user_display_name").HasValue("Test user"),
check.That(data.ResourceName).Key("user_email_address").HasValue(fmt.Sprintf("acctest-user-%s@test.com", data.RandomString)),
check.That(data.ResourceName).Key("user_id").Exists(),
check.That(data.ResourceName).Key("user_message.#").HasValue("1"),
check.That(data.ResourceName).Key("user_message.0.cc_recipients.#").HasValue("1"),
check.That(data.ResourceName).Key("user_message.0.cc_recipients.0").HasValue(fmt.Sprintf("acctest-another-%s@test.com", data.RandomString)),
check.That(data.ResourceName).Key("user_message.0.customized_body").HasValue("Hello there! You are invited to join my Azure tenant."),
check.That(data.ResourceName).Key("message.#").HasValue("1"),
check.That(data.ResourceName).Key("message.0.additional_recipients.#").HasValue("1"),
check.That(data.ResourceName).Key("message.0.additional_recipients.0").HasValue(fmt.Sprintf("acctest-another-%s@test.com", data.RandomString)),
check.That(data.ResourceName).Key("message.0.body").HasValue("Hello there! You are invited to join my Azure tenant."),
check.That(data.ResourceName).Key("user_type").HasValue("Guest"),
),
},
Expand All @@ -115,8 +115,8 @@ func TestAccInvitation_messageWithLanguage(t *testing.T) {
check.That(data.ResourceName).Key("user_display_name").HasValue("Test user"),
check.That(data.ResourceName).Key("user_email_address").HasValue(fmt.Sprintf("acctest-user-%s@test.com", data.RandomString)),
check.That(data.ResourceName).Key("user_id").Exists(),
check.That(data.ResourceName).Key("user_message.#").HasValue("1"),
check.That(data.ResourceName).Key("user_message.0.language").HasValue("fr-CA"),
check.That(data.ResourceName).Key("message.#").HasValue("1"),
check.That(data.ResourceName).Key("message.0.language").HasValue("fr-CA"),
check.That(data.ResourceName).Key("user_type").HasValue("Guest"),
),
},
Expand Down Expand Up @@ -166,7 +166,7 @@ resource "azuread_invitation" "test" {
user_email_address = "acctest-user-%[1]s@test.com"
user_display_name = "Test user"

user_message {}
message {}
}
`, data.RandomString)
}
Expand All @@ -178,9 +178,9 @@ resource "azuread_invitation" "test" {
user_email_address = "acctest-user-%[1]s@test.com"
user_display_name = "Test user"

user_message {
cc_recipients = ["acctest-another-%[1]s@test.com"]
customized_body = "Hello there! You are invited to join my Azure tenant."
message {
additional_recipients = ["acctest-another-%[1]s@test.com"]
body = "Hello there! You are invited to join my Azure tenant."
}
}
`, data.RandomString)
Expand All @@ -193,7 +193,7 @@ resource "azuread_invitation" "test" {
user_email_address = "acctest-user-%[1]s@test.com"
user_display_name = "Test user"

user_message {
message {
language = "fr-CA"
}
}
Expand Down