From d25ebd594d51ea57332ca4a8fb2c8250bb31e105 Mon Sep 17 00:00:00 2001 From: Matthew Huxtable Date: Thu, 5 Nov 2020 13:01:14 +0000 Subject: [PATCH] Add support for importing organization-level webhooks (#487) Co-authored-by: Jeremy Udit --- github/resource_github_organization_webhook.go | 5 +++++ .../resource_github_organization_webhook_test.go | 16 +++++++++++++++- .../docs/r/organization_webhook.html.markdown | 11 +++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/github/resource_github_organization_webhook.go b/github/resource_github_organization_webhook.go index e6431f679c..9bbd3b810b 100644 --- a/github/resource_github_organization_webhook.go +++ b/github/resource_github_organization_webhook.go @@ -17,6 +17,9 @@ func resourceGithubOrganizationWebhook() *schema.Resource { Read: resourceGithubOrganizationWebhookRead, Update: resourceGithubOrganizationWebhookUpdate, Delete: resourceGithubOrganizationWebhookDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, SchemaVersion: 1, MigrateState: resourceGithubWebhookMigrateState, @@ -155,6 +158,8 @@ func resourceGithubOrganizationWebhookRead(d *schema.ResourceData, meta interfac } } + hook.Config = insecureSslStringToBool(hook.Config) + d.Set("configuration", []interface{}{hook.Config}) return nil diff --git a/github/resource_github_organization_webhook_test.go b/github/resource_github_organization_webhook_test.go index f4b415a406..a8584a2943 100644 --- a/github/resource_github_organization_webhook_test.go +++ b/github/resource_github_organization_webhook_test.go @@ -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" ) @@ -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{ @@ -57,6 +58,12 @@ func TestAccGithubOrganizationWebhook_basic(t *testing.T) { }), ), }, + { + ResourceName: rn, + ImportState: true, + ImportStateVerify: true, + ImportStateIdPrefix: fmt.Sprintf("foo-%s/", randString), + }, }, }) } @@ -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) }, @@ -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), + }, }, }) } diff --git a/website/docs/r/organization_webhook.html.markdown b/website/docs/r/organization_webhook.html.markdown index 9f51b1536a..8bacb1ac3e 100644 --- a/website/docs/r/organization_webhook.html.markdown +++ b/website/docs/r/organization_webhook.html.markdown @@ -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 "********".