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 'name' to webhook resource, support for setting name in create/update operations #114

Merged
merged 2 commits into from
Dec 10, 2024

Conversation

ryanrhanson
Copy link
Contributor

@ryanrhanson ryanrhanson commented Dec 3, 2024

This adds support to the terraform provider for the 'name' field on webhook creation and update.

I've tested locally with creation and update of webhooks via Terraform.

Closes ENG-8677.

@ryanrhanson ryanrhanson self-assigned this Dec 4, 2024
Copy link
Member

@nmanoogian nmanoogian left a comment

Choose a reason for hiding this comment

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

Nice work! Just two small pieces are missing here:

  • We need to add the webhook name to the fetched model and read function. This ensures that if the webhook is renamed outside of Terraform, we'll detect and correct it
  • The Doppler API distinguishes between an empty string webhook name and a null name. The difference is subtle but empty string names look weird in the logs. Golang strings don't have a null/nil state so the most intuitive thing is probably to just treat empty strings as null/nil during serialization

Here's a patch containing fixes for both points:

diff --git a/doppler/api.go b/doppler/api.go
index 6d33c51..1b0b260 100644
--- a/doppler/api.go
+++ b/doppler/api.go
@@ -805,7 +805,11 @@ func (client APIClient) UpdateWebhook(ctx context.Context, project string, slug
 	payload["url"] = webhookUrl
 	payload["secret"] = secret
 	payload["payload"] = webhookPayload
-	payload["name"] = webhookName
+	if webhookName != "" {
+		payload["name"] = webhookName
+	} else {
+		payload["name"] = nil
+	}
 	payload["enableConfigs"] = enabledConfigs
 	payload["disableConfigs"] = disabledConfigs
 	payload["authentication"] = auth
diff --git a/doppler/models.go b/doppler/models.go
index a86b4fc..aa8258c 100644
--- a/doppler/models.go
+++ b/doppler/models.go
@@ -160,6 +160,7 @@ type WebhookAuth struct {
 
 type Webhook struct {
 	Slug           string   `json:"id"`
+	Name           string   `json:"name"`
 	Url            string   `json:"url"`
 	Enabled        bool     `json:"enabled"`
 	EnabledConfigs []string `json:"enabledConfigs"`
diff --git a/doppler/resource_webhook.go b/doppler/resource_webhook.go
index 3c10cf1..315e163 100644
--- a/doppler/resource_webhook.go
+++ b/doppler/resource_webhook.go
@@ -248,6 +248,10 @@ func resourceWebhookRead(ctx context.Context, d *schema.ResourceData, m interfac
 		return diag.FromErr(err)
 	}
 
+	if err = d.Set("name", webhook.Name); err != nil {
+		return diag.FromErr(err)
+	}
+
 	return diags
 }
 

If you haven't used these before, you can apply the patch by copying it and doing pbpaste | git apply.

@nmanoogian nmanoogian merged commit 2f779c1 into master Dec 10, 2024
4 checks passed
@nmanoogian nmanoogian deleted the add_name_to_webhook_create_update branch December 10, 2024 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants