From 2d62872336532f0f345e3b3f796774856a585736 Mon Sep 17 00:00:00 2001 From: Feyz Sari Date: Fri, 17 Apr 2026 17:47:07 +0100 Subject: [PATCH] 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 --- ...urce_github_actions_organization_registration_token.go | 6 ++++-- github/data_source_github_actions_registration_token.go | 7 +++++-- github/data_source_github_branch.go | 8 ++++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/github/data_source_github_actions_organization_registration_token.go b/github/data_source_github_actions_organization_registration_token.go index 44cb4ec4d3..4527c95c65 100644 --- a/github/data_source_github_actions_organization_registration_token.go +++ b/github/data_source_github_actions_organization_registration_token.go @@ -2,8 +2,8 @@ package github import ( "context" - "log" + "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -29,7 +29,9 @@ func dataSourceGithubActionsOrganizationRegistrationTokenRead(ctx context.Contex client := meta.(*Owner).v3client owner := meta.(*Owner).name - log.Printf("[DEBUG] Creating a GitHub Actions organization registration token for %s", owner) + tflog.Debug(ctx, "Creating a GitHub Actions organization registration token", map[string]any{ + "owner": owner, + }) token, _, err := client.Actions.CreateOrganizationRegistrationToken(ctx, owner) if err != nil { return diag.Errorf("error creating a GitHub Actions organization registration token for %s: %v", owner, err) diff --git a/github/data_source_github_actions_registration_token.go b/github/data_source_github_actions_registration_token.go index 070d112b4d..a961063286 100644 --- a/github/data_source_github_actions_registration_token.go +++ b/github/data_source_github_actions_registration_token.go @@ -3,8 +3,8 @@ package github import ( "context" "fmt" - "log" + "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -36,7 +36,10 @@ func dataSourceGithubActionsRegistrationTokenRead(ctx context.Context, d *schema owner := meta.(*Owner).name repoName := d.Get("repository").(string) - log.Printf("[DEBUG] Creating a GitHub Actions repository registration token for %s/%s", owner, repoName) + tflog.Debug(ctx, "Creating a GitHub Actions repository registration token", map[string]any{ + "owner": owner, + "repository": repoName, + }) token, _, err := client.Actions.CreateRegistrationToken(ctx, owner, repoName) if err != nil { return diag.Errorf("error creating a GitHub Actions repository registration token for %s/%s: %v", owner, repoName, err) diff --git a/github/data_source_github_branch.go b/github/data_source_github_branch.go index 5b32b1c3e5..f6d04342e3 100644 --- a/github/data_source_github_branch.go +++ b/github/data_source_github_branch.go @@ -3,10 +3,10 @@ package github import ( "context" "errors" - "log" "net/http" "github.com/google/go-github/v84/github" + "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -54,7 +54,11 @@ func dataSourceGithubBranchRead(ctx context.Context, d *schema.ResourceData, met var ghErr *github.ErrorResponse if errors.As(err, &ghErr) { if ghErr.Response.StatusCode == http.StatusNotFound { - log.Printf("[DEBUG] Missing GitHub branch %s/%s (%s)", orgName, repoName, branchRefName) + tflog.Debug(ctx, "Missing GitHub branch", map[string]any{ + "owner": orgName, + "repository": repoName, + "branch_ref": branchRefName, + }) d.SetId("") return nil }