Skip to content

Commit

Permalink
Remove ConflictsWith
Browse files Browse the repository at this point in the history
Experimentation with `ConflictsWith` for this use case added too much 
friction. This diff opts to use a custom `OwnerOrOrgEnvDefaultFunc` 
function instead to ensure owner and organization flags are used 
correctly in CI.
  • Loading branch information
Jeremy Udit committed Sep 4, 2020
1 parent 4ea6801 commit 213e7ef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
18 changes: 8 additions & 10 deletions github/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,16 @@ func Provider() terraform.ResourceProvider {
Description: descriptions["token"],
},
"owner": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("GITHUB_OWNER", nil),
Description: descriptions["owner"],
ConflictsWith: []string{"organization"},
Type: schema.TypeString,
Optional: true,
DefaultFunc: OwnerOrOrgEnvDefaultFunc,
Description: descriptions["owner"],
},
"organization": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("GITHUB_ORGANIZATION", nil),
Description: descriptions["organization"],
ConflictsWith: []string{"owner"},
Type: schema.TypeString,
Optional: true,
DefaultFunc: OwnerOrOrgEnvDefaultFunc,
Description: descriptions["organization"],
},
"base_url": {
Type: schema.TypeString,
Expand Down
7 changes: 7 additions & 0 deletions github/provider_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,10 @@ func orgResponseBody(port string) string {
}
`, testOwner, url, url)
}

func OwnerOrOrgEnvDefaultFunc() (interface{}, error) {
if organization := os.Getenv("GITHUB_ORGANIZATION"); organization != "" {
return os.Getenv("GITHUB_ORGANIZATION"), nil
}
return os.Getenv("GITHUB_OWNER"), nil
}

0 comments on commit 213e7ef

Please sign in to comment.