Skip to content

Commit

Permalink
Fixing enterprise id reference (#2274)
Browse files Browse the repository at this point in the history
Co-authored-by: Keegan Campbell <me@kfcampbell.com>
  • Loading branch information
ErikElkins and kfcampbell committed Jun 17, 2024
1 parent 5ce4588 commit 2a17feb
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 51 deletions.
11 changes: 7 additions & 4 deletions github/resource_github_enterprise_actions_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ func resourceGithubActionsEnterprisePermissions() *schema.Resource {
},

Schema: map[string]*schema.Schema{
"enterprise_id": {
"enterprise_slug": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The ID of the enterprise.",
Description: "The slug of the enterprise.",
},
"allowed_actions": {
Type: schema.TypeString,
Expand Down Expand Up @@ -145,7 +145,7 @@ func resourceGithubActionsEnterprisePermissionsCreateOrUpdate(d *schema.Resource
ctx = context.WithValue(ctx, ctxId, d.Id())
}

enterpriseId := d.Get("enterprise_id").(string)
enterpriseId := d.Get("enterprise_slug").(string)
allowedActions := d.Get("allowed_actions").(string)
enabledOrganizations := d.Get("enabled_organizations").(string)

Expand Down Expand Up @@ -264,6 +264,9 @@ func resourceGithubActionsEnterprisePermissionsRead(d *schema.ResourceData, meta
if err = d.Set("enabled_organizations", actionsPermissions.GetEnabledOrganizations()); err != nil {
return err
}
if err = d.Set("enterprise_slug", d.Id()); err != nil {
return err
}

return nil
}
Expand All @@ -275,7 +278,7 @@ func resourceGithubActionsEnterprisePermissionsDelete(d *schema.ResourceData, me

// This will nullify any allowedActions elements
_, _, err := client.Actions.EditActionsPermissionsInEnterprise(ctx,
d.Get("enterprise_id").(string),
d.Get("enterprise_slug").(string),
github.ActionsPermissionsEnterprise{
AllowedActions: github.String("all"),
EnabledOrganizations: github.String("all"),
Expand Down
62 changes: 24 additions & 38 deletions github/resource_github_enterprise_actions_permissions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,8 @@ func TestAccGithubActionsEnterprisePermissions(t *testing.T) {
enabledOrganizations := "all"

config := fmt.Sprintf(`
data "github_enterprise" "enterprise" {
slug = "%s"
}
resource "github_enterprise_actions_permissions" "test" {
enterprise_id = data.github_enterprise.enterprise.id
enterprise_slug = "%s"
allowed_actions = "%s"
enabled_organizations = "%s"
}
Expand Down Expand Up @@ -74,27 +70,23 @@ func TestAccGithubActionsEnterprisePermissions(t *testing.T) {
desc := "Initial org description"

config := fmt.Sprintf(`
data "github_enterprise" "enterprise" {
slug = "%s"
}
data "github_user" "current" {
username = ""
}
resource "github_enterprise_organization" "org" {
enterprise_id = data.github_enterprise.enterprise.id
name = "%s"
display_name = "%s"
description = "%s"
billing_email = data.github_user.current.email
admin_logins = [
enterprise_slug = "%s"
name = "%s"
display_name = "%s"
description = "%s"
billing_email = data.github_user.current.email
admin_logins = [
data.github_user.current.login
]
}
resource "github_enterprise_actions_permissions" "test" {
enterprise_id = data.github_enterprise.enterprise.id
enterprise_slug = "%s"
allowed_actions = "%s"
enabled_organizations = "%s"
allowed_actions_config {
Expand All @@ -106,7 +98,7 @@ func TestAccGithubActionsEnterprisePermissions(t *testing.T) {
organization_ids = [github_enterprise_organization.org.id]
}
}
`, testEnterprise, orgName, displayName, desc, allowedActions, enabledOrganizations, githubOwnedAllowed, verifiedAllowed)
`, testEnterprise, orgName, displayName, desc, testEnterprise, allowedActions, enabledOrganizations, githubOwnedAllowed, verifiedAllowed)

check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -160,11 +152,8 @@ func TestAccGithubActionsEnterprisePermissions(t *testing.T) {
verifiedAllowed := true

config := fmt.Sprintf(`
data "github_enterprise" "enterprise" {
slug = "%s"
}
resource "github_enterprise_actions_permissions" "test" {
enterprise_id = data.github_enterprise.enterprise.id
enterprise_slug = "%s"
allowed_actions = "%s"
enabled_organizations = "%s"
allowed_actions_config {
Expand Down Expand Up @@ -227,41 +216,38 @@ func TestAccGithubActionsEnterprisePermissions(t *testing.T) {
desc2 := fmt.Sprintf("Initial org description %s", randomID2)

config := fmt.Sprintf(`
data "github_enterprise" "enterprise" {
slug = "%s"
}
data "github_user" "current" {
username = ""
}
resource "github_enterprise_organization" "org" {
enterprise_id = data.github_enterprise.enterprise.id
name = "%s"
display_name = "%s"
description = "%s"
billing_email = data.github_user.current.email
admin_logins = [
enterprise_slug = "%s"
name = "%s"
display_name = "%s"
description = "%s"
billing_email = data.github_user.current.email
admin_logins = [
data.github_user.current.login
]
}
resource "github_enterprise_organization" "org2" {
enterprise_id = data.github_enterprise.enterprise.id
name = "%s"
display_name = "%s"
description = "%s"
billing_email = data.github_user.current.email
admin_logins = [
enterprise_slug = "%s"
name = "%s"
display_name = "%s"
description = "%s"
billing_email = data.github_user.current.email
admin_logins = [
data.github_user.current.login
]
}
resource "github_enterprise_actions_permissions" "test" {
enterprise_id = data.github_enterprise.enterprise.id
enterprise_slug = "%s"
allowed_actions = "%s"
enabled_organizations = "%s"
enabled_organizations_config {
organization_ids = [github_enterprise_organization.org.id, github_enterprise_organization.org2.id]
}
}
`, testEnterprise, orgName, displayName, desc, orgName2, displayName2, desc2, allowedActions, enabledOrganizations)
`, testEnterprise, orgName, displayName, desc, testEnterprise, orgName2, displayName2, desc2, testEnterprise, allowedActions, enabledOrganizations)

check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
Expand Down
14 changes: 5 additions & 9 deletions website/docs/r/enterprise_actions_permissions.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@ You must have admin access to an enterprise to use this resource.
## Example Usage

```hcl
data "github_enterprise" "example-enterprise" {
slug = "my-enterprise"
}
data "github_organization" "example-org" {
name = "my-org"
}
resource "github_enterprise_actions_permissions" "test" {
enterprise_id = data.github_enterprise.example-enterprise.slug
enterprise_slug = "my-enterprise"
allowed_actions = "selected"
enabled_organizations = "selected"
allowed_actions_config {
Expand All @@ -39,10 +35,10 @@ resource "github_enterprise_actions_permissions" "test" {
## Argument Reference

The following arguments are supported:
* `enterprise_id` - (Required) The ID of the enterprise.
* `allowed_actions` - (Optional) The permissions policy that controls the actions that are allowed to run. Can be one of: `all`, `local_only`, or `selected`.
* `enabled_organizations` - (Required) The policy that controls the organizations in the enterprise that are allowed to run GitHub Actions. Can be one of: `all`, `none`, or `selected`.
* `allowed_actions_config` - (Optional) Sets the actions that are allowed in an enterprise. Only available when `allowed_actions` = `selected`. See [Allowed Actions Config](#allowed-actions-config) below for details.
* `"my-enterprise"` - (Required) The slug of the enterprise.
* `allowed_actions` - (Optional) The permissions policy that controls the actions that are allowed to run. Can be one of: `all`, `local_only`, or `selected`.
* `enabled_organizations` - (Required) The policy that controls the organizations in the enterprise that are allowed to run GitHub Actions. Can be one of: `all`, `none`, or `selected`.
* `allowed_actions_config` - (Optional) Sets the actions that are allowed in an enterprise. Only available when `allowed_actions` = `selected`. See [Allowed Actions Config](#allowed-actions-config) below for details.
* `enabled_organizations_config` - (Optional) Sets the list of selected organizations that are enabled for GitHub Actions in an enterprise. Only available when `enabled_organizations` = `selected`. See [Enabled Organizations Config](#enabled-organizations-config) below for details.

### Allowed Actions Config
Expand Down

0 comments on commit 2a17feb

Please sign in to comment.