@@ -190,6 +190,12 @@ func resourceGithubActionsRunnerGroupCreate(ctx context.Context, d *schema.Resou
190190 }
191191 }
192192
193+ var networkConfigurationIDPtr * string
194+ if networkConfigurationID , ok := d .GetOk ("network_configuration_id" ); ok {
195+ value := networkConfigurationID .(string )
196+ networkConfigurationIDPtr = & value
197+ }
198+
193199 runnerGroup , resp , err := client .Actions .CreateOrganizationRunnerGroup (ctx ,
194200 orgName ,
195201 github.CreateRunnerGroupRequest {
@@ -199,6 +205,7 @@ func resourceGithubActionsRunnerGroupCreate(ctx context.Context, d *schema.Resou
199205 SelectedRepositoryIDs : selectedRepositoryIDs ,
200206 SelectedWorkflows : selectedWorkflows ,
201207 AllowsPublicRepositories : & allowsPublicRepositories ,
208+ NetworkConfigurationID : networkConfigurationIDPtr ,
202209 },
203210 )
204211 if err != nil {
@@ -208,23 +215,7 @@ func resourceGithubActionsRunnerGroupCreate(ctx context.Context, d *schema.Resou
208215 if err = setGithubActionsRunnerGroupState (d , runnerGroup , normalizeEtag (resp .Header .Get ("ETag" )), selectedRepositoryIDs ); err != nil {
209216 return diag .FromErr (err )
210217 }
211-
212- if networkConfigurationID , ok := d .GetOk ("network_configuration_id" ); ok {
213- networkConfigurationIDValue := networkConfigurationID .(string )
214- // The create endpoint does not accept network_configuration_id, so private networking
215- // must be attached with a follow-up PATCH after the runner group has been created.
216- if _ , err = updateRunnerGroupNetworking (client , ctx , fmt .Sprintf ("orgs/%s/actions/runner-groups/%d" , orgName , runnerGroup .GetID ()), & networkConfigurationIDValue ); err != nil {
217- return diag .FromErr (err )
218- }
219-
220- if err = setRunnerGroupNetworkingState (d , & runnerGroupNetworking {NetworkConfigurationID : & networkConfigurationIDValue }); err != nil {
221- return diag .FromErr (err )
222- }
223-
224- return nil
225- }
226-
227- if err = setRunnerGroupNetworkingState (d , nil ); err != nil {
218+ if err = d .Set ("network_configuration_id" , runnerGroup .NetworkConfigurationID ); err != nil {
228219 return diag .FromErr (err )
229220 }
230221
@@ -262,10 +253,8 @@ func resourceGithubActionsRunnerGroupRead(ctx context.Context, d *schema.Resourc
262253 return diag .FromErr (err )
263254 }
264255
265- runnerGroupEtag := normalizeEtag (resp .Header .Get ("ETag" ))
266- runnerGroupNetworking , _ , err := getRunnerGroupNetworking (client , ctx , fmt .Sprintf ("orgs/%s/actions/runner-groups/%d" , orgName , runnerGroupID ))
267- if err != nil {
268- return diag .FromErr (err )
256+ if runnerGroup == nil {
257+ return nil
269258 }
270259
271260 selectedRepositoryIDs := []int64 {}
@@ -290,22 +279,12 @@ func resourceGithubActionsRunnerGroupRead(ctx context.Context, d *schema.Resourc
290279 options .Page = resp .NextPage
291280 }
292281
293- if runnerGroup != nil {
294- if err = setGithubActionsRunnerGroupState (d , runnerGroup , runnerGroupEtag , selectedRepositoryIDs ); err != nil {
295- return diag .FromErr (err )
296- }
297- } else {
298- if err := d .Set ("selected_repository_ids" , selectedRepositoryIDs ); err != nil {
299- return diag .FromErr (err )
300- }
301- if err := d .Set ("etag" , runnerGroupEtag ); err != nil {
302- return diag .FromErr (err )
303- }
282+ runnerGroupEtag := normalizeEtag (resp .Header .Get ("ETag" ))
283+ if err = setGithubActionsRunnerGroupState (d , runnerGroup , runnerGroupEtag , selectedRepositoryIDs ); err != nil {
284+ return diag .FromErr (err )
304285 }
305- if runnerGroupNetworking != nil {
306- if err = setRunnerGroupNetworkingState (d , runnerGroupNetworking ); err != nil {
307- return diag .FromErr (err )
308- }
286+ if err = d .Set ("network_configuration_id" , runnerGroup .NetworkConfigurationID ); err != nil {
287+ return diag .FromErr (err )
309288 }
310289
311290 return nil
@@ -330,12 +309,24 @@ func resourceGithubActionsRunnerGroupUpdate(ctx context.Context, d *schema.Resou
330309 }
331310 }
332311
312+ var networkConfigurationIDPtr * string
313+ if networkConfigurationID , ok := d .GetOk ("network_configuration_id" ); ok {
314+ value := networkConfigurationID .(string )
315+ networkConfigurationIDPtr = & value
316+ } else if d .HasChange ("network_configuration_id" ) {
317+ // Field was removed — send empty string to clear it.
318+ // go-github's omitempty omits nil pointers, so empty string is used as a workaround.
319+ empty := ""
320+ networkConfigurationIDPtr = & empty
321+ }
322+
333323 options := github.UpdateRunnerGroupRequest {
334324 Name : & name ,
335325 Visibility : & visibility ,
336326 RestrictedToWorkflows : & restrictedToWorkflows ,
337327 SelectedWorkflows : selectedWorkflows ,
338328 AllowsPublicRepositories : & allowsPublicRepositories ,
329+ NetworkConfigurationID : networkConfigurationIDPtr ,
339330 }
340331
341332 runnerGroupID , err := strconv .ParseInt (d .Id (), 10 , 64 )
@@ -349,23 +340,6 @@ func resourceGithubActionsRunnerGroupUpdate(ctx context.Context, d *schema.Resou
349340 return diag .FromErr (err )
350341 }
351342
352- var networkConfigurationIDValue * string
353- if networkConfigurationID , ok := d .GetOk ("network_configuration_id" ); ok {
354- value := networkConfigurationID .(string )
355- networkConfigurationIDValue = & value
356- }
357-
358- if d .HasChange ("network_configuration_id" ) {
359- if _ , err := updateRunnerGroupNetworking (client , ctx , fmt .Sprintf ("orgs/%s/actions/runner-groups/%d" , orgName , runnerGroupID ), networkConfigurationIDValue ); err != nil {
360- return diag .FromErr (err )
361- }
362- }
363-
364- var networkingState * runnerGroupNetworking
365- if networkConfigurationIDValue != nil {
366- networkingState = & runnerGroupNetworking {NetworkConfigurationID : networkConfigurationIDValue }
367- }
368-
369343 selectedRepositories , hasSelectedRepositories := d .GetOk ("selected_repository_ids" )
370344 selectedRepositoryIDs := []int64 {}
371345
@@ -388,7 +362,7 @@ func resourceGithubActionsRunnerGroupUpdate(ctx context.Context, d *schema.Resou
388362 if err := setGithubActionsRunnerGroupState (d , runnerGroup , runnerGroupEtag , selectedRepositoryIDs ); err != nil {
389363 return diag .FromErr (err )
390364 }
391- if err := setRunnerGroupNetworkingState ( d , networkingState ); err != nil {
365+ if err := d . Set ( "network_configuration_id" , runnerGroup . NetworkConfigurationID ); err != nil {
392366 return diag .FromErr (err )
393367 }
394368
0 commit comments