Skip to content

Commit

Permalink
chore: tflog trace -> info (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanndickson authored Aug 19, 2024
1 parent 1a38271 commit dfa7472
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 43 deletions.
16 changes: 8 additions & 8 deletions internal/provider/group_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (r *GroupResource) Create(ctx context.Context, req resource.CreateRequest,

orgID := data.OrganizationID.ValueUUID()

tflog.Trace(ctx, "creating group")
tflog.Info(ctx, "creating group")
group, err := client.CreateGroup(ctx, orgID, codersdk.CreateGroupRequest{
Name: data.Name.ValueString(),
DisplayName: data.DisplayName.ValueString(),
Expand All @@ -169,13 +169,13 @@ func (r *GroupResource) Create(ctx context.Context, req resource.CreateRequest,
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to create group, got error: %s", err))
return
}
tflog.Trace(ctx, "successfully created group", map[string]any{
tflog.Info(ctx, "successfully created group", map[string]any{
"id": group.ID.String(),
})
data.ID = UUIDValue(group.ID)
data.DisplayName = types.StringValue(group.DisplayName)

tflog.Trace(ctx, "setting group members")
tflog.Info(ctx, "setting group members")
var members []string
resp.Diagnostics.Append(
data.Members.ElementsAs(ctx, &members, false)...,
Expand All @@ -190,7 +190,7 @@ func (r *GroupResource) Create(ctx context.Context, req resource.CreateRequest,
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to add members to group, got error: %s", err))
return
}
tflog.Trace(ctx, "successfully set group members")
tflog.Info(ctx, "successfully set group members")

// Save data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
Expand Down Expand Up @@ -270,7 +270,7 @@ func (r *GroupResource) Update(ctx context.Context, req resource.UpdateRequest,
}
add, remove = memberDiff(curMembers, plannedMembers)
}
tflog.Trace(ctx, "updating group", map[string]any{
tflog.Info(ctx, "updating group", map[string]any{
"id": groupID,
"new_members": add,
"removed_members": remove,
Expand All @@ -293,7 +293,7 @@ func (r *GroupResource) Update(ctx context.Context, req resource.UpdateRequest,
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to update group, got error: %s", err))
return
}
tflog.Trace(ctx, "successfully updated group")
tflog.Info(ctx, "successfully updated group")

// Save updated data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
Expand All @@ -312,15 +312,15 @@ func (r *GroupResource) Delete(ctx context.Context, req resource.DeleteRequest,
client := r.data.Client
groupID := data.ID.ValueUUID()

tflog.Trace(ctx, "deleting group", map[string]any{
tflog.Info(ctx, "deleting group", map[string]any{
"id": groupID,
})
err := client.DeleteGroup(ctx, groupID)
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to delete group, got error: %s", err))
return
}
tflog.Trace(ctx, "successfully deleted group")
tflog.Info(ctx, "successfully deleted group")
}

func (r *GroupResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
Expand Down
42 changes: 21 additions & 21 deletions internal/provider/template_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ func (r *TemplateResource) Create(ctx context.Context, req resource.CreateReques
return
}
if idx == 0 {
tflog.Trace(ctx, "creating template")
tflog.Info(ctx, "creating template")
createReq := data.toCreateRequest(ctx, resp, versionResp.ID)
if resp.Diagnostics.HasError() {
return
Expand All @@ -502,7 +502,7 @@ func (r *TemplateResource) Create(ctx context.Context, req resource.CreateReques
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to create template: %s", err))
return
}
tflog.Trace(ctx, "successfully created template", map[string]any{
tflog.Info(ctx, "successfully created template", map[string]any{
"id": templateResp.ID,
})

Expand All @@ -514,7 +514,7 @@ func (r *TemplateResource) Create(ctx context.Context, req resource.CreateReques
}

if !data.ACL.IsNull() {
tflog.Trace(ctx, "updating template ACL")
tflog.Info(ctx, "updating template ACL")
var acl ACL
resp.Diagnostics.Append(
data.ACL.As(ctx, &acl, basetypes.ObjectAsOptions{})...,
Expand All @@ -527,7 +527,7 @@ func (r *TemplateResource) Create(ctx context.Context, req resource.CreateReques
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to create template ACL: %s", err))
return
}
tflog.Trace(ctx, "successfully updated template ACL")
tflog.Info(ctx, "successfully updated template ACL")
}
}
if version.Active.ValueBool() {
Expand Down Expand Up @@ -578,7 +578,7 @@ func (r *TemplateResource) Read(ctx context.Context, req resource.ReadRequest, r
}

if !data.ACL.IsNull() {
tflog.Trace(ctx, "reading template ACL")
tflog.Info(ctx, "reading template ACL")
acl, err := client.TemplateACL(ctx, templateID)
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to get template ACL: %s", err))
Expand All @@ -591,7 +591,7 @@ func (r *TemplateResource) Read(ctx context.Context, req resource.ReadRequest, r
return
}
data.ACL = aclObj
tflog.Trace(ctx, "read template ACL")
tflog.Info(ctx, "read template ACL")
}

for idx, version := range data.Versions {
Expand Down Expand Up @@ -653,7 +653,7 @@ func (r *TemplateResource) Update(ctx context.Context, req resource.UpdateReques
templateMetadataChanged := !newState.EqualTemplateMetadata(&curState)
// This is required, as the API will reject no-diff updates.
if templateMetadataChanged {
tflog.Trace(ctx, "change in template metadata detected, updating.")
tflog.Info(ctx, "change in template metadata detected, updating.")
updateReq := newState.toUpdateRequest(ctx, resp)
if resp.Diagnostics.HasError() {
return
Expand All @@ -664,7 +664,7 @@ func (r *TemplateResource) Update(ctx context.Context, req resource.UpdateReques
return
}

tflog.Trace(ctx, "successfully updated template metadata")
tflog.Info(ctx, "successfully updated template metadata")
}

// Since the everyone group always gets deleted by `DisableEveryoneGroupAccess`, we need to run this even if there
Expand All @@ -680,12 +680,12 @@ func (r *TemplateResource) Update(ctx context.Context, req resource.UpdateReques
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to update template ACL: %s", err))
return
}
tflog.Trace(ctx, "successfully updated template ACL")
tflog.Info(ctx, "successfully updated template ACL")
}

for idx := range newState.Versions {
if newState.Versions[idx].ID.IsUnknown() {
tflog.Trace(ctx, "discovered a new or modified template version")
tflog.Info(ctx, "discovered a new or modified template version")
uploadResp, err := newVersion(ctx, client, newVersionRequest{
Version: &newState.Versions[idx],
OrganizationID: orgID,
Expand Down Expand Up @@ -761,7 +761,7 @@ func (r *TemplateResource) Delete(ctx context.Context, req resource.DeleteReques

templateID := data.ID.ValueUUID()

tflog.Trace(ctx, "deleting template")
tflog.Info(ctx, "deleting template")
err := client.DeleteTemplate(ctx, templateID)
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to delete template: %s", err))
Expand Down Expand Up @@ -927,7 +927,7 @@ func waitForJob(ctx context.Context, client *codersdk.Client, version *codersdk.
if !ok {
break
}
tflog.Trace(ctx, logs.Output, map[string]interface{}{
tflog.Info(ctx, logs.Output, map[string]interface{}{
"job_id": logs.ID,
"job_stage": logs.Stage,
"log_source": logs.Source,
Expand Down Expand Up @@ -959,13 +959,13 @@ type newVersionRequest struct {

func newVersion(ctx context.Context, client *codersdk.Client, req newVersionRequest) (*codersdk.TemplateVersion, error) {
directory := req.Version.Directory.ValueString()
tflog.Trace(ctx, "uploading directory")
tflog.Info(ctx, "uploading directory")
uploadResp, err := uploadDirectory(ctx, client, slog.Make(newTFLogSink(ctx)), directory)
if err != nil {
return nil, fmt.Errorf("failed to upload directory: %s", err)
}
tflog.Trace(ctx, "successfully uploaded directory")
tflog.Trace(ctx, "discovering and parsing vars files")
tflog.Info(ctx, "successfully uploaded directory")
tflog.Info(ctx, "discovering and parsing vars files")
varFiles, err := codersdk.DiscoverVarsFiles(directory)
if err != nil {
return nil, fmt.Errorf("failed to discover vars files: %s", err)
Expand All @@ -974,7 +974,7 @@ func newVersion(ctx context.Context, client *codersdk.Client, req newVersionRequ
if err != nil {
return nil, fmt.Errorf("failed to parse user variable values: %s", err)
}
tflog.Trace(ctx, "discovered and parsed vars files", map[string]any{
tflog.Info(ctx, "discovered and parsed vars files", map[string]any{
"vars": vars,
})
for _, variable := range req.Version.TerraformVariables {
Expand All @@ -994,22 +994,22 @@ func newVersion(ctx context.Context, client *codersdk.Client, req newVersionRequ
if req.TemplateID != nil {
tmplVerReq.TemplateID = *req.TemplateID
}
tflog.Trace(ctx, "creating template version")
tflog.Info(ctx, "creating template version")
versionResp, err := client.CreateTemplateVersion(ctx, req.OrganizationID, tmplVerReq)
if err != nil {
return nil, fmt.Errorf("failed to create template version: %s", err)
}
tflog.Trace(ctx, "waiting for template version import job.")
tflog.Info(ctx, "waiting for template version import job.")
err = waitForJob(ctx, client, &versionResp)
if err != nil {
return nil, fmt.Errorf("failed to wait for job: %s", err)
}
tflog.Trace(ctx, "successfully created template version")
tflog.Info(ctx, "successfully created template version")
return &versionResp, nil
}

func markActive(ctx context.Context, client *codersdk.Client, templateID uuid.UUID, versionID uuid.UUID) error {
tflog.Trace(ctx, "marking template version as active", map[string]any{
tflog.Info(ctx, "marking template version as active", map[string]any{
"version_id": versionID.String(),
"template_id": templateID.String(),
})
Expand All @@ -1019,7 +1019,7 @@ func markActive(ctx context.Context, client *codersdk.Client, templateID uuid.UU
if err != nil {
return fmt.Errorf("Failed to update active template version: %s", err)
}
tflog.Trace(ctx, "marked template version as active")
tflog.Info(ctx, "marked template version as active")
return nil
}

Expand Down
28 changes: 14 additions & 14 deletions internal/provider/user_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (r *UserResource) Create(ctx context.Context, req resource.CreateRequest, r
return
}

tflog.Trace(ctx, "creating user")
tflog.Info(ctx, "creating user")
loginType := codersdk.LoginType(data.LoginType.ValueString())
if loginType == codersdk.LoginTypePassword && data.Password.IsNull() {
resp.Diagnostics.AddError("Data Error", "Password is required when login_type is 'password'")
Expand All @@ -180,12 +180,12 @@ func (r *UserResource) Create(ctx context.Context, req resource.CreateRequest, r
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to create user, got error: %s", err))
return
}
tflog.Trace(ctx, "successfully created user", map[string]any{
tflog.Info(ctx, "successfully created user", map[string]any{
"id": user.ID.String(),
})
data.ID = UUIDValue(user.ID)

tflog.Trace(ctx, "updating user profile")
tflog.Info(ctx, "updating user profile")
name := data.Username
if data.Name.ValueString() != "" {
name = data.Name
Expand All @@ -198,14 +198,14 @@ func (r *UserResource) Create(ctx context.Context, req resource.CreateRequest, r
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to update newly created user profile, got error: %s", err))
return
}
tflog.Trace(ctx, "successfully updated user profile")
tflog.Info(ctx, "successfully updated user profile")
data.Name = types.StringValue(user.Name)

var roles []string
resp.Diagnostics.Append(
data.Roles.ElementsAs(ctx, &roles, false)...,
)
tflog.Trace(ctx, "updating user roles", map[string]any{
tflog.Info(ctx, "updating user roles", map[string]any{
"new_roles": roles,
})
user, err = client.UpdateUserRoles(ctx, user.ID.String(), codersdk.UpdateRoles{
Expand All @@ -215,7 +215,7 @@ func (r *UserResource) Create(ctx context.Context, req resource.CreateRequest, r
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to update newly created user roles, got error: %s", err))
return
}
tflog.Trace(ctx, "successfully updated user roles")
tflog.Info(ctx, "successfully updated user roles")

if data.Suspended.ValueBool() {
_, err = client.UpdateUserStatus(ctx, data.ID.ValueString(), codersdk.UserStatus("suspended"))
Expand Down Expand Up @@ -291,7 +291,7 @@ func (r *UserResource) Update(ctx context.Context, req resource.UpdateRequest, r
if data.Name.ValueString() != "" {
name = data.Name
}
tflog.Trace(ctx, "updating user", map[string]any{
tflog.Info(ctx, "updating user", map[string]any{
"new_username": data.Username.ValueString(),
"new_name": name.ValueString(),
})
Expand All @@ -304,13 +304,13 @@ func (r *UserResource) Update(ctx context.Context, req resource.UpdateRequest, r
return
}
data.Name = name
tflog.Trace(ctx, "successfully updated user profile")
tflog.Info(ctx, "successfully updated user profile")

var roles []string
resp.Diagnostics.Append(
data.Roles.ElementsAs(ctx, &roles, false)...,
)
tflog.Trace(ctx, "updating user roles", map[string]any{
tflog.Info(ctx, "updating user roles", map[string]any{
"new_roles": roles,
})
_, err = client.UpdateUserRoles(ctx, user.ID.String(), codersdk.UpdateRoles{
Expand All @@ -320,18 +320,18 @@ func (r *UserResource) Update(ctx context.Context, req resource.UpdateRequest, r
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to update user roles, got error: %s", err))
return
}
tflog.Trace(ctx, "successfully updated user roles")
tflog.Info(ctx, "successfully updated user roles")

if data.LoginType.ValueString() == string(codersdk.LoginTypePassword) && !data.Password.IsNull() {
tflog.Trace(ctx, "updating password")
tflog.Info(ctx, "updating password")
err = client.UpdateUserPassword(ctx, user.ID.String(), codersdk.UpdateUserPasswordRequest{
Password: data.Password.ValueString(),
})
if err != nil && !strings.Contains(err.Error(), "New password cannot match old password.") {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to update password, got error: %s", err))
return
}
tflog.Trace(ctx, "successfully updated password")
tflog.Info(ctx, "successfully updated password")
}

var statusErr error
Expand Down Expand Up @@ -362,13 +362,13 @@ func (r *UserResource) Delete(ctx context.Context, req resource.DeleteRequest, r

client := r.data.Client

tflog.Trace(ctx, "deleting user")
tflog.Info(ctx, "deleting user")
err := client.DeleteUser(ctx, data.ID.ValueUUID())
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to delete user, got error: %s", err))
return
}
tflog.Trace(ctx, "successfully deleted user")
tflog.Info(ctx, "successfully deleted user")
}

func (r *UserResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
Expand Down

0 comments on commit dfa7472

Please sign in to comment.