diff --git a/github/provider.go b/github/provider.go index 3a3b24863c..cd4e905ade 100644 --- a/github/provider.go +++ b/github/provider.go @@ -18,11 +18,11 @@ func Provider() *schema.Provider { p := &schema.Provider{ Schema: map[string]*schema.Schema{ "token": { - Type: schema.TypeString, - Optional: true, - DefaultFunc: schema.EnvDefaultFunc("GITHUB_TOKEN", nil), - Description: descriptions["token"], - ExactlyOneOf: []string{"app_auth"}, + Type: schema.TypeString, + Optional: true, + DefaultFunc: schema.EnvDefaultFunc("GITHUB_TOKEN", nil), + Description: descriptions["token"], + ConflictsWith: []string{"app_auth"}, }, "owner": { Type: schema.TypeString, @@ -94,11 +94,11 @@ func Provider() *schema.Provider { Description: descriptions["parallel_requests"], }, "app_auth": { - Type: schema.TypeList, - Optional: true, - MaxItems: 1, - Description: descriptions["app_auth"], - ExactlyOneOf: []string{"token"}, + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Description: descriptions["app_auth"], + ConflictsWith: []string{"token"}, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "id": { @@ -505,6 +505,7 @@ func tokenFromGHCLI(u *url.URL) string { out, err := exec.Command(ghCliPath, "auth", "token", "--hostname", host).Output() if err != nil { + log.Printf("[DEBUG] Error getting token from GitHub CLI: %s", err.Error()) // GH CLI is either not installed or there was no `gh auth login` command issued, // which is fine. don't return the error to keep the flow going return "" diff --git a/github/provider_test.go b/github/provider_test.go index 6d05f3fa15..037c91cbf4 100644 --- a/github/provider_test.go +++ b/github/provider_test.go @@ -54,12 +54,12 @@ func TestAccProviderConfigure(t *testing.T) { t.Run("can be configured to run anonymously", func(t *testing.T) { config := ` provider "github" { - token = "" } data "github_ip_ranges" "test" {} ` resource.Test(t, resource.TestCase{ + PreCheck: func() { t.Setenv("GITHUB_TOKEN", ""); t.Setenv("GH_PATH", "none-existent-path") }, ProviderFactories: providerFactories, Steps: []resource.TestStep{ { @@ -161,10 +161,15 @@ func TestAccProviderConfigure(t *testing.T) { provider "github" { token = "%s" base_url = "%s" - }`, testAccConf.token, testAccConf.owner) + }`, testAccConf.token, testAccConf.baseURL) resource.Test(t, resource.TestCase{ - PreCheck: func() { skipUnlessMode(t, individual) }, + PreCheck: func() { + skipUnlessMode(t, enterprise) + if testAccConf.baseURL.Host != "api.github.com" { + t.Skip("Skipping as test mode is not GHES") + } + }, ProviderFactories: providerFactories, Steps: []resource.TestStep{ { @@ -187,7 +192,6 @@ func TestAccProviderConfigure(t *testing.T) { `, testAccConf.owner, testMaxRetries) resource.Test(t, resource.TestCase{ - PreCheck: func() { skipUnauthenticated(t) }, ProviderFactories: providerFactories, Steps: []resource.TestStep{ { @@ -211,7 +215,6 @@ func TestAccProviderConfigure(t *testing.T) { `, testAccConf.owner, testMaxPerPage) resource.Test(t, resource.TestCase{ - PreCheck: func() { skipUnauthenticated(t) }, ProviderFactories: providerFactories, Steps: []resource.TestStep{ { @@ -243,12 +246,11 @@ func TestAccProviderConfigure(t *testing.T) { `, testAccConf.owner, testAccConf.token) resource.Test(t, resource.TestCase{ - PreCheck: func() { skipUnauthenticated(t) }, ProviderFactories: providerFactories, Steps: []resource.TestStep{ { Config: config, - ExpectError: regexp.MustCompile("only one of `app_auth,token` can be specified"), + ExpectError: regexp.MustCompile(`"app_auth": conflicts with token`), }, }, }) @@ -268,12 +270,12 @@ func TestAccProviderConfigure(t *testing.T) { `, testAccConf.owner) resource.Test(t, resource.TestCase{ - PreCheck: func() { skipUnauthenticated(t); t.Setenv("GITHUB_TOKEN", "1234567890") }, + PreCheck: func() { t.Setenv("GITHUB_TOKEN", "1234567890") }, ProviderFactories: providerFactories, Steps: []resource.TestStep{ { Config: config, - ExpectError: regexp.MustCompile("only one of `app_auth,token` can be specified"), + ExpectError: regexp.MustCompile(`"token": conflicts with app_auth`), }, }, })