Skip to content

Commit b62d82b

Browse files
committed
maint: migrate various data sources to tflog structured logging
1 parent e72c809 commit b62d82b

3 files changed

Lines changed: 35 additions & 10 deletions

File tree

github/data_source_github_ref.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
)
@@ -56,7 +56,11 @@ func dataSourceGithubRefRead(ctx context.Context, d *schema.ResourceData, meta a
5656
var ghErr *github.ErrorResponse
5757
if errors.As(err, &ghErr) {
5858
if ghErr.Response.StatusCode == http.StatusNotFound {
59-
log.Printf("[DEBUG] Missing GitHub ref %s/%s (%s)", owner, repoName, ref)
59+
tflog.Debug(ctx, "Missing GitHub ref", map[string]any{
60+
"owner": owner,
61+
"repoName": repoName,
62+
"ref": ref,
63+
})
6064
d.SetId("")
6165
return nil
6266
}

github/data_source_github_repository.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import (
44
"context"
55
"errors"
66
"fmt"
7-
"log"
87
"net/http"
98
"strings"
109

1110
"github.com/google/go-github/v84/github"
11+
"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/schema"
1414
)
@@ -370,7 +370,10 @@ func dataSourceGithubRepositoryRead(ctx context.Context, d *schema.ResourceData,
370370
var ghErr *github.ErrorResponse
371371
if errors.As(err, &ghErr) {
372372
if ghErr.Response.StatusCode == http.StatusNotFound {
373-
log.Printf("[DEBUG] Missing GitHub repository %s/%s", owner, repoName)
373+
tflog.Debug(ctx, "Missing GitHub repository", map[string]any{
374+
"owner": owner,
375+
"repo": repoName,
376+
})
374377
d.SetId("")
375378
return nil
376379
}

github/data_source_github_repository_file.go

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import (
44
"context"
55
"errors"
66
"fmt"
7-
"log"
87
"net/http"
98
"net/url"
109
"strings"
1110

1211
"github.com/google/go-github/v84/github"
12+
"github.com/hashicorp/terraform-plugin-log/tflog"
1313
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1414
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1515
)
@@ -83,11 +83,16 @@ func dataSourceGithubRepositoryFileRead(ctx context.Context, d *schema.ResourceD
8383
// split and replace owner and repo
8484
parts := strings.Split(repo, "/")
8585
if len(parts) == 2 {
86-
log.Printf("[DEBUG] repo has a slash, extracting owner from: %s", repo)
86+
tflog.Debug(ctx, "repo has a slash, extracting owner from", map[string]any{
87+
"repo": repo,
88+
})
8789
owner = parts[0]
8890
repo = parts[1]
8991

90-
log.Printf("[DEBUG] owner: %s repo:%s", owner, repo)
92+
tflog.Debug(ctx, "owner and repo", map[string]any{
93+
"owner": owner,
94+
"repo": repo,
95+
})
9196
}
9297

9398
file := d.Get("file").(string)
@@ -102,7 +107,11 @@ func dataSourceGithubRepositoryFileRead(ctx context.Context, d *schema.ResourceD
102107
var ghErr *github.ErrorResponse
103108
if errors.As(err, &ghErr) {
104109
if ghErr.Response.StatusCode == http.StatusNotFound {
105-
log.Printf("[DEBUG] Missing GitHub repository file %s/%s/%s", owner, repo, file)
110+
tflog.Debug(ctx, "Missing GitHub repository file", map[string]any{
111+
"owner": owner,
112+
"repo": repo,
113+
"file": file,
114+
})
106115
d.SetId("")
107116
return nil
108117
}
@@ -145,12 +154,21 @@ func dataSourceGithubRepositoryFileRead(ctx context.Context, d *schema.ResourceD
145154
})
146155
}
147156

148-
log.Printf("[DEBUG] Data Source fetching commit info for repository file: %s/%s/%s", owner, repo, file)
157+
tflog.Debug(ctx, "Data Source fetching commit info for repository file", map[string]any{
158+
"owner": owner,
159+
"repo": repo,
160+
"file": file,
161+
})
149162
commit, err := getFileCommit(ctx, client, owner, repo, file, ref)
150163
if err != nil {
151164
return diag.FromErr(err)
152165
}
153-
log.Printf("[DEBUG] Found file: %s/%s/%s, in commit SHA: %s ", owner, repo, file, commit.GetSHA())
166+
tflog.Debug(ctx, "Found file, in commit SHA", map[string]any{
167+
"owner": owner,
168+
"repo": repo,
169+
"file": file,
170+
"sha": commit.GetSHA(),
171+
})
154172

155173
if err = d.Set("commit_sha", commit.GetSHA()); err != nil {
156174
return diag.FromErr(err)

0 commit comments

Comments
 (0)