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 Microsoft Teams destination to notification_configuration #484

Merged
merged 5 commits into from
Jun 15, 2022
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
Next Next commit
Change microsoft_teams notification destination type to microsoft-teams
  • Loading branch information
JarrettSpiker committed Jun 15, 2022
commit 4187c5a0aee513754bf527d293381b9c060180df
8 changes: 4 additions & 4 deletions tfe/resource_tfe_notification_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func resourceTFENotificationConfigurationCreate(d *schema.ResourceData, meta int
return err
}
} else if destinationType == tfe.NotificationDestinationTypeMicrosoftTeams {
// When destination_type is 'microsoft_teams':
// When destination_type is 'microsoft-teams':
// 1. email_addresses, email_user_ids, and token cannot be set
// 2. url must be set
err := validateSchemaAttributesForDestinationTypeMicrosoftTeams(d)
Expand Down Expand Up @@ -269,7 +269,7 @@ func resourceTFENotificationConfigurationUpdate(d *schema.ResourceData, meta int
return err
}
} else if destinationType == tfe.NotificationDestinationTypeMicrosoftTeams {
// When destination_type is 'microsoft_teams':
// When destination_type is 'microsoft-teams':
// 1. email_addresses, email_user_ids, and token cannot be set
// 2. url must be set
err := validateSchemaAttributesForDestinationTypeMicrosoftTeams(d)
Expand Down Expand Up @@ -389,7 +389,7 @@ func validateSchemaAttributesForDestinationTypeSlack(d *schema.ResourceData) err
}

func validateSchemaAttributesForDestinationTypeMicrosoftTeams(d *schema.ResourceData) error {
// Make sure email_addresses, email_user_ids, and token are not set when destination_type is 'microsoft_teams'
// Make sure email_addresses, email_user_ids, and token are not set when destination_type is 'microsoft-teams'
_, emailAddressesIsSet := d.GetOk("email_addresses")
if emailAddressesIsSet {
return fmt.Errorf("Email addresses cannot be set with destination type of %s", string(tfe.NotificationDestinationTypeMicrosoftTeams))
Expand All @@ -403,7 +403,7 @@ func validateSchemaAttributesForDestinationTypeMicrosoftTeams(d *schema.Resource
return fmt.Errorf("Token cannot be set with destination type of %s", string(tfe.NotificationDestinationTypeMicrosoftTeams))
}

// Make sure url is set when destination_type is 'microsoft_teams'
// Make sure url is set when destination_type is 'microsoft-teams'
_, urlIsSet := d.GetOk("url")
if !urlIsSet {
return fmt.Errorf("URL is required with destination type of %s", string(tfe.NotificationDestinationTypeMicrosoftTeams))
Expand Down
28 changes: 14 additions & 14 deletions tfe/resource_tfe_notification_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,19 +257,19 @@ func TestAccTFENotificationConfiguration_validateSchemaAttributesMicrosoftTeams(
Steps: []resource.TestStep{
{
Config: testAccTFENotificationConfiguration_microsoftTeamsWithEmailAddresses(rInt),
ExpectError: regexp.MustCompile(`Email addresses cannot be set with destination type of microsoft_teams`),
ExpectError: regexp.MustCompile(`Email addresses cannot be set with destination type of microsoft-teams`),
},
{
Config: testAccTFENotificationConfiguration_microsoftTeamsWithEmailUserIDs(rInt),
ExpectError: regexp.MustCompile(`Email user IDs cannot be set with destination type of microsoft_teams`),
ExpectError: regexp.MustCompile(`Email user IDs cannot be set with destination type of microsoft-teams`),
},
{
Config: testAccTFENotificationConfiguration_microsoftTeamsWithToken(rInt),
ExpectError: regexp.MustCompile(`Token cannot be set with destination type of microsoft_teams`),
ExpectError: regexp.MustCompile(`Token cannot be set with destination type of microsoft-teams`),
},
{
Config: testAccTFENotificationConfiguration_microsoftTeamsWithoutURL(rInt),
ExpectError: regexp.MustCompile(`URL is required with destination type of microsoft_teams`),
ExpectError: regexp.MustCompile(`URL is required with destination type of microsoft-teams`),
},
},
})
Expand Down Expand Up @@ -420,7 +420,7 @@ func TestAccTFENotificationConfiguration_updateValidateSchemaAttributesMicrosoft
"tfe_notification_configuration.foobar", notificationConfiguration),
testAccCheckTFENotificationConfigurationAttributesMicrosoftTeams(notificationConfiguration),
resource.TestCheckResourceAttr(
"tfe_notification_configuration.foobar", "destination_type", "microsoft_teams"),
"tfe_notification_configuration.foobar", "destination_type", "microsoft-teams"),
resource.TestCheckResourceAttr(
"tfe_notification_configuration.foobar", "name", "notification_msteams"),
resource.TestCheckResourceAttr(
Expand All @@ -429,19 +429,19 @@ func TestAccTFENotificationConfiguration_updateValidateSchemaAttributesMicrosoft
},
{
Config: testAccTFENotificationConfiguration_microsoftTeamsWithEmailAddresses(rInt),
ExpectError: regexp.MustCompile(`Email addresses cannot be set with destination type of microsoft_teams`),
ExpectError: regexp.MustCompile(`Email addresses cannot be set with destination type of microsoft-teams`),
},
{
Config: testAccTFENotificationConfiguration_microsoftTeamsWithEmailUserIDs(rInt),
ExpectError: regexp.MustCompile(`Email user IDs cannot be set with destination type of microsoft_teams`),
ExpectError: regexp.MustCompile(`Email user IDs cannot be set with destination type of microsoft-teams`),
},
{
Config: testAccTFENotificationConfiguration_microsoftTeamsWithToken(rInt),
ExpectError: regexp.MustCompile(`Token cannot be set with destination type of microsoft_teams`),
ExpectError: regexp.MustCompile(`Token cannot be set with destination type of microsoft-teams`),
},
{
Config: testAccTFENotificationConfiguration_microsoftTeamsWithoutURL(rInt),
ExpectError: regexp.MustCompile(`URL is required with destination type of microsoft_teams`),
ExpectError: regexp.MustCompile(`URL is required with destination type of microsoft-teams`),
},
},
})
Expand Down Expand Up @@ -861,7 +861,7 @@ resource "tfe_workspace" "foobar" {

resource "tfe_notification_configuration" "foobar" {
name = "notification_msteams"
destination_type = "microsoft_teams"
destination_type = "microsoft-teams"
url = "http://example.com"
workspace_id = tfe_workspace.foobar.id
}`, rInt)
Expand Down Expand Up @@ -1119,7 +1119,7 @@ resource "tfe_workspace" "foobar" {

resource "tfe_notification_configuration" "foobar" {
name = "notification_msteams_with_email_addresses"
destination_type = "microsoft_teams"
destination_type = "microsoft-teams"
email_addresses = ["[email protected]", "[email protected]"]
workspace_id = tfe_workspace.foobar.id
}`, rInt)
Expand All @@ -1144,7 +1144,7 @@ resource "tfe_organization_membership" "foobar" {

resource "tfe_notification_configuration" "foobar" {
name = "notification_msteams_with_email_user_ids"
destination_type = "microsoft_teams"
destination_type = "microsoft-teams"
email_user_ids = [tfe_organization_membership.foobar.id]
workspace_id = tfe_workspace.foobar.id
}`, rInt)
Expand All @@ -1164,7 +1164,7 @@ resource "tfe_workspace" "foobar" {

resource "tfe_notification_configuration" "foobar" {
name = "notification_msteams_with_token"
destination_type = "microsoft_teams"
destination_type = "microsoft-teams"
token = "1234567890"
url = "http://example.com"
workspace_id = tfe_workspace.foobar.id
Expand All @@ -1185,7 +1185,7 @@ resource "tfe_workspace" "foobar" {

resource "tfe_notification_configuration" "foobar" {
name = "notification_msteams_without_url"
destination_type = "microsoft_teams"
destination_type = "microsoft-teams"
workspace_id = tfe_workspace.foobar.id
}`, rInt)
}
Expand Down
10 changes: 5 additions & 5 deletions website/docs/r/notification_configuration.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,21 @@ The following arguments are supported:
* `generic`
* `email` available in Terraform Cloud or Terraform Enterprise v202005-1 or later
* `slack`
* `microsoft_teams` available in Terraform Cloud or Terraform Enterprise v202206-1 or later
* `microsoft-teams` available in Terraform Cloud or Terraform Enterprise v202206-1 or later
* `email_addresses` - (Optional) **TFE only** A list of email addresses. This value
_must not_ be provided if `destination_type` is `generic`, `microsoft_teams`, or `slack`.
_must not_ be provided if `destination_type` is `generic`, `microsoft-teams`, or `slack`.
* `email_user_ids` - (Optional) A list of user IDs. This value _must not_ be provided
if `destination_type` is `generic`, `microsoft_teams`, or `slack`.
if `destination_type` is `generic`, `microsoft-teams`, or `slack`.
* `enabled` - (Optional) Whether the notification configuration should be enabled or not.
Disabled configurations will not send any notifications. Defaults to `false`.
* `token` - (Optional) A write-only secure token for the notification configuration, which can
be used by the receiving server to verify request authenticity when configured for notification
configurations with a destination type of `generic`. Defaults to `null`.
This value _must not_ be provided if `destination_type` is `email`, `microsoft_teams`, or `slack`.
This value _must not_ be provided if `destination_type` is `email`, `microsoft-teams`, or `slack`.
* `triggers` - (Optional) The array of triggers for which this notification configuration will
send notifications. Valid values are `run:created`, `run:planning`, `run:needs_attention`, `run:applying`
`run:completed`, `run:errored`. If omitted, no notification triggers are configured.
* `url` - (Required if `destination_type` is `generic`, `microsoft_teams`, or `slack`) The HTTP or HTTPS URL of the notification
* `url` - (Required if `destination_type` is `generic`, `microsoft-teams`, or `slack`) The HTTP or HTTPS URL of the notification
configuration where notification requests will be made. This value _must not_ be provided if `destination_type`
is `email`.
* `workspace_id` - (Required) The id of the workspace that owns the notification configuration.
Expand Down