Skip to content

Commit bc460d1

Browse files
committed
Fix tflog.SetField usage
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
1 parent 0bfdaee commit bc460d1

1 file changed

Lines changed: 17 additions & 27 deletions

File tree

github/resource_github_emu_group_mapping.go

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

7979
teamSlug := d.Get("team_slug").(string)
80-
tflog.SetField(ctx, "team_slug", teamSlug)
80+
ctx = tflog.SetField(ctx, "team_slug", teamSlug)
8181

8282
groupID := toInt64(d.Get("group_id"))
83-
tflog.SetField(ctx, "group_id", groupID)
83+
ctx = tflog.SetField(ctx, "group_id", groupID)
8484
eg := &github.ExternalGroup{
8585
GroupID: new(groupID),
8686
}
@@ -133,9 +133,8 @@ func resourceGithubEMUGroupMappingCreate(ctx context.Context, d *schema.Resource
133133
}
134134

135135
func resourceGithubEMUGroupMappingRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
136-
tflog.Trace(ctx, "Reading EMU group mapping", map[string]any{
137-
"resource_id": d.Id(),
138-
})
136+
ctx = tflog.SetField(ctx, "resource_id", d.Id())
137+
tflog.Trace(ctx, "Reading EMU group mapping")
139138

140139
err := checkOrganization(meta)
141140
if err != nil {
@@ -147,36 +146,30 @@ func resourceGithubEMUGroupMappingRead(ctx context.Context, d *schema.ResourceDa
147146
groupID := toInt64(d.Get("group_id"))
148147
teamSlug := d.Get("team_slug").(string)
149148

150-
tflog.SetField(ctx, "group_id", groupID)
151-
tflog.SetField(ctx, "team_slug", teamSlug)
152-
tflog.SetField(ctx, "org_name", orgName)
149+
ctx = tflog.SetField(ctx, "group_id", groupID)
150+
ctx = tflog.SetField(ctx, "team_slug", teamSlug)
151+
ctx = tflog.SetField(ctx, "org_name", orgName)
153152

154153
tflog.Debug(ctx, "Querying external groups linked to team from GitHub API")
155154

156155
groupsList, resp, err := client.Teams.ListExternalGroupsForTeamBySlug(ctx, orgName, teamSlug)
157156
if err != nil {
158157
if resp != nil && resp.StatusCode == http.StatusBadRequest {
159-
tflog.Info(ctx, "Removing EMU group mapping from state because the team has explicit members in GitHub", map[string]any{
160-
"resource_id": d.Id(),
161-
})
158+
tflog.Info(ctx, "Removing EMU group mapping from state because the team has explicit members in GitHub")
162159
d.SetId("")
163160
return nil
164161
}
165162
if resp != nil && (resp.StatusCode == http.StatusNotFound) {
166163
// If the Group is not found, remove it from state
167-
tflog.Info(ctx, "Removing EMU group mapping from state because team no longer exists in GitHub", map[string]any{
168-
"resource_id": d.Id(),
169-
})
164+
tflog.Info(ctx, "Removing EMU group mapping from state because team no longer exists in GitHub")
170165
d.SetId("")
171166
return nil
172167
}
173168
return diag.FromErr(err)
174169
}
175170

176171
if len(groupsList.Groups) < 1 {
177-
tflog.Info(ctx, "Removing EMU group mapping from state because no external groups are linked to the team", map[string]any{
178-
"resource_id": d.Id(),
179-
})
172+
tflog.Info(ctx, "Removing EMU group mapping from state because no external groups are linked to the team")
180173
d.SetId("")
181174
return nil
182175
}
@@ -210,23 +203,22 @@ func resourceGithubEMUGroupMappingRead(ctx context.Context, d *schema.ResourceDa
210203
}
211204

212205
func resourceGithubEMUGroupMappingUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
213-
tflog.Trace(ctx, "Updating EMU group mapping", map[string]any{
214-
"resource_id": d.Id(),
215-
})
206+
ctx = tflog.SetField(ctx, "resource_id", d.Id())
207+
tflog.Trace(ctx, "Updating EMU group mapping")
216208

217209
err := checkOrganization(meta)
218210
if err != nil {
219211
return diag.FromErr(err)
220212
}
221213
client := meta.(*Owner).v3client
222214
orgName := meta.(*Owner).name
223-
tflog.SetField(ctx, "org_name", orgName)
215+
ctx = tflog.SetField(ctx, "org_name", orgName)
224216

225217
teamSlug := d.Get("team_slug").(string)
226-
tflog.SetField(ctx, "team_slug", teamSlug)
218+
ctx = tflog.SetField(ctx, "team_slug", teamSlug)
227219

228220
groupID := toInt64(d.Get("group_id"))
229-
tflog.SetField(ctx, "group_id", groupID)
221+
ctx = tflog.SetField(ctx, "group_id", groupID)
230222
eg := &github.ExternalGroup{
231223
GroupID: new(groupID),
232224
}
@@ -255,9 +247,7 @@ func resourceGithubEMUGroupMappingUpdate(ctx context.Context, d *schema.Resource
255247
}
256248
}
257249

258-
tflog.Trace(ctx, "Updated successfully", map[string]any{
259-
"resource_id": d.Id(),
260-
})
250+
tflog.Trace(ctx, "Updated successfully")
261251

262252
return nil
263253
}

0 commit comments

Comments
 (0)