Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate individual flag for provider configuration #512

Merged
merged 6 commits into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions github/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
})
}
15 changes: 10 additions & 5 deletions github/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}

Expand Down