Skip to content

Commit 472d4d6

Browse files
committed
Cleanup extra tflog.SetField calls
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
1 parent c7cb2c2 commit 472d4d6

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

github/resource_github_emu_group_mapping.go

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,19 @@ func resourceGithubEMUGroupMappingCreate(ctx context.Context, d *schema.Resource
7474
}
7575
client := meta.(*Owner).v3client
7676
orgName := meta.(*Owner).name
77-
ctx = tflog.SetField(ctx, "org_name", orgName)
7877

7978
teamSlug := d.Get("team_slug").(string)
80-
ctx = tflog.SetField(ctx, "team_slug", teamSlug)
8179

8280
groupID := toInt64(d.Get("group_id"))
83-
ctx = tflog.SetField(ctx, "group_id", groupID)
8481
eg := &github.ExternalGroup{
8582
GroupID: github.Ptr(groupID),
8683
}
8784

88-
tflog.Debug(ctx, "Connecting external group to team via GitHub API")
85+
tflog.Debug(ctx, "Connecting external group to team via GitHub API", map[string]any{
86+
"org_name": orgName,
87+
"team_slug": teamSlug,
88+
"group_id": groupID,
89+
})
8990

9091
group, resp, err := client.Teams.UpdateConnectedExternalGroup(ctx, orgName, teamSlug, eg)
9192
if err != nil {
@@ -104,15 +105,18 @@ func resourceGithubEMUGroupMappingCreate(ctx context.Context, d *schema.Resource
104105
return diag.FromErr(err)
105106
}
106107

107-
if err := d.Set("team_id", int(teamID)); err != nil {
108-
return diag.FromErr(err)
109-
}
110-
111108
tflog.Trace(ctx, "Setting resource ID", map[string]any{
112109
"resource_id": newResourceID,
113110
})
114111
d.SetId(newResourceID)
115112

113+
tflog.Trace(ctx, "Setting team_id", map[string]any{
114+
"team_id": teamID,
115+
})
116+
if err := d.Set("team_id", int(teamID)); err != nil {
117+
return diag.FromErr(err)
118+
}
119+
116120
etag := resp.Header.Get("ETag")
117121
tflog.Trace(ctx, "Setting state attribute: etag", map[string]any{
118122
"etag": etag,
@@ -121,6 +125,9 @@ func resourceGithubEMUGroupMappingCreate(ctx context.Context, d *schema.Resource
121125
return diag.FromErr(err)
122126
}
123127

128+
tflog.Trace(ctx, "Setting group_name", map[string]any{
129+
"group_name": group.GetGroupName(),
130+
})
124131
if err := d.Set("group_name", group.GetGroupName()); err != nil {
125132
return diag.FromErr(err)
126133
}
@@ -146,11 +153,10 @@ func resourceGithubEMUGroupMappingRead(ctx context.Context, d *schema.ResourceDa
146153
groupID := toInt64(d.Get("group_id"))
147154
teamSlug := d.Get("team_slug").(string)
148155

149-
ctx = tflog.SetField(ctx, "group_id", groupID)
150-
ctx = tflog.SetField(ctx, "team_slug", teamSlug)
151-
ctx = tflog.SetField(ctx, "org_name", orgName)
152-
153-
tflog.Debug(ctx, "Querying external groups linked to team from GitHub API")
156+
tflog.Debug(ctx, "Querying external groups linked to team from GitHub API", map[string]any{
157+
"org_name": orgName,
158+
"team_slug": teamSlug,
159+
})
154160

155161
groupsList, resp, err := client.Teams.ListExternalGroupsForTeamBySlug(ctx, orgName, teamSlug)
156162
if err != nil {
@@ -178,8 +184,9 @@ func resourceGithubEMUGroupMappingRead(ctx context.Context, d *schema.ResourceDa
178184
group := groupsList.Groups[0]
179185

180186
tflog.Debug(ctx, "Successfully retrieved external group from GitHub API", map[string]any{
181-
"group_id": group.GetGroupID(),
182-
"group_name": group.GetGroupName(),
187+
"configured_group_id": groupID,
188+
"upstream_group_id": group.GetGroupID(),
189+
"group_name": group.GetGroupName(),
183190
})
184191

185192
if group.GetGroupID() != groupID {
@@ -212,20 +219,21 @@ func resourceGithubEMUGroupMappingUpdate(ctx context.Context, d *schema.Resource
212219
}
213220
client := meta.(*Owner).v3client
214221
orgName := meta.(*Owner).name
215-
ctx = tflog.SetField(ctx, "org_name", orgName)
216222

217223
teamSlug := d.Get("team_slug").(string)
218-
ctx = tflog.SetField(ctx, "team_slug", teamSlug)
219224

220225
groupID := toInt64(d.Get("group_id"))
221-
ctx = tflog.SetField(ctx, "group_id", groupID)
222226
eg := &github.ExternalGroup{
223227
GroupID: github.Ptr(groupID),
224228
}
225229

226230
if d.HasChange("team_slug") {
227231

228-
tflog.Debug(ctx, "Updating connected external group via GitHub API")
232+
tflog.Debug(ctx, "Updating connected external group via GitHub API", map[string]any{
233+
"org_name": orgName,
234+
"team_slug": teamSlug,
235+
"group_id": groupID,
236+
})
229237

230238
group, resp, err := client.Teams.UpdateConnectedExternalGroup(ctx, orgName, teamSlug, eg)
231239
if err != nil {

0 commit comments

Comments
 (0)