diff --git a/internal/addrs/output_value_test.go b/internal/addrs/output_value_test.go index fa114c8b80..bfeb673e9b 100644 --- a/internal/addrs/output_value_test.go +++ b/internal/addrs/output_value_test.go @@ -115,7 +115,7 @@ func TestParseAbsOutputValueStr(t *testing.T) { t.Run(input, func(t *testing.T) { got, diags := ParseAbsOutputValueStr(input) for _, problem := range deep.Equal(got, tc.want) { - t.Errorf(problem) + t.Error(problem) } if len(diags) > 0 { gotErr := diags.Err().Error() diff --git a/internal/addrs/parse_ref_test.go b/internal/addrs/parse_ref_test.go index 1441c64ac9..6970031019 100644 --- a/internal/addrs/parse_ref_test.go +++ b/internal/addrs/parse_ref_test.go @@ -159,7 +159,7 @@ func TestParseRefInTestingScope(t *testing.T) { } for _, problem := range deep.Equal(got, test.Want) { - t.Errorf(problem) + t.Error(problem) } }) } @@ -950,7 +950,7 @@ func TestParseRef(t *testing.T) { } for _, problem := range deep.Equal(got, test.Want) { - t.Errorf(problem) + t.Error(problem) } }) } diff --git a/internal/addrs/parse_target_test.go b/internal/addrs/parse_target_test.go index 3c6257bc72..1e3c264efc 100644 --- a/internal/addrs/parse_target_test.go +++ b/internal/addrs/parse_target_test.go @@ -403,7 +403,7 @@ func TestParseTarget(t *testing.T) { } for _, problem := range deep.Equal(got, test.Want) { - t.Errorf(problem) + t.Error(problem) } }) } diff --git a/internal/addrs/provider_test.go b/internal/addrs/provider_test.go index ed1ffdb33c..c7ee613349 100644 --- a/internal/addrs/provider_test.go +++ b/internal/addrs/provider_test.go @@ -432,7 +432,7 @@ func TestParseProviderSourceStr(t *testing.T) { for name, test := range tests { got, diags := ParseProviderSourceString(name) for _, problem := range deep.Equal(got, test.Want) { - t.Errorf(problem) + t.Error(problem) } if len(diags) > 0 { if test.Err == false { diff --git a/internal/backend/remote/backend_common.go b/internal/backend/remote/backend_common.go index f46150a305..50ce2b5e06 100644 --- a/internal/backend/remote/backend_common.go +++ b/internal/backend/remote/backend_common.go @@ -439,9 +439,7 @@ func (b *Remote) checkPolicy(stopCtx, cancelCtx context.Context, op *backendrun. } err = b.confirm(stopCtx, op, opts, r, "override") if err != nil && err != errRunOverridden { - return fmt.Errorf( - fmt.Sprintf("Failed to override: %s\n%s\n", err.Error(), runURL), - ) + return fmt.Errorf("Failed to override: %w\n%s\n", err, runURL) } if err != errRunOverridden { diff --git a/internal/cloud/backend_common.go b/internal/cloud/backend_common.go index 7389d36449..d4f2ffd6c8 100644 --- a/internal/cloud/backend_common.go +++ b/internal/cloud/backend_common.go @@ -412,9 +412,7 @@ func (b *Cloud) checkPolicy(stopCtx, cancelCtx context.Context, op *backendrun.O } err = b.confirm(stopCtx, op, opts, r, "override") if err != nil && err != errRunOverridden { - return fmt.Errorf( - fmt.Sprintf("Failed to override: %s\n%s\n", err.Error(), runURL), - ) + return fmt.Errorf("Failed to override: %w\n%s\n", err, runURL) } if err != errRunOverridden { diff --git a/internal/cloud/backend_taskStages.go b/internal/cloud/backend_taskStages.go index 6a38492ea9..8d9298680a 100644 --- a/internal/cloud/backend_taskStages.go +++ b/internal/cloud/backend_taskStages.go @@ -191,9 +191,7 @@ func (b *Cloud) processStageOverrides(context *IntegrationContext, output Integr runURL := fmt.Sprintf(taskStageHeader, b.Hostname, b.Organization, context.Op.Workspace, context.Run.ID) err := b.confirm(context.StopContext, context.Op, opts, context.Run, "override") if err != nil && err != errRunOverridden { - return false, fmt.Errorf( - fmt.Sprintf("Failed to override: %s\n%s\n", err.Error(), runURL), - ) + return false, fmt.Errorf("Failed to override: %w\n%s\n", err, runURL) } if err != errRunOverridden { diff --git a/internal/cloud/e2e/helper_test.go b/internal/cloud/e2e/helper_test.go index 685b6f3880..f943a47823 100644 --- a/internal/cloud/e2e/helper_test.go +++ b/internal/cloud/e2e/helper_test.go @@ -259,7 +259,7 @@ func skipWithoutRemoteTerraformVersion(t *testing.T) { version := tfversion.Version baseVersion, err := goversion.NewVersion(version) if err != nil { - t.Fatalf(fmt.Sprintf("Error instantiating go-version for %s", version)) + t.Fatalf("Error instantiating go-version for %s", version) } opts := &tfe.AdminTerraformVersionsListOptions{ ListOptions: tfe.ListOptions{ diff --git a/internal/command/init.go b/internal/command/init.go index 89ab5746de..8a223f95b7 100644 --- a/internal/command/init.go +++ b/internal/command/init.go @@ -167,7 +167,7 @@ func (c *InitCommand) Run(args []string) int { // be the first error displayed if that is an issue, but other operations are required // before being able to check core version requirements. if rootModEarly == nil { - diags = diags.Append(fmt.Errorf(view.PrepareMessage(views.InitConfigError)), earlyConfDiags) + diags = diags.Append(errors.New(view.PrepareMessage(views.InitConfigError)), earlyConfDiags) view.Diagnostics(diags) return 1 @@ -259,7 +259,7 @@ func (c *InitCommand) Run(args []string) int { diags = diags.Append(earlyConfDiags) diags = diags.Append(backDiags) if earlyConfDiags.HasErrors() { - diags = diags.Append(fmt.Errorf(view.PrepareMessage(views.InitConfigError))) + diags = diags.Append(errors.New(view.PrepareMessage(views.InitConfigError))) view.Diagnostics(diags) return 1 } @@ -276,7 +276,7 @@ func (c *InitCommand) Run(args []string) int { // show other errors from loading the full configuration tree. diags = diags.Append(confDiags) if confDiags.HasErrors() { - diags = diags.Append(fmt.Errorf(view.PrepareMessage(views.InitConfigError))) + diags = diags.Append(errors.New(view.PrepareMessage(views.InitConfigError))) view.Diagnostics(diags) return 1 } diff --git a/internal/command/meta_backend.go b/internal/command/meta_backend.go index 82178566d2..95c8b3ea80 100644 --- a/internal/command/meta_backend.go +++ b/internal/command/meta_backend.go @@ -242,7 +242,7 @@ func (m *Meta) selectWorkspace(b backend.Backend) error { log.Printf("[TRACE] Meta.selectWorkspace: selecting the new HCP Terraform workspace requested by the user (%s)", name) return m.SetWorkspace(name) } else { - return fmt.Errorf(strings.TrimSpace(errBackendNoExistingWorkspaces)) + return errors.New(strings.TrimSpace(errBackendNoExistingWorkspaces)) } } diff --git a/internal/command/meta_backend_migrate.go b/internal/command/meta_backend_migrate.go index 9c7523bd2b..8ea598c9ab 100644 --- a/internal/command/meta_backend_migrate.go +++ b/internal/command/meta_backend_migrate.go @@ -8,7 +8,6 @@ import ( "context" "errors" "fmt" - "io/ioutil" "log" "os" "path/filepath" @@ -492,7 +491,7 @@ func (m *Meta) backendMigrateNonEmptyConfirm( destination := destinationState.State() // Save both to a temporary - td, err := ioutil.TempDir("", "terraform") + td, err := os.MkdirTemp("", "terraform") if err != nil { return false, fmt.Errorf("Error creating temporary directory: %s", err) } @@ -577,7 +576,7 @@ func (m *Meta) backendMigrateTFC(opts *backendMigrateOpts) error { if sourceTFC && !destinationTFC { // From HCP Terraform to another backend. This is not yet implemented, and // we recommend people to use the HCP Terraform API. - return fmt.Errorf(strings.TrimSpace(errTFCMigrateNotYetImplemented)) + return errors.New(strings.TrimSpace(errTFCMigrateNotYetImplemented)) } // Everything below, by the above two conditionals, now assumes that the diff --git a/internal/command/show.go b/internal/command/show.go index 5334423b2a..9e624a915d 100644 --- a/internal/command/show.go +++ b/internal/command/show.go @@ -286,7 +286,7 @@ func (c *ShowCommand) getDataFromCloudPlan(plan *cloudplan.SavedPlanBookmark, re cl, ok := b.(*cloud.Cloud) if !ok { errMessage := fmt.Sprintf("can't show a saved cloud plan unless the current root module is connected to %s", cl.AppName()) - return nil, errUnusable(fmt.Errorf(errMessage), "cloud plan") + return nil, errUnusable(errors.New(errMessage), "cloud plan") } result, err := cl.ShowPlanForRun(context.Background(), plan.RunID, plan.Hostname, redacted) diff --git a/internal/configs/configload/loader_snapshot_test.go b/internal/configs/configload/loader_snapshot_test.go index b7c0626b62..be3f1ee263 100644 --- a/internal/configs/configload/loader_snapshot_test.go +++ b/internal/configs/configload/loader_snapshot_test.go @@ -45,7 +45,7 @@ func TestLoadConfigWithSnapshot(t *testing.T) { problems := deep.Equal(wantModuleDirs, gotModuleDirs) for _, problem := range problems { - t.Errorf(problem) + t.Error(problem) } if len(problems) > 0 { return diff --git a/internal/depsfile/locks_file_test.go b/internal/depsfile/locks_file_test.go index 2281b7bc8c..0cf9b5ab56 100644 --- a/internal/depsfile/locks_file_test.go +++ b/internal/depsfile/locks_file_test.go @@ -234,7 +234,7 @@ func TestSaveLocksToFile(t *testing.T) { fileInfo, err := os.Stat(filename) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } if mode := fileInfo.Mode(); mode&0111 != 0 { t.Fatalf("Expected lock file to be non-executable: %o", mode) @@ -242,7 +242,7 @@ func TestSaveLocksToFile(t *testing.T) { gotContentBytes, err := ioutil.ReadFile(filename) if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } gotContent := string(gotContentBytes) wantContent := `# This file is maintained automatically by "terraform init". diff --git a/internal/rpcapi/packages_test.go b/internal/rpcapi/packages_test.go index d7d5407a86..b9f7954e39 100644 --- a/internal/rpcapi/packages_test.go +++ b/internal/rpcapi/packages_test.go @@ -99,7 +99,7 @@ func TestPackagesServer_ProviderPackageVersions(t *testing.T) { if diag.Severity == terraform1.Diagnostic_WARNING && diag.Summary == "Additional provider information from registry" { expected := fmt.Sprintf("The remote registry returned warnings for %s:\n%s", tc.source, strings.Join(tc.expectedWarnings, "\n")) if diff := cmp.Diff(expected, diag.Detail); len(diff) > 0 { - t.Errorf(diff) + t.Error(diff) } } } @@ -122,7 +122,7 @@ func TestPackagesServer_ProviderPackageVersions(t *testing.T) { } if diff := cmp.Diff(tc.expectedVersions, response.Versions); len(diff) > 0 { - t.Errorf(diff) + t.Error(diff) } }) } @@ -277,7 +277,7 @@ func TestPackagesServer_FetchProviderPackage(t *testing.T) { } if diff := cmp.Diff(providerHashes[tc.platformLocations[platform]], result.Provider.Hashes); len(diff) > 0 { - t.Errorf(diff) + t.Error(diff) } } }) diff --git a/internal/terraform/context_apply2_test.go b/internal/terraform/context_apply2_test.go index eae1886bbe..147d221306 100644 --- a/internal/terraform/context_apply2_test.go +++ b/internal/terraform/context_apply2_test.go @@ -71,7 +71,7 @@ func TestContext2Apply_createBeforeDestroy_deposedKeyPreApply(t *testing.T) { if diags.HasErrors() { t.Fatalf("diags: %s", diags.Err()) } else { - t.Logf(legacyDiffComparisonString(plan.Changes)) + t.Log(legacyDiffComparisonString(plan.Changes)) } _, diags = ctx.Apply(plan, m, nil) diff --git a/internal/terraform/context_apply_test.go b/internal/terraform/context_apply_test.go index 90c4b45348..5cafacc661 100644 --- a/internal/terraform/context_apply_test.go +++ b/internal/terraform/context_apply_test.go @@ -814,7 +814,7 @@ func TestContext2Apply_providerAliasConfigure(t *testing.T) { if diags.HasErrors() { t.Fatalf("diags: %s", diags.Err()) } else { - t.Logf(legacyDiffComparisonString(plan.Changes)) + t.Log(legacyDiffComparisonString(plan.Changes)) } // Configure to record calls AFTER Plan above @@ -950,7 +950,7 @@ func TestContext2Apply_createBeforeDestroy(t *testing.T) { if diags.HasErrors() { t.Fatalf("diags: %s", diags.Err()) } else { - t.Logf(legacyDiffComparisonString(plan.Changes)) + t.Log(legacyDiffComparisonString(plan.Changes)) } state, diags = ctx.Apply(plan, m, nil) @@ -1030,7 +1030,7 @@ func TestContext2Apply_createBeforeDestroyUpdate(t *testing.T) { if diags.HasErrors() { t.Fatalf("diags: %s", diags.Err()) } else { - t.Logf(legacyDiffComparisonString(plan.Changes)) + t.Log(legacyDiffComparisonString(plan.Changes)) } state, diags = ctx.Apply(plan, m, nil) @@ -1087,7 +1087,7 @@ func TestContext2Apply_createBeforeDestroy_dependsNonCBD(t *testing.T) { if diags.HasErrors() { t.Fatalf("diags: %s", diags.Err()) } else { - t.Logf(legacyDiffComparisonString(plan.Changes)) + t.Log(legacyDiffComparisonString(plan.Changes)) } state, diags = ctx.Apply(plan, m, nil) @@ -1151,7 +1151,7 @@ func TestContext2Apply_createBeforeDestroy_hook(t *testing.T) { if diags.HasErrors() { t.Fatalf("diags: %s", diags.Err()) } else { - t.Logf(legacyDiffComparisonString(plan.Changes)) + t.Log(legacyDiffComparisonString(plan.Changes)) } if _, diags := ctx.Apply(plan, m, nil); diags.HasErrors() { @@ -1227,7 +1227,7 @@ func TestContext2Apply_createBeforeDestroy_deposedCount(t *testing.T) { if diags.HasErrors() { t.Fatalf("diags: %s", diags.Err()) } else { - t.Logf(legacyDiffComparisonString(plan.Changes)) + t.Log(legacyDiffComparisonString(plan.Changes)) } state, diags = ctx.Apply(plan, m, nil) @@ -1287,7 +1287,7 @@ func TestContext2Apply_createBeforeDestroy_deposedOnly(t *testing.T) { if diags.HasErrors() { t.Fatalf("diags: %s", diags.Err()) } else { - t.Logf(legacyDiffComparisonString(plan.Changes)) + t.Log(legacyDiffComparisonString(plan.Changes)) } state, diags = ctx.Apply(plan, m, nil) @@ -1619,7 +1619,7 @@ func TestContext2Apply_dataBasic(t *testing.T) { if diags.HasErrors() { t.Fatalf("diags: %s", diags.Err()) } else { - t.Logf(legacyDiffComparisonString(plan.Changes)) + t.Log(legacyDiffComparisonString(plan.Changes)) } state, diags := ctx.Apply(plan, m, nil) @@ -1674,7 +1674,7 @@ func TestContext2Apply_destroyData(t *testing.T) { if diags.HasErrors() { t.Fatalf("diags: %s", diags.Err()) } else { - t.Logf(legacyDiffComparisonString(plan.Changes)) + t.Log(legacyDiffComparisonString(plan.Changes)) } newState, diags := ctx.Apply(plan, m, nil) @@ -1739,7 +1739,7 @@ func TestContext2Apply_destroySkipsCBD(t *testing.T) { if diags.HasErrors() { t.Fatalf("diags: %s", diags.Err()) } else { - t.Logf(legacyDiffComparisonString(plan.Changes)) + t.Log(legacyDiffComparisonString(plan.Changes)) } if _, diags := ctx.Apply(plan, m, nil); diags.HasErrors() { @@ -3742,7 +3742,7 @@ func TestContext2Apply_multiVarComprehensive(t *testing.T) { t.Run("config for "+key, func(t *testing.T) { for _, problem := range deep.Equal(got, want) { - t.Errorf(problem) + t.Error(problem) } }) } @@ -8333,7 +8333,7 @@ func TestContext2Apply_ignoreChangesCreate(t *testing.T) { if diags.HasErrors() { t.Fatalf("diags: %s", diags.Err()) } else { - t.Logf(legacyDiffComparisonString(plan.Changes)) + t.Log(legacyDiffComparisonString(plan.Changes)) } state, diags := ctx.Apply(plan, m, nil) @@ -8475,7 +8475,7 @@ func TestContext2Apply_ignoreChangesAll(t *testing.T) { logDiagnostics(t, diags) t.Fatal("plan failed") } else { - t.Logf(legacyDiffComparisonString(plan.Changes)) + t.Log(legacyDiffComparisonString(plan.Changes)) } state, diags := ctx.Apply(plan, m, nil) @@ -12646,7 +12646,7 @@ func TestContext2Apply_dataSensitive(t *testing.T) { if diags.HasErrors() { t.Fatalf("diags: %s", diags.Err()) } else { - t.Logf(legacyDiffComparisonString(plan.Changes)) + t.Log(legacyDiffComparisonString(plan.Changes)) } state, diags := ctx.Apply(plan, m, nil) diff --git a/internal/terraform/context_plan_test.go b/internal/terraform/context_plan_test.go index d0b8220d0c..e13eebabb1 100644 --- a/internal/terraform/context_plan_test.go +++ b/internal/terraform/context_plan_test.go @@ -1393,7 +1393,7 @@ func TestContext2Plan_preventDestroy_bad(t *testing.T) { expectedErr := "aws_instance.foo has lifecycle.prevent_destroy" if !strings.Contains(fmt.Sprintf("%s", err), expectedErr) { if plan != nil { - t.Logf(legacyDiffComparisonString(plan.Changes)) + t.Log(legacyDiffComparisonString(plan.Changes)) } t.Fatalf("expected err would contain %q\nerr: %s", expectedErr, err) } @@ -1494,7 +1494,7 @@ func TestContext2Plan_preventDestroy_countBad(t *testing.T) { expectedErr := "aws_instance.foo[1] has lifecycle.prevent_destroy" if !strings.Contains(fmt.Sprintf("%s", err), expectedErr) { if plan != nil { - t.Logf(legacyDiffComparisonString(plan.Changes)) + t.Log(legacyDiffComparisonString(plan.Changes)) } t.Fatalf("expected err would contain %q\nerr: %s", expectedErr, err) } @@ -1620,7 +1620,7 @@ func TestContext2Plan_preventDestroy_destroyPlan(t *testing.T) { expectedErr := "aws_instance.foo has lifecycle.prevent_destroy" if !strings.Contains(fmt.Sprintf("%s", diags.Err()), expectedErr) { if plan != nil { - t.Logf(legacyDiffComparisonString(plan.Changes)) + t.Log(legacyDiffComparisonString(plan.Changes)) } t.Fatalf("expected diagnostics would contain %q\nactual diags: %s", expectedErr, diags.Err()) } diff --git a/internal/terraform/transform_deferred.go b/internal/terraform/transform_deferred.go index 3650c99d38..e0c0e88a7a 100644 --- a/internal/terraform/transform_deferred.go +++ b/internal/terraform/transform_deferred.go @@ -21,7 +21,7 @@ type DeferredTransformer struct { } func (t *DeferredTransformer) Transform(g *Graph) error { - if t.DeferredChanges == nil || len(t.DeferredChanges) == 0 { + if len(t.DeferredChanges) == 0 { return nil }