Skip to content

Commit

Permalink
Add support for importing organization-level webhooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Huxtable committed Jun 10, 2020
1 parent 60fff96 commit 28cbe56
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
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
17 changes: 15 additions & 2 deletions github/resource_github_organization_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import (
"testing"

"github.com/google/go-github/v31/github"
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)

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 @@ -53,13 +54,19 @@ func TestAccGithubOrganizationWebhook_basic(t *testing.T) {
}),
),
},
{
ResourceName: rn,
ImportState: true,
ImportStateVerify: true,
ImportStateIdPrefix: fmt.Sprintf("foo-%s/", randString),
},
},
})
}

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 @@ -72,6 +79,12 @@ func TestAccGithubOrganizationWebhook_secret(t *testing.T) {
testAccCheckGithubOrganizationWebhookSecret(rn, "VerySecret"),
),
},
{
ResourceName: rn,
ImportState: true,
ImportStateVerify: true,
ImportStateIdPrefix: fmt.Sprintf("foo-%s/", randString),
},
},
})
}
Expand Down

0 comments on commit 28cbe56

Please sign in to comment.