From 213e7ef6326ac20d62a27beaedd4d0b3621bb647 Mon Sep 17 00:00:00 2001 From: Jeremy Udit Date: Fri, 31 Jul 2020 16:46:06 -0400 Subject: [PATCH] Remove `ConflictsWith` 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. --- github/provider.go | 18 ++++++++---------- github/provider_utils.go | 7 +++++++ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/github/provider.go b/github/provider.go index 193d520521..f5d98f7f6b 100644 --- a/github/provider.go +++ b/github/provider.go @@ -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, diff --git a/github/provider_utils.go b/github/provider_utils.go index 68634492f5..cba71a096f 100644 --- a/github/provider_utils.go +++ b/github/provider_utils.go @@ -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 +}