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 tfe_team_notification_configuration resource #1540

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

jfreda
Copy link
Member

@jfreda jfreda commented Dec 7, 2024

Description

This PR adds a new tfe_team_notification_configuration resource for team notification configurations.

Remember to:

Testing plan

provider "tfe" {}

resource "tfe_organization" "example" {
  name  = "example-org"
  email = "[email protected]"
}

resource "tfe_team" "example" {
  name         = "example-team"
  organization = tfe_organization.example.id
}

resource "tfe_team_notification_configuration" "example" {
  name             = "example"
  destination_type = "generic"
  url              = "https://httpstat.us/200"
  team_id          = tfe_team.example.id
} 

External links

Output from acceptance tests

$ TESTARGS="-run TestAccTFETeamNotificationConfiguration" make testacc
?   	github.com/hashicorp/terraform-provider-tfe	[no test files]
testing: warning: no tests to run
PASS
ok  	github.com/hashicorp/terraform-provider-tfe/internal/client	(cached) [no tests to run]
testing: warning: no tests to run
PASS
ok  	github.com/hashicorp/terraform-provider-tfe/internal/logging	(cached) [no tests to run]
?   	github.com/hashicorp/terraform-provider-tfe/internal/provider/validators	[no test files]
?   	github.com/hashicorp/terraform-provider-tfe/version	[no test files]
=== RUN   TestAccTFETeamNotificationConfiguration_basic
--- PASS: TestAccTFETeamNotificationConfiguration_basic (5.85s)
=== RUN   TestAccTFETeamNotificationConfiguration_emailUserIDs
--- PASS: TestAccTFETeamNotificationConfiguration_emailUserIDs (6.13s)
=== RUN   TestAccTFETeamNotificationConfiguration_update
--- PASS: TestAccTFETeamNotificationConfiguration_update (8.60s)
=== RUN   TestAccTFETeamNotificationConfiguration_updateEmailUserIDs
--- PASS: TestAccTFETeamNotificationConfiguration_updateEmailUserIDs (11.47s)
=== RUN   TestAccTFETeamNotificationConfiguration_validateSchemaAttributesEmail
--- PASS: TestAccTFETeamNotificationConfiguration_validateSchemaAttributesEmail (0.21s)
=== RUN   TestAccTFETeamNotificationConfiguration_validateSchemaAttributesGeneric
--- PASS: TestAccTFETeamNotificationConfiguration_validateSchemaAttributesGeneric (0.22s)
=== RUN   TestAccTFETeamNotificationConfiguration_validateSchemaAttributesSlack
--- PASS: TestAccTFETeamNotificationConfiguration_validateSchemaAttributesSlack (0.26s)
=== RUN   TestAccTFETeamNotificationConfiguration_validateSchemaAttributesMicrosoftTeams
--- PASS: TestAccTFETeamNotificationConfiguration_validateSchemaAttributesMicrosoftTeams (0.26s)
=== RUN   TestAccTFETeamNotificationConfiguration_validateSchemaAttributesBadDestinationType
--- PASS: TestAccTFETeamNotificationConfiguration_validateSchemaAttributesBadDestinationType (0.13s)
=== RUN   TestAccTFETeamNotificationConfiguration_updateValidateSchemaAttributesEmail
--- PASS: TestAccTFETeamNotificationConfiguration_updateValidateSchemaAttributesEmail (9.62s)
=== RUN   TestAccTFETeamNotificationConfiguration_updateValidateSchemaAttributesGeneric
--- PASS: TestAccTFETeamNotificationConfiguration_updateValidateSchemaAttributesGeneric (7.81s)
=== RUN   TestAccTFETeamNotificationConfiguration_updateValidateSchemaAttributesSlack
--- PASS: TestAccTFETeamNotificationConfiguration_updateValidateSchemaAttributesSlack (7.89s)
=== RUN   TestAccTFETeamNotificationConfiguration_updateValidateSchemaAttributesMicrosoftTeams
--- PASS: TestAccTFETeamNotificationConfiguration_updateValidateSchemaAttributesMicrosoftTeams (7.62s)
=== RUN   TestAccTFETeamNotificationConfiguration_duplicateTriggers
--- PASS: TestAccTFETeamNotificationConfiguration_duplicateTriggers (5.33s)
=== RUN   TestAccTFETeamNotificationConfigurationImport_basic
--- PASS: TestAccTFETeamNotificationConfigurationImport_basic (6.08s)
=== RUN   TestAccTFETeamNotificationConfigurationImport_emailUserIDs
--- PASS: TestAccTFETeamNotificationConfigurationImport_emailUserIDs (8.14s)
=== RUN   TestAccTFETeamNotificationConfigurationImport_emptyEmailUserIDs
--- PASS: TestAccTFETeamNotificationConfigurationImport_emptyEmailUserIDs (6.85s)
PASS
ok  	github.com/hashicorp/terraform-provider-tfe/internal/provider	93.437s
...

@jfreda jfreda requested a review from a team December 7, 2024 01:51
@notchairmk notchairmk marked this pull request as ready for review January 9, 2025 21:57
@notchairmk notchairmk requested a review from a team as a code owner January 9, 2025 21:57
@notchairmk
Copy link
Member

New tests are passing when run against local env

RUN_TASKS_URL=<webhook-url> TFE_TOKEN=<token> TFE_ADMIN_PROVISION_LICENSES_TOKEN=<token> ENABLE_BETA=1 TESTARGS='-run "TestAccTFETeamNotificationConfiguration"' make testacc
TF_ACC=1 TF_LOG_SDK_PROTO=OFF go test $(go list ./... |grep -v 'vendor') -v -run "TestAccTFETeamNotificationConfiguration" -timeout 15m
?       github.com/hashicorp/terraform-provider-tfe     [no test files]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-tfe/internal/client     (cached) [no tests to run]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-tfe/internal/logging    (cached) [no tests to run]
?       github.com/hashicorp/terraform-provider-tfe/internal/provider/validators        [no test files]
?       github.com/hashicorp/terraform-provider-tfe/version     [no test files]
=== RUN   TestAccTFETeamNotificationConfiguration_basic
--- PASS: TestAccTFETeamNotificationConfiguration_basic (7.00s)
=== RUN   TestAccTFETeamNotificationConfiguration_emailUserIDs
--- PASS: TestAccTFETeamNotificationConfiguration_emailUserIDs (7.21s)
=== RUN   TestAccTFETeamNotificationConfiguration_update
--- PASS: TestAccTFETeamNotificationConfiguration_update (10.65s)
=== RUN   TestAccTFETeamNotificationConfiguration_updateEmailUserIDs
--- PASS: TestAccTFETeamNotificationConfiguration_updateEmailUserIDs (11.23s)
=== RUN   TestAccTFETeamNotificationConfiguration_validateSchemaAttributesEmail
--- PASS: TestAccTFETeamNotificationConfiguration_validateSchemaAttributesEmail (1.66s)
=== RUN   TestAccTFETeamNotificationConfiguration_validateSchemaAttributesGeneric
--- PASS: TestAccTFETeamNotificationConfiguration_validateSchemaAttributesGeneric (1.82s)
=== RUN   TestAccTFETeamNotificationConfiguration_validateSchemaAttributesSlack
--- PASS: TestAccTFETeamNotificationConfiguration_validateSchemaAttributesSlack (1.90s)
=== RUN   TestAccTFETeamNotificationConfiguration_validateSchemaAttributesMicrosoftTeams
--- PASS: TestAccTFETeamNotificationConfiguration_validateSchemaAttributesMicrosoftTeams (1.93s)
=== RUN   TestAccTFETeamNotificationConfiguration_validateSchemaAttributesBadDestinationType
--- PASS: TestAccTFETeamNotificationConfiguration_validateSchemaAttributesBadDestinationType (1.64s)
=== RUN   TestAccTFETeamNotificationConfiguration_updateValidateSchemaAttributesEmail
--- PASS: TestAccTFETeamNotificationConfiguration_updateValidateSchemaAttributesEmail (10.05s)
=== RUN   TestAccTFETeamNotificationConfiguration_updateValidateSchemaAttributesGeneric
--- PASS: TestAccTFETeamNotificationConfiguration_updateValidateSchemaAttributesGeneric (9.74s)
=== RUN   TestAccTFETeamNotificationConfiguration_updateValidateSchemaAttributesSlack
--- PASS: TestAccTFETeamNotificationConfiguration_updateValidateSchemaAttributesSlack (9.68s)
=== RUN   TestAccTFETeamNotificationConfiguration_updateValidateSchemaAttributesMicrosoftTeams
--- PASS: TestAccTFETeamNotificationConfiguration_updateValidateSchemaAttributesMicrosoftTeams (9.65s)
=== RUN   TestAccTFETeamNotificationConfiguration_duplicateTriggers
--- PASS: TestAccTFETeamNotificationConfiguration_duplicateTriggers (5.97s)
=== RUN   TestAccTFETeamNotificationConfigurationImport_basic
--- PASS: TestAccTFETeamNotificationConfigurationImport_basic (7.26s)
=== RUN   TestAccTFETeamNotificationConfigurationImport_emailUserIDs
--- PASS: TestAccTFETeamNotificationConfigurationImport_emailUserIDs (9.00s)
=== RUN   TestAccTFETeamNotificationConfigurationImport_emptyEmailUserIDs
--- PASS: TestAccTFETeamNotificationConfigurationImport_emptyEmailUserIDs (7.79s)
PASS
ok      github.com/hashicorp/terraform-provider-tfe/internal/provider   114.695s
⏎

simonxmh
simonxmh previously approved these changes Jan 15, 2025
Copy link
Contributor

@simonxmh simonxmh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with generic and email notifications. Small questions on validation

name = "my-test-email-notification-configuration"
enabled = true
destination_type = "email"
email_user_ids = [tfe_organization_membership.test.user_id]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this supposedly doesn't work on non-TFE

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what part doesn't work?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought you mentioned that emailing specific users was only on TFE, I may have misunderstood?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the example add the user to the team, not sure if that's the part that was failing for you or if it was something else.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the email_addresses will only work for TFE (there's an example for that one below this as well). but email_user_ids should work fine for both.

Description: "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`.",
Optional: true,
Sensitive: true,
Validators: []validator.String{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add the setvalidator to conflict with email_addresses andemail_user_id here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my preference is to only have conflicts in one place, otherwise the UX is kind of obnoxious. the validations were in a somewhat inconsistent state, so I consolidated them more

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay! sounds good

Computed: true,
ElementType: types.StringType,
Validators: []validator.Set{
validators.AttributeValueConflictSetValidator(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering when we would opt for attribute required vs attribute conflicts the other options? The required option seems to be more straightforward

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are you thinking the required logic would look like?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm seeing this logic
https://github.com/hashicorp/terraform-provider-tfe/pull/1540/files#diff-ad99357d00b5259c75af9f4a94edadd00fe2235ed7e23214b95a984d72845e2aR214

where we do a required on generic, ms-teams, slack. Why not just require email?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in that case, URL is required to create any of those types of notifications — it's enforced by the API. the API doesn't require the notification to have an email_user_id nor email_address for email notifications though

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but you need to have notification_type to be email if you were to supply email_user_id or email_address field correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants