forked from integrations/terraform-provider-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] Add support for provisioning github orgs to enterprises.
- Loading branch information
Showing
7 changed files
with
536 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package github | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/shurcooL/githubv4" | ||
) | ||
|
||
func dataSourceGithubEnterprise() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceGithubEnterpriseRead, | ||
Schema: map[string]*schema.Schema{ | ||
"slug": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"created_at": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"url": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceGithubEnterpriseRead(data *schema.ResourceData, meta interface{}) error { | ||
var query struct { | ||
Enterprise struct { | ||
ID githubv4.String | ||
Name githubv4.String | ||
Description githubv4.String | ||
CreatedAt githubv4.String | ||
Url githubv4.String | ||
} `graphql:"enterprise(slug: $slug)"` | ||
} | ||
|
||
slug := data.Get("slug").(string) | ||
client := meta.(*Owner).v4client | ||
variables := map[string]interface{}{ | ||
"slug": githubv4.String(slug), | ||
} | ||
err := client.Query(context.Background(), &query, variables) | ||
if err != nil { | ||
return err | ||
} | ||
if query.Enterprise.ID == "" { | ||
return fmt.Errorf("could not find enterprise %v", slug) | ||
} | ||
data.SetId(string(query.Enterprise.ID)) | ||
data.Set("name", query.Enterprise.Name) | ||
data.Set("description", query.Enterprise.Description) | ||
data.Set("created_at", query.Enterprise.CreatedAt) | ||
data.Set("url", query.Enterprise.Url) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package github | ||
|
||
import ( | ||
"fmt" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
"testing" | ||
) | ||
|
||
func TestAccGithubEnterpriseDataSource(t *testing.T) { | ||
if isEnterprise != "true" { | ||
t.Skip("Skipping because `ENTERPRISE_ACCOUNT` is not set or set to false") | ||
} | ||
|
||
if testEnterprise == "" { | ||
t.Skip("Skipping because `ENTERPRISE_SLUG` is not set") | ||
} | ||
|
||
config := fmt.Sprintf(` | ||
data "github_enterprise" "test" { | ||
slug = "%s" | ||
} | ||
`, | ||
testEnterprise, | ||
) | ||
|
||
check := resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.github_enterprise.test", "slug", testEnterprise), | ||
resource.TestCheckResourceAttrSet("data.github_enterprise.test", "name"), | ||
resource.TestCheckResourceAttrSet("data.github_enterprise.test", "created_at"), | ||
resource.TestCheckResourceAttrSet("data.github_enterprise.test", "url"), | ||
) | ||
|
||
resource.Test( | ||
t, | ||
resource.TestCase{ | ||
PreCheck: func() { skipUnlessMode(t, enterprise) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
Check: check, | ||
}, | ||
}, | ||
}, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.