Skip to content

Commit

Permalink
feat: add github_enterprise_actions_runner_group
Browse files Browse the repository at this point in the history
  • Loading branch information
bradam12 committed Feb 18, 2024
1 parent 16872b7 commit 5a67e73
Show file tree
Hide file tree
Showing 9 changed files with 685 additions and 1 deletion.
9 changes: 9 additions & 0 deletions github/data_source_github_enterprise.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ func dataSourceGithubEnterprise() *schema.Resource {
return &schema.Resource{
Read: dataSourceGithubEnterpriseRead,
Schema: map[string]*schema.Schema{
"database_id": {
Type: schema.TypeInt,
Computed: true,
},
"slug": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -40,6 +44,7 @@ func dataSourceGithubEnterpriseRead(data *schema.ResourceData, meta interface{})
var query struct {
Enterprise struct {
ID githubv4.String
DatabaseId githubv4.Int
Name githubv4.String
Description githubv4.String
CreatedAt githubv4.String
Expand Down Expand Up @@ -76,6 +81,10 @@ func dataSourceGithubEnterpriseRead(data *schema.ResourceData, meta interface{})
if err != nil {
return err
}
err = data.Set("database_id", query.Enterprise.DatabaseId)
if err != nil {
return err
}

return nil
}
1 change: 1 addition & 0 deletions github/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ func Provider() *schema.Provider {
"github_user_invitation_accepter": resourceGithubUserInvitationAccepter(),
"github_user_ssh_key": resourceGithubUserSshKey(),
"github_enterprise_organization": resourceGithubEnterpriseOrganization(),
"github_enterprise_actions_runner_group": resourceGithubActionsEnterpriseRunnerGroup(),
},

DataSourcesMap: map[string]*schema.Resource{
Expand Down
228 changes: 228 additions & 0 deletions github/resource_github_enteprise_actions_runner_group_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
package github

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccGithubActionsEnterpriseRunnerGroup(t *testing.T) {
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)

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")
}

t.Run("creates enterprise runner groups without error", func(t *testing.T) {
config := fmt.Sprintf(`
data "github_enterprise" "enterprise" {
slug = "%s"
}
resource "github_enterprise_actions_runner_group" "test" {
enterprise_slug = data.github_enterprise.enterprise.slug
name = "tf-acc-test-%s"
visibility = "all"
allows_public_repositories = true
}
`, testEnterprise, randomID)

check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(
"github_enterprise_actions_runner_group.test", "name",
),
resource.TestCheckResourceAttr(
"github_enterprise_actions_runner_group.test", "name",
fmt.Sprintf(`tf-acc-test-%s`, randomID),
),
resource.TestCheckResourceAttr(
"github_enterprise_actions_runner_group.test", "visibility",
"all",
),
resource.TestCheckResourceAttr(
"github_enterprise_actions_runner_group.test", "allows_public_repositories",
"true",
),
)

testCase := func(t *testing.T, mode string) {
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessMode(t, mode) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
Check: check,
},
},
})
}

t.Run("with an enterprise account", func(t *testing.T) {
testCase(t, enterprise)
})
})

t.Run("manages runner group visibility to selected orgs", func(t *testing.T) {

config := fmt.Sprintf(`
data "github_enterprise" "enterprise" {
slug = "%s"
}
data "github_organization" "org" {
name = "%s"
}
resource "github_enterprise_actions_runner_group" "test" {
enterprise_slug = data.github_enterprise.enterprise.slug
name = "tf-acc-test-%s"
visibility = "selected"
selected_organization_ids = [data.github_organization.org.id]
}
`, testEnterprise, testOrganization, randomID)

check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(
"github_enterprise_actions_runner_group.test", "name",
),
resource.TestCheckResourceAttr(
"github_enterprise_actions_runner_group.test", "name",
fmt.Sprintf(`tf-acc-test-%s`, randomID),
),
resource.TestCheckResourceAttr(
"github_enterprise_actions_runner_group.test", "visibility",
"selected",
),
resource.TestCheckResourceAttr(
"github_enterprise_actions_runner_group.test", "selected_organization_ids.#",
"1",
),
resource.TestCheckResourceAttrSet(
"github_enterprise_actions_runner_group.test", "selected_organizations_url",
),
)

testCase := func(t *testing.T, mode string) {
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessMode(t, mode) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
Check: check,
},
},
})
}

t.Run("with an enterprise account", func(t *testing.T) {
testCase(t, enterprise)
})
})

t.Run("imports an all runner group without error", func(t *testing.T) {
config := fmt.Sprintf(`
data "github_enterprise" "enterprise" {
slug = "%s"
}
resource "github_enterprise_actions_runner_group" "test" {
enterprise_slug = data.github_enterprise.enterprise.slug
name = "tf-acc-test-%s"
visibility = "all"
}
`, testEnterprise, randomID)

check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("github_enterprise_actions_runner_group.test", "name"),
resource.TestCheckResourceAttrSet("github_enterprise_actions_runner_group.test", "visibility"),
resource.TestCheckResourceAttr("github_enterprise_actions_runner_group.test", "visibility", "all"),
resource.TestCheckResourceAttr("github_enterprise_actions_runner_group.test", "name", fmt.Sprintf(`tf-acc-test-%s`, randomID)),
)

testCase := func(t *testing.T, mode string) {
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessMode(t, mode) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
Check: check,
},
{
ResourceName: "github_enterprise_actions_runner_group.test",
ImportState: true,
ImportStateVerify: true,
ImportStateIdPrefix: fmt.Sprintf(`%s/`, testEnterprise),
},
},
})
}

t.Run("with an enterprise account", func(t *testing.T) {
testCase(t, enterprise)
})
})

t.Run("imports a runner group with selected orgs without error", func(t *testing.T) {

config := fmt.Sprintf(`
data "github_enterprise" "enterprise" {
slug = "%s"
}
data "github_organization" "org" {
name = "%s"
}
resource "github_enterprise_actions_runner_group" "test" {
enterprise_slug = data.github_enterprise.enterprise.slug
name = "tf-acc-test-%s"
visibility = "selected"
selected_organization_ids = [data.github_organization.org.id]
}
`, testEnterprise, testOrganization, randomID)

check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("github_enterprise_actions_runner_group.test", "name"),
resource.TestCheckResourceAttr("github_enterprise_actions_runner_group.test", "name", fmt.Sprintf(`tf-acc-test-%s`, randomID)),
resource.TestCheckResourceAttrSet("github_enterprise_actions_runner_group.test", "visibility"),
resource.TestCheckResourceAttr("github_enterprise_actions_runner_group.test", "visibility", "selected"),
resource.TestCheckResourceAttr(
"github_enterprise_actions_runner_group.test", "selected_organization_ids.#",
"1",
),
)

testCase := func(t *testing.T, mode string) {
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessMode(t, mode) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
Check: check,
},
{
ResourceName: "github_enterprise_actions_runner_group.test",
ImportState: true,
ImportStateVerify: true,
ImportStateIdPrefix: fmt.Sprintf(`%s/`, testEnterprise),
},
},
})
}

t.Run("with an enterprise account", func(t *testing.T) {
testCase(t, enterprise)
})
})
}
Loading

0 comments on commit 5a67e73

Please sign in to comment.