Skip to content

Commit 72a4c1a

Browse files
committed
feat: Validated unit tests and manual tests for OIDC custom property integration
1 parent 2f0f407 commit 72a4c1a

2 files changed

Lines changed: 53 additions & 10 deletions

github/resource_github_actions_organization_oidc_custom_property_inclusion.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ package github
33
import (
44
"context"
55
"fmt"
6+
"log"
67

78
"github.com/google/go-github/v84/github"
89
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
910
)
1011

12+
const oidcCustomPropertyAPIVersion = "2026-03-10"
13+
1114
func resourceGithubActionsOrganizationOIDCCustomPropertyInclusion() *schema.Resource {
1215
return &schema.Resource{
1316
Create: resourceGithubActionsOrganizationOIDCCustomPropertyInclusionCreate,
@@ -47,12 +50,15 @@ func resourceGithubActionsOrganizationOIDCCustomPropertyInclusionCreate(d *schem
4750
if err != nil {
4851
return fmt.Errorf("error creating request to add OIDC custom property inclusion: %w", err)
4952
}
53+
req.Header.Set("X-GitHub-Api-Version", oidcCustomPropertyAPIVersion)
5054

5155
_, err = client.Do(ctx, req, nil)
5256
if err != nil {
5357
return fmt.Errorf("error adding OIDC custom property inclusion %q for organization %q: %w", customPropertyName, orgName, err)
5458
}
5559

60+
log.Printf("[DEBUG] Successfully added OIDC custom property inclusion %q for organization %q", customPropertyName, orgName)
61+
5662
d.SetId(buildTwoPartID(orgName, customPropertyName))
5763

5864
return resourceGithubActionsOrganizationOIDCCustomPropertyInclusionRead(d, meta)
@@ -115,6 +121,7 @@ func resourceGithubActionsOrganizationOIDCCustomPropertyInclusionDelete(d *schem
115121
if err != nil {
116122
return fmt.Errorf("error creating request to delete OIDC custom property inclusion: %w", err)
117123
}
124+
req.Header.Set("X-GitHub-Api-Version", oidcCustomPropertyAPIVersion)
118125

119126
_, err = client.Do(ctx, req, nil)
120127
if err != nil {
@@ -126,7 +133,8 @@ func resourceGithubActionsOrganizationOIDCCustomPropertyInclusionDelete(d *schem
126133

127134
// OIDCCustomPropertyInclusion represents a custom property included in OIDC tokens.
128135
type OIDCCustomPropertyInclusion struct {
129-
PropertyName string `json:"property_name"`
136+
PropertyName string `json:"custom_property_name"`
137+
InclusionSource string `json:"inclusion_source,omitempty"`
130138
}
131139

132140
// listOrgOIDCCustomPropertyInclusions lists all custom properties included in OIDC tokens for an organization.
@@ -135,6 +143,7 @@ func listOrgOIDCCustomPropertyInclusions(ctx context.Context, client *github.Cli
135143
if err != nil {
136144
return nil, err
137145
}
146+
req.Header.Set("X-GitHub-Api-Version", oidcCustomPropertyAPIVersion)
138147

139148
var inclusions []*OIDCCustomPropertyInclusion
140149
_, err = client.Do(ctx, req, &inclusions)

github/resource_github_actions_organization_oidc_custom_property_inclusion_test.go

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,21 @@ import (
99
func TestAccGithubActionsOrganizationOIDCCustomPropertyInclusion(t *testing.T) {
1010
t.Run("creates and deletes an OIDC custom property inclusion without error", func(t *testing.T) {
1111
config := `
12+
resource "github_organization_custom_properties" "test" {
13+
property_name = "tf-acc-test-oidc-env"
14+
value_type = "single_select"
15+
required = false
16+
allowed_values = ["production", "staging"]
17+
}
18+
1219
resource "github_actions_organization_oidc_custom_property_inclusion" "test" {
13-
custom_property_name = "environment"
20+
custom_property_name = github_organization_custom_properties.test.property_name
1421
}`
1522

1623
check := resource.ComposeTestCheckFunc(
1724
resource.TestCheckResourceAttr(
1825
"github_actions_organization_oidc_custom_property_inclusion.test",
19-
"custom_property_name", "environment",
26+
"custom_property_name", "tf-acc-test-oidc-env",
2027
),
2128
)
2229
resource.Test(t, resource.TestCase{
@@ -33,14 +40,21 @@ func TestAccGithubActionsOrganizationOIDCCustomPropertyInclusion(t *testing.T) {
3340

3441
t.Run("imports an OIDC custom property inclusion without error", func(t *testing.T) {
3542
config := `
43+
resource "github_organization_custom_properties" "test" {
44+
property_name = "tf-acc-test-oidc-import"
45+
value_type = "single_select"
46+
required = false
47+
allowed_values = ["production", "staging"]
48+
}
49+
3650
resource "github_actions_organization_oidc_custom_property_inclusion" "test" {
37-
custom_property_name = "environment"
51+
custom_property_name = github_organization_custom_properties.test.property_name
3852
}`
3953

4054
check := resource.ComposeTestCheckFunc(
4155
resource.TestCheckResourceAttr(
4256
"github_actions_organization_oidc_custom_property_inclusion.test",
43-
"custom_property_name", "environment",
57+
"custom_property_name", "tf-acc-test-oidc-import",
4458
),
4559
)
4660

@@ -63,22 +77,35 @@ func TestAccGithubActionsOrganizationOIDCCustomPropertyInclusion(t *testing.T) {
6377

6478
t.Run("manages multiple OIDC custom property inclusions", func(t *testing.T) {
6579
config := `
80+
resource "github_organization_custom_properties" "env" {
81+
property_name = "tf-acc-test-oidc-env2"
82+
value_type = "single_select"
83+
required = false
84+
allowed_values = ["production", "staging"]
85+
}
86+
87+
resource "github_organization_custom_properties" "team" {
88+
property_name = "tf-acc-test-oidc-team"
89+
value_type = "string"
90+
required = false
91+
}
92+
6693
resource "github_actions_organization_oidc_custom_property_inclusion" "env" {
67-
custom_property_name = "environment"
94+
custom_property_name = github_organization_custom_properties.env.property_name
6895
}
6996
7097
resource "github_actions_organization_oidc_custom_property_inclusion" "team" {
71-
custom_property_name = "team"
98+
custom_property_name = github_organization_custom_properties.team.property_name
7299
}`
73100

74101
check := resource.ComposeTestCheckFunc(
75102
resource.TestCheckResourceAttr(
76103
"github_actions_organization_oidc_custom_property_inclusion.env",
77-
"custom_property_name", "environment",
104+
"custom_property_name", "tf-acc-test-oidc-env2",
78105
),
79106
resource.TestCheckResourceAttr(
80107
"github_actions_organization_oidc_custom_property_inclusion.team",
81-
"custom_property_name", "team",
108+
"custom_property_name", "tf-acc-test-oidc-team",
82109
),
83110
)
84111

@@ -98,8 +125,15 @@ func TestAccGithubActionsOrganizationOIDCCustomPropertyInclusion(t *testing.T) {
98125
func TestAccGithubActionsOrganizationOIDCCustomPropertyInclusionsDataSource(t *testing.T) {
99126
t.Run("reads OIDC custom property inclusions without error", func(t *testing.T) {
100127
config := `
128+
resource "github_organization_custom_properties" "test" {
129+
property_name = "tf-acc-test-oidc-ds"
130+
value_type = "single_select"
131+
required = false
132+
allowed_values = ["production", "staging"]
133+
}
134+
101135
resource "github_actions_organization_oidc_custom_property_inclusion" "test" {
102-
custom_property_name = "environment"
136+
custom_property_name = github_organization_custom_properties.test.property_name
103137
}
104138
105139
data "github_actions_organization_oidc_custom_property_inclusions" "test" {

0 commit comments

Comments
 (0)