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 20 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.

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?

Copy link
Member

Choose a reason for hiding this comment

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

where we do a required on generic, ms-teams, slack. Why not just require email?
but you need to have notification_type to be email if you were to supply email_user_id or email_address field correct?

the logic is slight inverted. it boils down to "if destination_type is set to generic, slack, etc, then require that url is also set." what you're asking for is the opposite: "if email_user_ids is set, then require that destination_type is email."

as far as I know, inspecting the value of the other attribute would require adding one more custom validator (there are already two new ones in this PR). but in this case we can make do with using one of the one's we're already adding.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, yea if we need an additional custom validator to achieve the same thing then it wouldn't make sense.

simonxmh
simonxmh previously approved these changes Jan 17, 2025
ctrombley
ctrombley previously approved these changes Jan 17, 2025
Copy link
Contributor

@ctrombley ctrombley left a comment

Choose a reason for hiding this comment

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

Looks good! Approved with some comments, but no blockers.

Comment on lines 68 to 76
if emailAddresses, err := types.SetValueFrom(ctx, types.StringType, v.EmailAddresses); err == nil {
result.EmailAddresses = emailAddresses
}

if len(v.Triggers) == 0 {
result.Triggers = types.SetNull(types.StringType)
} else if triggers, err := types.SetValueFrom(ctx, types.StringType, v.Triggers); err == nil {
result.Triggers = triggers
}
Copy link
Contributor

Choose a reason for hiding this comment

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

In both cases here, is the err != nil case worth a diagnostic warning? Or are we sure that won't happen based on how the config is parsed in the methods below?

Copy link
Member

Choose a reason for hiding this comment

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

I ended up just exposing diagnostics to the caller generating the model and halting if there are any errors

}

// Add email_addresses set to the options struct
emailAddresses := make([]types.String, 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider:

Suggested change
emailAddresses := make([]types.String, 0)
emailAddresses := make([]types.String, len(plan.Triggers.Elements()))

There are some other places in the PR where we can allocate to a known length.

Copy link
Member

Choose a reason for hiding this comment

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

these should all be good now

@notchairmk notchairmk dismissed stale reviews from ctrombley and simonxmh via 49806ea January 17, 2025 21:48
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.

4 participants