Skip to content

Commit 2d62872

Browse files
committed
maint: migrate data sources to tflog structured logging
Replace standard log.Printf calls with tflog.Debug using structured fields in the following data sources: - data_source_github_actions_organization_registration_token - data_source_github_actions_registration_token - data_source_github_branch Part of #2629
1 parent e72c809 commit 2d62872

3 files changed

Lines changed: 15 additions & 6 deletions

github/data_source_github_actions_organization_registration_token.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package github
22

33
import (
44
"context"
5-
"log"
65

6+
"github.com/hashicorp/terraform-plugin-log/tflog"
77
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
88
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
99
)
@@ -29,7 +29,9 @@ func dataSourceGithubActionsOrganizationRegistrationTokenRead(ctx context.Contex
2929
client := meta.(*Owner).v3client
3030
owner := meta.(*Owner).name
3131

32-
log.Printf("[DEBUG] Creating a GitHub Actions organization registration token for %s", owner)
32+
tflog.Debug(ctx, "Creating a GitHub Actions organization registration token", map[string]any{
33+
"owner": owner,
34+
})
3335
token, _, err := client.Actions.CreateOrganizationRegistrationToken(ctx, owner)
3436
if err != nil {
3537
return diag.Errorf("error creating a GitHub Actions organization registration token for %s: %v", owner, err)

github/data_source_github_actions_registration_token.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package github
33
import (
44
"context"
55
"fmt"
6-
"log"
76

7+
"github.com/hashicorp/terraform-plugin-log/tflog"
88
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
99
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1010
)
@@ -36,7 +36,10 @@ func dataSourceGithubActionsRegistrationTokenRead(ctx context.Context, d *schema
3636
owner := meta.(*Owner).name
3737
repoName := d.Get("repository").(string)
3838

39-
log.Printf("[DEBUG] Creating a GitHub Actions repository registration token for %s/%s", owner, repoName)
39+
tflog.Debug(ctx, "Creating a GitHub Actions repository registration token", map[string]any{
40+
"owner": owner,
41+
"repository": repoName,
42+
})
4043
token, _, err := client.Actions.CreateRegistrationToken(ctx, owner, repoName)
4144
if err != nil {
4245
return diag.Errorf("error creating a GitHub Actions repository registration token for %s/%s: %v", owner, repoName, err)

github/data_source_github_branch.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package github
33
import (
44
"context"
55
"errors"
6-
"log"
76
"net/http"
87

98
"github.com/google/go-github/v84/github"
9+
"github.com/hashicorp/terraform-plugin-log/tflog"
1010
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1111
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1212
)
@@ -54,7 +54,11 @@ func dataSourceGithubBranchRead(ctx context.Context, d *schema.ResourceData, met
5454
var ghErr *github.ErrorResponse
5555
if errors.As(err, &ghErr) {
5656
if ghErr.Response.StatusCode == http.StatusNotFound {
57-
log.Printf("[DEBUG] Missing GitHub branch %s/%s (%s)", orgName, repoName, branchRefName)
57+
tflog.Debug(ctx, "Missing GitHub branch", map[string]any{
58+
"owner": orgName,
59+
"repository": repoName,
60+
"branch_ref": branchRefName,
61+
})
5862
d.SetId("")
5963
return nil
6064
}

0 commit comments

Comments
 (0)