From 2a17feb6f7e71925ff2b5f8eb13ee6f9680ee5bb Mon Sep 17 00:00:00 2001 From: Erik Elkins Date: Mon, 17 Jun 2024 18:45:47 -0500 Subject: [PATCH] Fixing enterprise id reference (#2274) Co-authored-by: Keegan Campbell --- ...e_github_enterprise_actions_permissions.go | 11 ++-- ...hub_enterprise_actions_permissions_test.go | 62 +++++++------------ ...b_enterprise_actions_runner_group_test.go} | 0 ...terprise_actions_permissions.html.markdown | 14 ++--- 4 files changed, 36 insertions(+), 51 deletions(-) rename github/{resource_github_enteprise_actions_runner_group_test.go => resource_github_enterprise_actions_runner_group_test.go} (100%) diff --git a/github/resource_github_enterprise_actions_permissions.go b/github/resource_github_enterprise_actions_permissions.go index 0b26926cf..5c7239c87 100644 --- a/github/resource_github_enterprise_actions_permissions.go +++ b/github/resource_github_enterprise_actions_permissions.go @@ -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, @@ -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) @@ -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 } @@ -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"), diff --git a/github/resource_github_enterprise_actions_permissions_test.go b/github/resource_github_enterprise_actions_permissions_test.go index bdb41c536..d04773fa3 100644 --- a/github/resource_github_enterprise_actions_permissions_test.go +++ b/github/resource_github_enterprise_actions_permissions_test.go @@ -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" } @@ -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 { @@ -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( @@ -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 { @@ -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( diff --git a/github/resource_github_enteprise_actions_runner_group_test.go b/github/resource_github_enterprise_actions_runner_group_test.go similarity index 100% rename from github/resource_github_enteprise_actions_runner_group_test.go rename to github/resource_github_enterprise_actions_runner_group_test.go diff --git a/website/docs/r/enterprise_actions_permissions.html.markdown b/website/docs/r/enterprise_actions_permissions.html.markdown index 80d0a06d4..eb299a56b 100644 --- a/website/docs/r/enterprise_actions_permissions.html.markdown +++ b/website/docs/r/enterprise_actions_permissions.html.markdown @@ -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 { @@ -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