From 56363f5e99aa12ec528c4e1b0d16415645ce93de Mon Sep 17 00:00:00 2001 From: Jeremy Udit Date: Tue, 14 Jul 2020 13:39:02 -0400 Subject: [PATCH] Deprecate `individual` flag for provider configuration (#512) * Deprecate `anonymous` flag for provider configuration * Add Configuration Tests * fixup! Fix Spelling * fixup! hard-code values for CI environment * Deprecate `individual` flag for provider configuration --- github/config_test.go | 21 +++++++++++++++++++++ github/provider.go | 15 ++++++++++----- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/github/config_test.go b/github/config_test.go index a321915760..6fb47ba6e5 100644 --- a/github/config_test.go +++ b/github/config_test.go @@ -58,4 +58,25 @@ func TestConfigClients(t *testing.T) { t.Fatalf("failed to return a v3 client") } }) + + t.Run("returns clients configured as individual", func(t *testing.T) { + config := Config{ + Organization: "", + Anonymous: true, + Individual: true, + } + + meta, err := config.Clients() + if err != nil { + t.Fatalf("failed to return clients without error: %s", err.Error()) + } + + if client := meta.(*Organization).v4client; client == nil { + t.Fatalf("failed to return a v4 client") + } + + if client := meta.(*Organization).v3client; client == nil { + t.Fatalf("failed to return a v3 client") + } + }) } diff --git a/github/provider.go b/github/provider.go index 547f2a569b..1a56092ab3 100644 --- a/github/provider.go +++ b/github/provider.go @@ -33,10 +33,10 @@ func Provider() terraform.ResourceProvider { Description: descriptions["insecure"], }, "individual": { - Type: schema.TypeBool, - Optional: true, - Default: false, - Description: descriptions["individual"], + Type: schema.TypeBool, + Optional: true, + Default: false, + Deprecated: "For versions later than 3.0.0, absence of an organization enables this mode", }, "anonymous": { Type: schema.TypeBool, @@ -124,12 +124,17 @@ func providerConfigure(p *schema.Provider) schema.ConfigureFunc { anonymous = false } + individual := true + if d.Get("organization").(string) != "" { + individual = false + } + config := Config{ Token: d.Get("token").(string), Organization: d.Get("organization").(string), BaseURL: d.Get("base_url").(string), Insecure: d.Get("insecure").(bool), - Individual: d.Get("individual").(bool), + Individual: individual, Anonymous: anonymous, }