Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport missed commits from #31408 #31726

Merged
merged 1 commit into from Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 0 additions & 14 deletions internal/command/init.go
Expand Up @@ -763,20 +763,6 @@ func (c *InitCommand) getProviders(config *configs.Config, state *states.State,
// but rather just emit a single general message about it at
// the end, by checking ctx.Err().

case providercache.ErrProviderChecksumMiss:
// This is a special kind of error that can often be fixed using
// the `terraform providers lock` command. We're just going to
// amend the actual error message with some extra information
// about how to fix this.

diags = diags.Append(tfdiags.Sourceless(
tfdiags.Error,
"Failed to install provider",
fmt.Sprintf("Error while installing %s v%s: %s\n\nYou can ensure the current platform, %s, is included in the dependency lock file by running: `terraform providers lock -provider=%s`.\n\nIf this does not fix the problem you may need to reset any provider caching present in your setup or make sure you are connecting to valid provider distributions.",
provider.ForDisplay(), version, err.Msg, err.Meta.TargetPlatform.String(), err.Meta.TargetPlatform.String(),
),
))

default:
// We can potentially end up in here under cancellation too,
// in spite of our getproviders.ErrRequestCanceled case above,
Expand Down
1 change: 1 addition & 0 deletions internal/getproviders/errors.go
Expand Up @@ -5,6 +5,7 @@ import (
"net/url"

svchost "github.com/hashicorp/terraform-svchost"

"github.com/hashicorp/terraform/internal/addrs"
)

Expand Down
14 changes: 0 additions & 14 deletions internal/providercache/errors.go

This file was deleted.

5 changes: 3 additions & 2 deletions internal/providercache/installer_test.go
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/google/go-cmp/cmp"
svchost "github.com/hashicorp/terraform-svchost"
"github.com/hashicorp/terraform-svchost/disco"

"github.com/hashicorp/terraform/internal/addrs"
"github.com/hashicorp/terraform/internal/depsfile"
"github.com/hashicorp/terraform/internal/getproviders"
Expand Down Expand Up @@ -1401,7 +1402,7 @@ func TestEnsureProviderVersions(t *testing.T) {
beepProvider: getproviders.MustParseVersionConstraints(">= 1.0.0"),
},
WantErr: `some providers could not be installed:
- example.com/foo/beep: the local package for example.com/foo/beep 1.0.0 doesn't match any of the checksums previously recorded in the dependency lock file (this might be because the available checksums are for packages targeting different platforms)`,
- example.com/foo/beep: the local package for example.com/foo/beep 1.0.0 doesn't match any of the checksums previously recorded in the dependency lock file (this might be because the available checksums are for packages targeting different platforms); for more information: https://www.terraform.io/language/provider-checksum-verification`,
WantEvents: func(inst *Installer, dir *Dir) map[addrs.Provider][]*testInstallerEventLogItem {
return map[addrs.Provider][]*testInstallerEventLogItem{
noProvider: {
Expand Down Expand Up @@ -1447,7 +1448,7 @@ func TestEnsureProviderVersions(t *testing.T) {
Error string
}{
"1.0.0",
`the local package for example.com/foo/beep 1.0.0 doesn't match any of the checksums previously recorded in the dependency lock file (this might be because the available checksums are for packages targeting different platforms)`,
`the local package for example.com/foo/beep 1.0.0 doesn't match any of the checksums previously recorded in the dependency lock file (this might be because the available checksums are for packages targeting different platforms); for more information: https://www.terraform.io/language/provider-checksum-verification`,
},
},
},
Expand Down
22 changes: 8 additions & 14 deletions internal/providercache/package_install.go
Expand Up @@ -116,13 +116,10 @@ func installFromLocalArchive(ctx context.Context, meta getproviders.PackageMeta,
meta.Provider, meta.Version, meta.Location, err,
)
} else if !matches {
return authResult, ErrProviderChecksumMiss{
Meta: meta,
Msg: fmt.Sprintf(
"the current package for %s %s doesn't match any of the checksums previously recorded in the dependency lock file",
meta.Provider, meta.Version,
),
}
return authResult, fmt.Errorf(
"the current package for %s %s doesn't match any of the checksums previously recorded in the dependency lock file; for more information: https://www.terraform.io/language/provider-checksum-verification",
meta.Provider, meta.Version,
)
}
}

Expand Down Expand Up @@ -201,13 +198,10 @@ func installFromLocalDir(ctx context.Context, meta getproviders.PackageMeta, tar
meta.Provider, meta.Version, meta.Location, err,
)
} else if !matches {
return authResult, ErrProviderChecksumMiss{
Meta: meta,
Msg: fmt.Sprintf(
"the local package for %s %s doesn't match any of the checksums previously recorded in the dependency lock file (this might be because the available checksums are for packages targeting different platforms)",
meta.Provider, meta.Version,
),
}
return authResult, fmt.Errorf(
"the local package for %s %s doesn't match any of the checksums previously recorded in the dependency lock file (this might be because the available checksums are for packages targeting different platforms); for more information: https://www.terraform.io/language/provider-checksum-verification",
meta.Provider, meta.Version,
)
}
}

Expand Down