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

feat: add azure devops servicehook webhook resource #461

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

Conversation

iswym
Copy link

@iswym iswym commented Oct 8, 2021

All Submissions:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • My code follows the code style of this project.
  • I ran lint checks locally prior to submission.
  • Have you checked to ensure there aren't other open PRs for the same update/change?

What about the current behavior has changed?

Added:

  • resource azuredevops_servicehook_webhook
  • acceptance tests for azuredevops_servicehook_webhook resource
  • documentation for azuredevops_servicehook_webhook resource

Does this introduce a change to go.mod, go.sum or vendor/?

  • Yes
  • No

reason:

  • minor bump in azure-devops-go-api dependency
  • service hooks client is now being used

Does this introduce a breaking change?

  • Yes
  • No

Any relevant logs, error output, etc?

Other information

Locally built and tested manually.

@ghost
Copy link

ghost commented Oct 8, 2021

CLA assistant check
All CLA requirements met.

@iswym iswym force-pushed the azuredevops_servicehooks_webhook branch 3 times, most recently from bb46b23 to 6856988 Compare October 9, 2021 21:25
… for azuredevops_servicehook_webhook resource
Copy link
Collaborator

@xuzhang3 xuzhang3 left a comment

Choose a reason for hiding this comment

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

@iswym Thanks for your PR, a few changes requested. I was concerning that this resource support so many event type and filter and all of the have an internal name for them, if user set the wrong name, service will return an error and won't be able to create this resource. It would be great if we can document the event types and filer names in the document.

"updated_at": {
Type: schema.TypeString,
Computed: true,
ForceNew: true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Considering this property is a Computed, ForceNew should removed.

"url": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.IsURLWithHTTPS,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggest ValidateFunc: validation.IsURLWithHTTPorHTTPS, , in case of HTTP URL.

return nil
}

func getSubscription(d *schema.ResourceData) servicehooks.Subscription {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
func getSubscription(d *schema.ResourceData) servicehooks.Subscription {
func expandSubscription(d *schema.ResourceData) servicehooks.Subscription {

})

if err != nil {
return err
Copy link
Collaborator

Choose a reason for hiding this comment

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

Error message should return more context information which will help to locate the issue.
For example: return fmt.Errorf(" Create Web Hook Comsumer failed. EventType: %s, ComsumerID: %s. Error: %+v ", *subscription.EventType, *subscriptionData.ConsumerId, err)

subscriptionId := d.Id()

subscription, err := clients.ServiceHooksClient.GetSubscription(clients.Ctx, servicehooks.GetSubscriptionArgs{
SubscriptionId: converter.UUID(subscriptionId),
Copy link
Collaborator

Choose a reason for hiding this comment

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

subscriptionId can be replace by d.Id()

})

if err != nil {
return err
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same like above, error message should return more context information which will help to locate the issue.

basicAuth["username"] = username
}

if password, ok := basicAuth["password"]; ok && !afterCreateOrUpdate && oldUpdatedAt != newUpdatedAt {
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. afterCreateOrUpdate can be removed. The first d.Get("updated_at"), oldUpdatedAt will be an empty string, this can be used to determine if the password has been updated out of terraform
  2. Any configuration changing in this resource will update the updated_at, not only for password. We cannot detect the password changes.

{
Config: hclSvcHookWebhookResourceBasic(projectName, eventType, url),
Check: resource.ComposeTestCheckFunc(
testutils.CheckServiceHookWebhookExistsWithEventTypeAndUrl(tfSvcHookNode, eventType, url),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Duplicate with resource.TestCheckResourceAttr(tfSvcHookNode, "event_type", eventType), and resource.TestCheckResourceAttr(tfSvcHookNode, "url", url),

- `event_type` - (Required) Event type.
- `url` - (Required) The url of the hook to invoke.
- `basic_auth` - (Optional) Basic authentication.
- `username`
Copy link
Collaborator

Choose a reason for hiding this comment

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

The description of username and password are empty.


## Relevant Links

- [Azure DevOps Service REST API 5.1 - Service hooks](https://docs.microsoft.com/en-us/rest/api/azure/devops/hooks/?view=azure-devops-rest-5.1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

@tiwood
Copy link
Contributor

tiwood commented Feb 3, 2022

@xuzhang3 @iswym

Thanks for the PR! Is there anything we can help to get this merged?
I've just found out, that we may need a way to create service hooks rather quickly 😂️

@tmeckel
Copy link
Contributor

tmeckel commented Feb 4, 2022

Since the provider was upgraded to API v6 a rebase must be done in addition to the requested changes by @xuzhang3

@xuzhang3
Copy link
Collaborator

@tiwood @tmeckel can you help rebase to the latest code?

@TechnicallyJoe
Copy link

Any news on this? - We're really missing the service hook functionality :)

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

Successfully merging this pull request may close these issues.

5 participants