From 74126593ebc5c5082c182f15442d3cecd1f7728d Mon Sep 17 00:00:00 2001 From: Erik Osterman Date: Wed, 10 Jun 2020 16:10:17 -0700 Subject: [PATCH] fix "protocol scheme" error (#18) * fix-protocol-scheme-error * set api * set api * set github_token var * added anonymous var * fix test --- README.md | 2 ++ docs/terraform.md | 2 ++ main.tf | 5 +++-- test/src/examples_complete_test.go | 3 +-- variables.tf | 12 ++++++++++++ 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 319729d..f136b21 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,8 @@ Available targets: | active | Indicate of the webhook should receive events | bool | `true` | no | | enabled | Whether or not to enable this module | bool | `true` | no | | events | A list of events which should trigger the webhook. | list(string) | `` | no | +| github_anonymous | Github Anonymous API (if `true`, token must not be set as GITHUB_TOKEN or `github_token`) | bool | `false` | no | +| github_base_url | GitHub target API endpoint | string | `https://api.github.com/` | no | | github_organization | GitHub organization to use when creating webhooks | string | - | yes | | github_repositories | List of repository names which should be associated with the webhook | list(string) | `` | no | | github_token | GitHub token used for API access. If not provided, can be sourced from the `GITHUB_TOKEN` environment variable | string | `` | no | diff --git a/docs/terraform.md b/docs/terraform.md index b63ac76..cd2e869 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -5,6 +5,8 @@ | active | Indicate of the webhook should receive events | bool | `true` | no | | enabled | Whether or not to enable this module | bool | `true` | no | | events | A list of events which should trigger the webhook. | list(string) | `` | no | +| github_anonymous | Github Anonymous API (if `true`, token must not be set as GITHUB_TOKEN or `github_token`) | bool | `false` | no | +| github_base_url | GitHub target API endpoint | string | `https://api.github.com/` | no | | github_organization | GitHub organization to use when creating webhooks | string | - | yes | | github_repositories | List of repository names which should be associated with the webhook | list(string) | `` | no | | github_token | GitHub token used for API access. If not provided, can be sourced from the `GITHUB_TOKEN` environment variable | string | `` | no | diff --git a/main.tf b/main.tf index ed69478..4e1061d 100644 --- a/main.tf +++ b/main.tf @@ -1,7 +1,8 @@ provider "github" { token = var.github_token != "" ? var.github_token : null organization = var.github_organization - anonymous = var.github_token != "" ? false : true + anonymous = var.github_anonymous + base_url = var.github_base_url } resource "github_repository_webhook" "default" { @@ -21,6 +22,6 @@ resource "github_repository_webhook" "default" { lifecycle { # This is required for idempotency - ignore_changes = ["configuration[0].secret"] + ignore_changes = [configuration[0].secret] } } diff --git a/test/src/examples_complete_test.go b/test/src/examples_complete_test.go index 40556c1..e126a03 100644 --- a/test/src/examples_complete_test.go +++ b/test/src/examples_complete_test.go @@ -28,7 +28,6 @@ func TestExamplesComplete(t *testing.T) { // Run `terraform output` to get the value of an output variable webhookUrl := terraform.Output(t, terraformOptions, "webhook_url") - expectedWebhookUrl := "https://archive.sweetops.com" // Verify we're getting back the outputs we expect - assert.Equal(t, expectedWebhookUrl, webhookUrl) + assert.Regexp(t, "^https://api.github.com/repos/.+/hooks/[0-9]+$", webhookUrl) } diff --git a/variables.tf b/variables.tf index d02f660..6646923 100644 --- a/variables.tf +++ b/variables.tf @@ -15,6 +15,18 @@ variable "github_organization" { description = "GitHub organization to use when creating webhooks" } +variable "github_base_url" { + type = string + description = "GitHub target API endpoint" + default = "https://api.github.com/" +} + +variable "github_anonymous" { + type = bool + description = "Github Anonymous API (if `true`, token must not be set as GITHUB_TOKEN or `github_token`)" + default = false +} + variable "github_repositories" { type = list(string) description = "List of repository names which should be associated with the webhook"