Skip to content

Commit 291829c

Browse files
committed
fix
1 parent cc263bd commit 291829c

9 files changed

Lines changed: 290 additions & 178 deletions

github/data_source_github_enterprise_actions_hosted_runner.go

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
func dataSourceGithubEnterpriseActionsHostedRunner() *schema.Resource {
1313
return &schema.Resource{
14+
Description: "Use this data source to retrieve information about a specific GitHub Enterprise Actions hosted runner.",
1415
ReadContext: dataSourceGithubEnterpriseActionsHostedRunnerRead,
1516

1617
Schema: map[string]*schema.Schema{
@@ -169,24 +170,35 @@ func dataSourceGithubEnterpriseActionsHostedRunnerRead(ctx context.Context, d *s
169170
}
170171
d.SetId(id)
171172

172-
runnerData := map[string]any{
173-
"name": runner.GetName(),
174-
"runner_group_id": int(runner.GetRunnerGroupID()),
175-
"platform": runner.GetPlatform(),
176-
"status": runner.GetStatus(),
177-
"maximum_runners": int(runner.GetMaximumRunners()),
178-
"public_ip_enabled": runner.GetPublicIPEnabled(),
179-
"image_details": flattenHostedRunnerImage(runner.ImageDetails),
180-
"machine_size_details": flattenHostedRunnerMachineSpec(runner.MachineSizeDetails),
181-
"public_ips": flattenHostedRunnerPublicIPs(runner.PublicIPs),
173+
if err := d.Set("name", runner.GetName()); err != nil {
174+
return diag.FromErr(err)
182175
}
183-
184-
if runner.LastActiveOn != nil {
185-
runnerData["last_active_on"] = runner.LastActiveOn.Format(time.RFC3339)
176+
if err := d.Set("runner_group_id", int(runner.GetRunnerGroupID())); err != nil {
177+
return diag.FromErr(err)
186178
}
187-
188-
for k, v := range runnerData {
189-
if err := d.Set(k, v); err != nil {
179+
if err := d.Set("platform", runner.GetPlatform()); err != nil {
180+
return diag.FromErr(err)
181+
}
182+
if err := d.Set("status", runner.GetStatus()); err != nil {
183+
return diag.FromErr(err)
184+
}
185+
if err := d.Set("maximum_runners", int(runner.GetMaximumRunners())); err != nil {
186+
return diag.FromErr(err)
187+
}
188+
if err := d.Set("public_ip_enabled", runner.GetPublicIPEnabled()); err != nil {
189+
return diag.FromErr(err)
190+
}
191+
if err := d.Set("image_details", flattenHostedRunnerImage(runner.ImageDetails)); err != nil {
192+
return diag.FromErr(err)
193+
}
194+
if err := d.Set("machine_size_details", flattenHostedRunnerMachineSpec(runner.MachineSizeDetails)); err != nil {
195+
return diag.FromErr(err)
196+
}
197+
if err := d.Set("public_ips", flattenHostedRunnerPublicIPs(runner.PublicIPs)); err != nil {
198+
return diag.FromErr(err)
199+
}
200+
if runner.LastActiveOn != nil {
201+
if err := d.Set("last_active_on", runner.LastActiveOn.Format(time.RFC3339)); err != nil {
190202
return diag.FromErr(err)
191203
}
192204
}

github/data_source_github_enterprise_actions_hosted_runner_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestAccGithubEnterpriseActionsHostedRunnerDataSource(t *testing.T) {
4747
`, testAccConf.enterpriseSlug, testResourcePrefix, randomID, testResourcePrefix, randomID)
4848

4949
resource.Test(t, resource.TestCase{
50-
PreCheck: func() { skipUnlessMode(t, enterprise) },
50+
PreCheck: func() { skipUnlessEnterprise(t) },
5151
ProviderFactories: providerFactories,
5252
Steps: []resource.TestStep{
5353
{

github/data_source_github_enterprise_actions_hosted_runners.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import (
44
"context"
55
"time"
66

7-
"github.com/google/go-github/v84/github"
7+
"github.com/google/go-github/v85/github"
88
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
99
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1010
)
1111

1212
func dataSourceGithubEnterpriseActionsHostedRunners() *schema.Resource {
1313
return &schema.Resource{
14+
Description: "Use this data source to retrieve the list of GitHub Enterprise Actions hosted runners.",
1415
ReadContext: dataSourceGithubEnterpriseActionsHostedRunnersRead,
1516

1617
Schema: map[string]*schema.Schema{

github/data_source_github_enterprise_actions_hosted_runners_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func TestAccGithubEnterpriseActionsHostedRunnersDataSource(t *testing.T) {
1919
`, testAccConf.enterpriseSlug)
2020

2121
resource.Test(t, resource.TestCase{
22-
PreCheck: func() { skipUnlessMode(t, enterprise) },
22+
PreCheck: func() { skipUnlessEnterprise(t) },
2323
ProviderFactories: providerFactories,
2424
Steps: []resource.TestStep{
2525
{

github/resource_github_enterprise_actions_hosted_runner.go

Lines changed: 18 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"strconv"
88
"time"
99

10-
"github.com/google/go-github/v84/github"
10+
"github.com/google/go-github/v85/github"
1111
"github.com/hashicorp/terraform-plugin-log/tflog"
1212
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1313
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
@@ -17,6 +17,7 @@ import (
1717

1818
func resourceGithubEnterpriseActionsHostedRunner() *schema.Resource {
1919
return &schema.Resource{
20+
Description: "Manages a GitHub Enterprise Actions hosted runner.",
2021
CreateContext: resourceGithubEnterpriseActionsHostedRunnerCreate,
2122
ReadContext: resourceGithubEnterpriseActionsHostedRunnerRead,
2223
UpdateContext: resourceGithubEnterpriseActionsHostedRunnerUpdate,
@@ -39,13 +40,13 @@ func resourceGithubEnterpriseActionsHostedRunner() *schema.Resource {
3940
"name": {
4041
Type: schema.TypeString,
4142
Required: true,
42-
ValidateFunc: validation.All(
43+
ValidateDiagFunc: validation.ToDiagFunc(validation.All(
4344
validation.StringLenBetween(1, 64),
4445
validation.StringMatch(
4546
regexp.MustCompile(`^[a-zA-Z0-9._-]+$`),
4647
"name may only contain alphanumeric characters, '.', '-', and '_'",
4748
),
48-
),
49+
)),
4950
Description: "Name of the hosted runner. Must be between 1 and 64 characters and may only contain upper and lowercase letters a-z, numbers 0-9, '.', '-', and '_'.",
5051
},
5152
"image": {
@@ -90,10 +91,10 @@ func resourceGithubEnterpriseActionsHostedRunner() *schema.Resource {
9091
"size": {
9192
Type: schema.TypeString,
9293
Required: true,
93-
ValidateFunc: validation.StringMatch(
94+
ValidateDiagFunc: validation.ToDiagFunc(validation.StringMatch(
9495
regexp.MustCompile(`^\d+-core$`),
9596
"size must be in the format '<number>-core' (e.g., '4-core', '8-core')",
96-
),
97+
)),
9798
Description: "Machine size for the hosted runner (e.g., '4-core', '8-core'). This determines the CPU, memory, and storage resources allocated to the runner. Can be updated to scale the runner. To list available sizes, use the GitHub API: GET /enterprises/{enterprise}/actions/hosted-runners/machine-sizes.",
9899
},
99100
"runner_group_id": {
@@ -105,7 +106,7 @@ func resourceGithubEnterpriseActionsHostedRunner() *schema.Resource {
105106
Type: schema.TypeInt,
106107
Optional: true,
107108
Computed: true,
108-
ValidateFunc: validation.IntAtLeast(1),
109+
ValidateDiagFunc: validation.ToDiagFunc(validation.IntAtLeast(1)),
109110
Description: "Maximum number of runners to scale up to. Runners will not auto-scale above this number. Use this setting to limit costs. If not specified, GitHub will use a default limit.",
110111
},
111112
"public_ip_enabled": {
@@ -207,7 +208,6 @@ func resourceGithubEnterpriseActionsHostedRunnerCreate(ctx context.Context, d *s
207208
client := meta.(*Owner).v3client
208209
enterpriseSlug := d.Get("enterprise_slug").(string)
209210

210-
// Build request using SDK struct
211211
request := github.CreateHostedRunnerRequest{
212212
Name: d.Get("name").(string),
213213
Size: d.Get("size").(string),
@@ -220,7 +220,7 @@ func resourceGithubEnterpriseActionsHostedRunnerCreate(ctx context.Context, d *s
220220

221221
if v, ok := d.GetOk("maximum_runners"); ok {
222222
maxRunners := int64(v.(int))
223-
request.MaximumRunners = new(maxRunners)
223+
request.MaximumRunners = &maxRunners
224224
}
225225

226226
if v, ok := d.GetOk("public_ip_enabled"); ok {
@@ -233,23 +233,16 @@ func resourceGithubEnterpriseActionsHostedRunnerCreate(ctx context.Context, d *s
233233
return diag.Errorf("error creating enterprise hosted runner: %s", err.Error())
234234
}
235235

236-
if runner == nil || runner.ID == nil {
237-
return diag.Errorf("no runner data returned from API")
238-
}
239-
240-
// Set the ID in the format enterprise_slug/runner_id
241236
id, err := buildID(enterpriseSlug, strconv.FormatInt(runner.GetID(), 10))
242237
if err != nil {
243238
return diag.FromErr(err)
244239
}
245240
d.SetId(id)
246241

247-
// Populate computed fields directly from API response
248242
if err := d.Set("enterprise_slug", enterpriseSlug); err != nil {
249243
return diag.FromErr(err)
250244
}
251245

252-
// runner.ID is guaranteed non-nil due to check above
253246
if err := d.Set("runner_id", int(runner.GetID())); err != nil {
254247
return diag.FromErr(err)
255248
}
@@ -297,10 +290,8 @@ func resourceGithubEnterpriseActionsHostedRunnerCreate(ctx context.Context, d *s
297290
return diag.FromErr(err)
298291
}
299292

300-
if runner.PublicIPs != nil {
301-
if err := d.Set("public_ips", flattenHostedRunnerPublicIPs(runner.PublicIPs)); err != nil {
302-
return diag.FromErr(err)
303-
}
293+
if err := d.Set("public_ips", flattenHostedRunnerPublicIPs(runner.PublicIPs)); err != nil {
294+
return diag.FromErr(err)
304295
}
305296

306297
return nil
@@ -384,10 +375,8 @@ func resourceGithubEnterpriseActionsHostedRunnerRead(ctx context.Context, d *sch
384375
return diag.FromErr(err)
385376
}
386377

387-
if runner.PublicIPs != nil {
388-
if err := d.Set("public_ips", flattenHostedRunnerPublicIPs(runner.PublicIPs)); err != nil {
389-
return diag.FromErr(err)
390-
}
378+
if err := d.Set("public_ips", flattenHostedRunnerPublicIPs(runner.PublicIPs)); err != nil {
379+
return diag.FromErr(err)
391380
}
392381

393382
return nil
@@ -396,15 +385,8 @@ func resourceGithubEnterpriseActionsHostedRunnerRead(ctx context.Context, d *sch
396385
func resourceGithubEnterpriseActionsHostedRunnerUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
397386
client := meta.(*Owner).v3client
398387

399-
enterpriseSlug, runnerIDStr, err := parseID2(d.Id())
400-
if err != nil {
401-
return diag.FromErr(err)
402-
}
403-
404-
runnerID, err := strconv.ParseInt(runnerIDStr, 10, 64)
405-
if err != nil {
406-
return diag.Errorf("invalid runner ID %q: %s", runnerIDStr, err.Error())
407-
}
388+
enterpriseSlug := d.Get("enterprise_slug").(string)
389+
runnerID := int64(d.Get("runner_id").(int))
408390

409391
name := d.Get("name").(string)
410392
size := d.Get("size").(string)
@@ -419,26 +401,19 @@ func resourceGithubEnterpriseActionsHostedRunnerUpdate(ctx context.Context, d *s
419401
EnableStaticIP: &enableStaticIP,
420402
}
421403

422-
_, _, err = client.Enterprise.UpdateHostedRunner(ctx, enterpriseSlug, runnerID, request)
404+
_, _, err := client.Enterprise.UpdateHostedRunner(ctx, enterpriseSlug, runnerID, request)
423405
if err != nil {
424406
return diag.Errorf("error updating enterprise hosted runner: %s", err.Error())
425407
}
426408

427-
return resourceGithubEnterpriseActionsHostedRunnerRead(ctx, d, meta)
409+
return nil
428410
}
429411

430412
func resourceGithubEnterpriseActionsHostedRunnerDelete(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
431413
client := meta.(*Owner).v3client
432414

433-
enterpriseSlug, runnerIDStr, err := parseID2(d.Id())
434-
if err != nil {
435-
return diag.FromErr(err)
436-
}
437-
438-
runnerID, err := strconv.ParseInt(runnerIDStr, 10, 64)
439-
if err != nil {
440-
return diag.Errorf("invalid runner ID %q: %s", runnerIDStr, err.Error())
441-
}
415+
enterpriseSlug := d.Get("enterprise_slug").(string)
416+
runnerID := int64(d.Get("runner_id").(int))
442417

443418
_, resp, err := client.Enterprise.DeleteHostedRunner(ctx, enterpriseSlug, runnerID)
444419

0 commit comments

Comments
 (0)