Skip to content

Commit

Permalink
Add support for importing organization-level webhooks (integrations#487)
Browse files Browse the repository at this point in the history
Co-authored-by: Jeremy Udit <jcudit@github.com>
  • Loading branch information
mhuxtable and Jeremy Udit authored Nov 5, 2020
1 parent 46d338a commit d25ebd5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
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 "********".

0 comments on commit d25ebd5

Please sign in to comment.