Skip to content

Commit a69fc2f

Browse files
committed
refactor: use native go-github functions for enterprise runner group networking
go-github v88 carries NetworkConfigurationID on EnterpriseRunnerGroup, CreateEnterpriseRunnerGroupRequest, and UpdateEnterpriseRunnerGroupRequest (added in google/go-github#4099). Replace the raw NewRequest/Do GET and PATCH shims with the native Create/Update/Get functions, mirroring the org runner group implementation. The enterprise create endpoint accepts network_configuration_id directly, so the follow-up PATCH is no longer needed. Removes resource_github_actions_runner_group_helpers.go and its test now that no callers remain.
1 parent d32fb1b commit a69fc2f

3 files changed

Lines changed: 23 additions & 279 deletions

github/resource_github_actions_runner_group_helpers.go

Lines changed: 0 additions & 61 deletions
This file was deleted.

github/resource_github_actions_runner_group_helpers_test.go

Lines changed: 0 additions & 173 deletions
This file was deleted.

github/resource_github_enterprise_actions_runner_group.go

Lines changed: 23 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ func resourceGithubActionsEnterpriseRunnerGroupCreate(ctx context.Context, d *sc
170170

171171
ctx = context.WithValue(ctx, ctxId, d.Id())
172172

173+
var networkConfigurationIDPtr *string
174+
if networkConfigurationID, ok := d.GetOk("network_configuration_id"); ok {
175+
value := networkConfigurationID.(string)
176+
networkConfigurationIDPtr = &value
177+
}
178+
173179
enterpriseRunnerGroup, resp, err := client.Enterprise.CreateEnterpriseRunnerGroup(ctx,
174180
enterpriseSlug,
175181
github.CreateEnterpriseRunnerGroupRequest{
@@ -179,33 +185,17 @@ func resourceGithubActionsEnterpriseRunnerGroupCreate(ctx context.Context, d *sc
179185
AllowsPublicRepositories: &allowsPublicRepositories,
180186
RestrictedToWorkflows: &restrictedToWorkflows,
181187
SelectedWorkflows: selectedWorkflows,
188+
NetworkConfigurationID: networkConfigurationIDPtr,
182189
},
183190
)
184191
if err != nil {
185192
return diag.FromErr(err)
186193
}
187194
d.SetId(strconv.FormatInt(enterpriseRunnerGroup.GetID(), 10))
188-
ctx = context.WithValue(ctx, ctxId, d.Id())
189195
if err = setGithubActionsEnterpriseRunnerGroupState(d, enterpriseRunnerGroup, normalizeEtag(resp.Header.Get("ETag")), enterpriseSlug, selectedOrganizationIDs); err != nil {
190196
return diag.FromErr(err)
191197
}
192-
193-
if networkConfigurationID, ok := d.GetOk("network_configuration_id"); ok {
194-
networkConfigurationIDValue := networkConfigurationID.(string)
195-
// The create endpoint does not accept network_configuration_id, so private networking
196-
// must be attached with a follow-up PATCH after the runner group has been created.
197-
if _, err = updateRunnerGroupNetworking(client, ctx, fmt.Sprintf("enterprises/%s/actions/runner-groups/%d", enterpriseSlug, enterpriseRunnerGroup.GetID()), &networkConfigurationIDValue); err != nil {
198-
return diag.FromErr(err)
199-
}
200-
201-
if err = setRunnerGroupNetworkingState(d, &runnerGroupNetworking{NetworkConfigurationID: &networkConfigurationIDValue}); err != nil {
202-
return diag.FromErr(err)
203-
}
204-
205-
return nil
206-
}
207-
208-
if err = setRunnerGroupNetworkingState(d, nil); err != nil {
198+
if err = d.Set("network_configuration_id", enterpriseRunnerGroup.NetworkConfigurationID); err != nil {
209199
return diag.FromErr(err)
210200
}
211201

@@ -257,11 +247,6 @@ func resourceGithubActionsEnterpriseRunnerGroupRead(ctx context.Context, d *sche
257247

258248
runnerGroupEtag := normalizeEtag(resp.Header.Get("ETag"))
259249

260-
runnerGroupNetworking, _, err := getRunnerGroupNetworking(client, ctx, fmt.Sprintf("enterprises/%s/actions/runner-groups/%d", enterpriseSlug, runnerGroupID))
261-
if err != nil {
262-
return diag.FromErr(err)
263-
}
264-
265250
selectedOrganizationIDs := []int64{}
266251
optionsOrgs := github.ListOptions{
267252
PerPage: maxPerPage,
@@ -287,10 +272,8 @@ func resourceGithubActionsEnterpriseRunnerGroupRead(ctx context.Context, d *sche
287272
if err = setGithubActionsEnterpriseRunnerGroupState(d, enterpriseRunnerGroup, runnerGroupEtag, enterpriseSlug, selectedOrganizationIDs); err != nil {
288273
return diag.FromErr(err)
289274
}
290-
if runnerGroupNetworking != nil {
291-
if err = setRunnerGroupNetworkingState(d, runnerGroupNetworking); err != nil {
292-
return diag.FromErr(err)
293-
}
275+
if err = d.Set("network_configuration_id", enterpriseRunnerGroup.NetworkConfigurationID); err != nil {
276+
return diag.FromErr(err)
294277
}
295278

296279
return nil
@@ -311,12 +294,24 @@ func resourceGithubActionsEnterpriseRunnerGroupUpdate(ctx context.Context, d *sc
311294
}
312295
}
313296

297+
var networkConfigurationIDPtr *string
298+
if networkConfigurationID, ok := d.GetOk("network_configuration_id"); ok {
299+
value := networkConfigurationID.(string)
300+
networkConfigurationIDPtr = &value
301+
} else if d.HasChange("network_configuration_id") {
302+
// Field was removed — send empty string to clear it.
303+
// go-github's omitempty omits nil pointers, so empty string is used as a workaround.
304+
empty := ""
305+
networkConfigurationIDPtr = &empty
306+
}
307+
314308
options := github.UpdateEnterpriseRunnerGroupRequest{
315309
Name: &name,
316310
Visibility: &visibility,
317311
RestrictedToWorkflows: &restrictedToWorkflows,
318312
SelectedWorkflows: selectedWorkflows,
319313
AllowsPublicRepositories: &allowsPublicRepositories,
314+
NetworkConfigurationID: networkConfigurationIDPtr,
320315
}
321316

322317
runnerGroupID, err := strconv.ParseInt(d.Id(), 10, 64)
@@ -331,23 +326,6 @@ func resourceGithubActionsEnterpriseRunnerGroupUpdate(ctx context.Context, d *sc
331326
return diag.FromErr(err)
332327
}
333328

334-
var networkConfigurationIDValue *string
335-
if networkConfigurationID, ok := d.GetOk("network_configuration_id"); ok {
336-
value := networkConfigurationID.(string)
337-
networkConfigurationIDValue = &value
338-
}
339-
340-
if d.HasChange("network_configuration_id") {
341-
if _, err := updateRunnerGroupNetworking(client, ctx, fmt.Sprintf("enterprises/%s/actions/runner-groups/%d", enterpriseSlug, runnerGroupID), networkConfigurationIDValue); err != nil {
342-
return diag.FromErr(err)
343-
}
344-
}
345-
346-
var networkingState *runnerGroupNetworking
347-
if networkConfigurationIDValue != nil {
348-
networkingState = &runnerGroupNetworking{NetworkConfigurationID: networkConfigurationIDValue}
349-
}
350-
351329
selectedOrganizations, hasSelectedOrganizations := d.GetOk("selected_organization_ids")
352330
selectedOrganizationIDs := []int64{}
353331

@@ -370,7 +348,7 @@ func resourceGithubActionsEnterpriseRunnerGroupUpdate(ctx context.Context, d *sc
370348
if err := setGithubActionsEnterpriseRunnerGroupState(d, runnerGroup, runnerGroupEtag, enterpriseSlug, selectedOrganizationIDs); err != nil {
371349
return diag.FromErr(err)
372350
}
373-
if err := setRunnerGroupNetworkingState(d, networkingState); err != nil {
351+
if err := d.Set("network_configuration_id", runnerGroup.NetworkConfigurationID); err != nil {
374352
return diag.FromErr(err)
375353
}
376354

0 commit comments

Comments
 (0)