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 support for importing organization-level webhooks #487

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions github/resource_github_organization_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ func resourceGithubOrganizationWebhook() *schema.Resource {
Read: resourceGithubOrganizationWebhookRead,
Update: resourceGithubOrganizationWebhookUpdate,
Delete: resourceGithubOrganizationWebhookDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

SchemaVersion: 1,
MigrateState: resourceGithubWebhookMigrateState,
Expand Down Expand Up @@ -155,6 +158,8 @@ func resourceGithubOrganizationWebhookRead(d *schema.ResourceData, meta interfac
}
}

hook.Config = insecureSslStringToBool(hook.Config)

d.Set("configuration", []interface{}{hook.Config})

return nil
Expand Down
16 changes: 15 additions & 1 deletion github/resource_github_organization_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"

"github.com/google/go-github/v32/github"
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)
Expand All @@ -19,7 +20,7 @@ func TestAccGithubOrganizationWebhook_basic(t *testing.T) {
}

var hook github.Hook

randString := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)
rn := "github_organization_webhook.foo"

resource.ParallelTest(t, resource.TestCase{
Expand Down Expand Up @@ -57,6 +58,12 @@ func TestAccGithubOrganizationWebhook_basic(t *testing.T) {
}),
),
},
{
ResourceName: rn,
ImportState: true,
ImportStateVerify: true,
ImportStateIdPrefix: fmt.Sprintf("foo-%s/", randString),
},
},
})
}
Expand All @@ -67,6 +74,7 @@ func TestAccGithubOrganizationWebhook_secret(t *testing.T) {
}

rn := "github_organization_webhook.foo"
randString := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -79,6 +87,12 @@ func TestAccGithubOrganizationWebhook_secret(t *testing.T) {
testAccCheckGithubOrganizationWebhookSecret(rn, "VerySecret"),
),
},
{
ResourceName: rn,
ImportState: true,
ImportStateVerify: true,
ImportStateIdPrefix: fmt.Sprintf("foo-%s/", randString),
},
},
})
}
Expand Down
11 changes: 11 additions & 0 deletions website/docs/r/organization_webhook.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,14 @@ The following arguments are supported:
The following additional attributes are exported:

* `url` - URL of the webhook

## Import

Organization webhooks can be imported using the `id` of the webhook.
The `id` of the webhook can be found in the URL of the webhook. For example, `"https://github.com/organizations/foo-org/settings/hooks/123456789"`.

```
$ terraform import github_organization_webhook.terraform 123456789
```

If secret is populated in the webhook's configuration, the value will be imported as "********".