Skip to content

Commit 73fd9d7

Browse files
committed
Ensure that token is never configured together with app_auth
Signed-off-by: Timo Sand <[email protected]>
1 parent 450176c commit 73fd9d7

2 files changed

Lines changed: 37 additions & 8 deletions

File tree

github/provider.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ func Provider() *schema.Provider {
1818
p := &schema.Provider{
1919
Schema: map[string]*schema.Schema{
2020
"token": {
21-
Type: schema.TypeString,
22-
Optional: true,
23-
DefaultFunc: schema.EnvDefaultFunc("GITHUB_TOKEN", nil),
24-
Description: descriptions["token"],
21+
Type: schema.TypeString,
22+
Optional: true,
23+
DefaultFunc: schema.EnvDefaultFunc("GITHUB_TOKEN", nil),
24+
Description: descriptions["token"],
25+
ConflictsWith: []string{"app_auth"},
2526
},
2627
"owner": {
2728
Type: schema.TypeString,
@@ -93,10 +94,11 @@ func Provider() *schema.Provider {
9394
Description: descriptions["parallel_requests"],
9495
},
9596
"app_auth": {
96-
Type: schema.TypeList,
97-
Optional: true,
98-
MaxItems: 1,
99-
Description: descriptions["app_auth"],
97+
Type: schema.TypeList,
98+
Optional: true,
99+
MaxItems: 1,
100+
Description: descriptions["app_auth"],
101+
ConflictsWith: []string{"token"},
100102
Elem: &schema.Resource{
101103
Schema: map[string]*schema.Schema{
102104
"id": {

github/provider_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package github
22

33
import (
44
"fmt"
5+
"regexp"
56
"testing"
67

78
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
@@ -214,4 +215,30 @@ func TestAccProviderConfigure(t *testing.T) {
214215
},
215216
})
216217
})
218+
t.Run("should not allow both token and app_auth to be configured", func(t *testing.T) {
219+
config := fmt.Sprintf(`
220+
provider "github" {
221+
owner = "%s"
222+
token = "%s"
223+
app_auth {
224+
id = "1234567890"
225+
installation_id = "1234567890"
226+
pem_file = "1234567890"
227+
}
228+
}
229+
230+
data "github_ip_ranges" "test" {}
231+
`, testAccConf.owner, testAccConf.token)
232+
233+
resource.Test(t, resource.TestCase{
234+
PreCheck: func() { skipUnauthenticated(t) },
235+
ProviderFactories: providerFactories,
236+
Steps: []resource.TestStep{
237+
{
238+
Config: config,
239+
ExpectError: regexp.MustCompile("\"app_auth\": conflicts with token"),
240+
},
241+
},
242+
})
243+
})
217244
}

0 commit comments

Comments
 (0)