diff --git a/internal/addrs/module_package.go b/internal/addrs/module_package.go index dc5a6621c798..e1c82e36ed7a 100644 --- a/internal/addrs/module_package.go +++ b/internal/addrs/module_package.go @@ -1,9 +1,7 @@ package addrs import ( - "strings" - - svchost "github.com/hashicorp/terraform-svchost" + tfaddr "github.com/hashicorp/terraform-registry-address" ) // A ModulePackage represents a physical location where Terraform can retrieve @@ -45,45 +43,4 @@ func (p ModulePackage) String() string { // registry in order to find a real module package address. These being // distinct is intended to help future maintainers more easily follow the // series of steps in the module installer, with the help of the type checker. -type ModuleRegistryPackage struct { - Host svchost.Hostname - Namespace string - Name string - TargetSystem string -} - -func (s ModuleRegistryPackage) String() string { - var buf strings.Builder - // Note: we're using the "display" form of the hostname here because - // for our service hostnames "for display" means something different: - // it means to render non-ASCII characters directly as Unicode - // characters, rather than using the "punycode" representation we - // use for internal processing, and so the "display" representation - // is actually what users would write in their configurations. - return s.Host.ForDisplay() + "/" + s.ForRegistryProtocol() - return buf.String() -} - -func (s ModuleRegistryPackage) ForDisplay() string { - if s.Host == DefaultModuleRegistryHost { - return s.ForRegistryProtocol() - } - return s.Host.ForDisplay() + "/" + s.ForRegistryProtocol() -} - -// ForRegistryProtocol returns a string representation of just the namespace, -// name, and target system portions of the address, always omitting the -// registry hostname and the subdirectory portion, if any. -// -// This is primarily intended for generating addresses to send to the -// registry in question via the registry protocol, since the protocol -// skips sending the registry its own hostname as part of identifiers. -func (s ModuleRegistryPackage) ForRegistryProtocol() string { - var buf strings.Builder - buf.WriteString(s.Namespace) - buf.WriteByte('/') - buf.WriteString(s.Name) - buf.WriteByte('/') - buf.WriteString(s.TargetSystem) - return buf.String() -} +type ModuleRegistryPackage = tfaddr.ModulePackage diff --git a/internal/addrs/module_source.go b/internal/addrs/module_source.go index c42bc9f04459..905b77e2f5c1 100644 --- a/internal/addrs/module_source.go +++ b/internal/addrs/module_source.go @@ -3,10 +3,9 @@ package addrs import ( "fmt" "path" - "regexp" "strings" - svchost "github.com/hashicorp/terraform-svchost" + tfaddr "github.com/hashicorp/terraform-registry-address" "github.com/hashicorp/terraform/internal/getmodules" ) @@ -197,30 +196,11 @@ func (s ModuleSourceLocal) ForDisplay() string { // combination of a ModuleSourceRegistry and a module version number into // a concrete ModuleSourceRemote that Terraform will then download and // install. -type ModuleSourceRegistry struct { - // PackageAddr is the registry package that the target module belongs to. - // The module installer must translate this into a ModuleSourceRemote - // using the registry API and then take that underlying address's - // PackageAddr in order to find the actual package location. - PackageAddr ModuleRegistryPackage - - // If Subdir is non-empty then it represents a sub-directory within the - // remote package that the registry address eventually resolves to. - // This will ultimately become the suffix of the Subdir of the - // ModuleSourceRemote that the registry address translates to. - // - // Subdir uses a normalized forward-slash-based path syntax within the - // virtual filesystem represented by the final package. It will never - // include `../` or `./` sequences. - Subdir string -} +type ModuleSourceRegistry tfaddr.Module // DefaultModuleRegistryHost is the hostname used for registry-based module // source addresses that do not have an explicit hostname. -const DefaultModuleRegistryHost = svchost.Hostname("registry.terraform.io") - -var moduleRegistryNamePattern = regexp.MustCompile("^[0-9A-Za-z](?:[0-9A-Za-z-_]{0,62}[0-9A-Za-z])?$") -var moduleRegistryTargetSystemPattern = regexp.MustCompile("^[0-9a-z]{1,64}$") +const DefaultModuleRegistryHost = tfaddr.DefaultModuleRegistryHost // ParseModuleSourceRegistry is a variant of ParseModuleSource which only // accepts module registry addresses, and will reject any other address type. @@ -237,147 +217,30 @@ func ParseModuleSourceRegistry(raw string) (ModuleSource, error) { return ModuleSourceRegistry{}, fmt.Errorf("can't use local directory %q as a module registry address", raw) } - ret, err := parseModuleSourceRegistry(raw) + src, err := tfaddr.ParseModuleSource(raw) if err != nil { - // This is to make sure we return a nil ModuleSource, rather than - // a non-nil ModuleSource containing a zero-value ModuleSourceRegistry. return nil, err } - return ret, nil -} - -func parseModuleSourceRegistry(raw string) (ModuleSourceRegistry, error) { - var err error - - var subDir string - raw, subDir = getmodules.SplitPackageSubdir(raw) - if strings.HasPrefix(subDir, "../") { - return ModuleSourceRegistry{}, fmt.Errorf("subdirectory path %q leads outside of the module package", subDir) - } - - parts := strings.Split(raw, "/") - // A valid registry address has either three or four parts, because the - // leading hostname part is optional. - if len(parts) != 3 && len(parts) != 4 { - return ModuleSourceRegistry{}, fmt.Errorf("a module registry source address must have either three or four slash-separated components") - } - - host := DefaultModuleRegistryHost - if len(parts) == 4 { - host, err = svchost.ForComparison(parts[0]) - if err != nil { - // The svchost library doesn't produce very good error messages to - // return to an end-user, so we'll use some custom ones here. - switch { - case strings.Contains(parts[0], "--"): - // Looks like possibly punycode, which we don't allow here - // to ensure that source addresses are written readably. - return ModuleSourceRegistry{}, fmt.Errorf("invalid module registry hostname %q; internationalized domain names must be given as direct unicode characters, not in punycode", parts[0]) - default: - return ModuleSourceRegistry{}, fmt.Errorf("invalid module registry hostname %q", parts[0]) - } - } - if !strings.Contains(host.String(), ".") { - return ModuleSourceRegistry{}, fmt.Errorf("invalid module registry hostname: must contain at least one dot") - } - // Discard the hostname prefix now that we've processed it - parts = parts[1:] - } - - ret := ModuleSourceRegistry{ - PackageAddr: ModuleRegistryPackage{ - Host: host, - }, - - Subdir: subDir, - } - - if host == svchost.Hostname("github.com") || host == svchost.Hostname("bitbucket.org") { - return ret, fmt.Errorf("can't use %q as a module registry host, because it's reserved for installing directly from version control repositories", host) - } - - if ret.PackageAddr.Namespace, err = parseModuleRegistryName(parts[0]); err != nil { - if strings.Contains(parts[0], ".") { - // Seems like the user omitted one of the latter components in - // an address with an explicit hostname. - return ret, fmt.Errorf("source address must have three more components after the hostname: the namespace, the name, and the target system") - } - return ret, fmt.Errorf("invalid namespace %q: %s", parts[0], err) - } - if ret.PackageAddr.Name, err = parseModuleRegistryName(parts[1]); err != nil { - return ret, fmt.Errorf("invalid module name %q: %s", parts[1], err) - } - if ret.PackageAddr.TargetSystem, err = parseModuleRegistryTargetSystem(parts[2]); err != nil { - if strings.Contains(parts[2], "?") { - // The user was trying to include a query string, probably? - return ret, fmt.Errorf("module registry addresses may not include a query string portion") - } - return ret, fmt.Errorf("invalid target system %q: %s", parts[2], err) - } - - return ret, nil -} - -// parseModuleRegistryName validates and normalizes a string in either the -// "namespace" or "name" position of a module registry source address. -func parseModuleRegistryName(given string) (string, error) { - // Similar to the names in provider source addresses, we defined these - // to be compatible with what filesystems and typical remote systems - // like GitHub allow in names. Unfortunately we didn't end up defining - // these exactly equivalently: provider names can only use dashes as - // punctuation, whereas module names can use underscores. So here we're - // using some regular expressions from the original module source - // implementation, rather than using the IDNA rules as we do in - // ParseProviderPart. - - if !moduleRegistryNamePattern.MatchString(given) { - return "", fmt.Errorf("must be between one and 64 characters, including ASCII letters, digits, dashes, and underscores, where dashes and underscores may not be the prefix or suffix") - } - - // We also skip normalizing the name to lowercase, because we historically - // didn't do that and so existing module registries might be doing - // case-sensitive matching. - return given, nil -} - -// parseModuleRegistryTargetSystem validates and normalizes a string in the -// "target system" position of a module registry source address. This is -// what we historically called "provider" but never actually enforced as -// being a provider address, and now _cannot_ be a provider address because -// provider addresses have three slash-separated components of their own. -func parseModuleRegistryTargetSystem(given string) (string, error) { - // Similar to the names in provider source addresses, we defined these - // to be compatible with what filesystems and typical remote systems - // like GitHub allow in names. Unfortunately we didn't end up defining - // these exactly equivalently: provider names can't use dashes or - // underscores. So here we're using some regular expressions from the - // original module source implementation, rather than using the IDNA rules - // as we do in ParseProviderPart. - - if !moduleRegistryTargetSystemPattern.MatchString(given) { - return "", fmt.Errorf("must be between one and 64 ASCII letters or digits") - } - - // We also skip normalizing the name to lowercase, because we historically - // didn't do that and so existing module registries might be doing - // case-sensitive matching. - return given, nil + return ModuleSourceRegistry{ + Package: src.Package, + Subdir: src.Subdir, + }, nil } func (s ModuleSourceRegistry) moduleSource() {} func (s ModuleSourceRegistry) String() string { if s.Subdir != "" { - return s.PackageAddr.String() + "//" + s.Subdir + return s.Package.String() + "//" + s.Subdir } - return s.PackageAddr.String() + return s.Package.String() } func (s ModuleSourceRegistry) ForDisplay() string { if s.Subdir != "" { - return s.PackageAddr.ForDisplay() + "//" + s.Subdir + return s.Package.ForDisplay() + "//" + s.Subdir } - return s.PackageAddr.ForDisplay() + return s.Package.ForDisplay() } // ModuleSourceRemote is a ModuleSource representing a remote location from @@ -387,9 +250,9 @@ func (s ModuleSourceRegistry) ForDisplay() string { // means that it's selecting a sub-directory of the given package to use as // the entry point into the package. type ModuleSourceRemote struct { - // PackageAddr is the address of the remote package that the requested + // Package is the address of the remote package that the requested // module belongs to. - PackageAddr ModulePackage + Package ModulePackage // If Subdir is non-empty then it represents a sub-directory within the // remote package which will serve as the entry-point for the package. @@ -445,8 +308,8 @@ func parseModuleSourceRemote(raw string) (ModuleSourceRemote, error) { } return ModuleSourceRemote{ - PackageAddr: ModulePackage(norm), - Subdir: subDir, + Package: ModulePackage(norm), + Subdir: subDir, }, nil } @@ -454,9 +317,9 @@ func (s ModuleSourceRemote) moduleSource() {} func (s ModuleSourceRemote) String() string { if s.Subdir != "" { - return s.PackageAddr.String() + "//" + s.Subdir + return s.Package.String() + "//" + s.Subdir } - return s.PackageAddr.String() + return s.Package.String() } func (s ModuleSourceRemote) ForDisplay() string { diff --git a/internal/addrs/module_source_test.go b/internal/addrs/module_source_test.go index 9604c33744bd..d6b5626ec682 100644 --- a/internal/addrs/module_source_test.go +++ b/internal/addrs/module_source_test.go @@ -59,7 +59,7 @@ func TestParseModuleSource(t *testing.T) { "main registry implied": { input: "hashicorp/subnets/cidr", want: ModuleSourceRegistry{ - PackageAddr: ModuleRegistryPackage{ + Package: ModuleRegistryPackage{ Host: svchost.Hostname("registry.terraform.io"), Namespace: "hashicorp", Name: "subnets", @@ -71,7 +71,7 @@ func TestParseModuleSource(t *testing.T) { "main registry implied, subdir": { input: "hashicorp/subnets/cidr//examples/foo", want: ModuleSourceRegistry{ - PackageAddr: ModuleRegistryPackage{ + Package: ModuleRegistryPackage{ Host: svchost.Hostname("registry.terraform.io"), Namespace: "hashicorp", Name: "subnets", @@ -92,7 +92,7 @@ func TestParseModuleSource(t *testing.T) { "custom registry": { input: "example.com/awesomecorp/network/happycloud", want: ModuleSourceRegistry{ - PackageAddr: ModuleRegistryPackage{ + Package: ModuleRegistryPackage{ Host: svchost.Hostname("example.com"), Namespace: "awesomecorp", Name: "network", @@ -104,7 +104,7 @@ func TestParseModuleSource(t *testing.T) { "custom registry, subdir": { input: "example.com/awesomecorp/network/happycloud//examples/foo", want: ModuleSourceRegistry{ - PackageAddr: ModuleRegistryPackage{ + Package: ModuleRegistryPackage{ Host: svchost.Hostname("example.com"), Namespace: "awesomecorp", Name: "network", @@ -118,68 +118,68 @@ func TestParseModuleSource(t *testing.T) { "github.com shorthand": { input: "github.com/hashicorp/terraform-cidr-subnets", want: ModuleSourceRemote{ - PackageAddr: ModulePackage("git::https://github.com/hashicorp/terraform-cidr-subnets.git"), + Package: ModulePackage("git::https://github.com/hashicorp/terraform-cidr-subnets.git"), }, }, "github.com shorthand, subdir": { input: "github.com/hashicorp/terraform-cidr-subnets//example/foo", want: ModuleSourceRemote{ - PackageAddr: ModulePackage("git::https://github.com/hashicorp/terraform-cidr-subnets.git"), - Subdir: "example/foo", + Package: ModulePackage("git::https://github.com/hashicorp/terraform-cidr-subnets.git"), + Subdir: "example/foo", }, }, "git protocol, URL-style": { input: "git://example.com/code/baz.git", want: ModuleSourceRemote{ - PackageAddr: ModulePackage("git://example.com/code/baz.git"), + Package: ModulePackage("git://example.com/code/baz.git"), }, }, "git protocol, URL-style, subdir": { input: "git://example.com/code/baz.git//bleep/bloop", want: ModuleSourceRemote{ - PackageAddr: ModulePackage("git://example.com/code/baz.git"), - Subdir: "bleep/bloop", + Package: ModulePackage("git://example.com/code/baz.git"), + Subdir: "bleep/bloop", }, }, "git over HTTPS, URL-style": { input: "git::https://example.com/code/baz.git", want: ModuleSourceRemote{ - PackageAddr: ModulePackage("git::https://example.com/code/baz.git"), + Package: ModulePackage("git::https://example.com/code/baz.git"), }, }, "git over HTTPS, URL-style, subdir": { input: "git::https://example.com/code/baz.git//bleep/bloop", want: ModuleSourceRemote{ - PackageAddr: ModulePackage("git::https://example.com/code/baz.git"), - Subdir: "bleep/bloop", + Package: ModulePackage("git::https://example.com/code/baz.git"), + Subdir: "bleep/bloop", }, }, "git over SSH, URL-style": { input: "git::ssh://git@example.com/code/baz.git", want: ModuleSourceRemote{ - PackageAddr: ModulePackage("git::ssh://git@example.com/code/baz.git"), + Package: ModulePackage("git::ssh://git@example.com/code/baz.git"), }, }, "git over SSH, URL-style, subdir": { input: "git::ssh://git@example.com/code/baz.git//bleep/bloop", want: ModuleSourceRemote{ - PackageAddr: ModulePackage("git::ssh://git@example.com/code/baz.git"), - Subdir: "bleep/bloop", + Package: ModulePackage("git::ssh://git@example.com/code/baz.git"), + Subdir: "bleep/bloop", }, }, "git over SSH, scp-style": { input: "git::git@example.com:code/baz.git", want: ModuleSourceRemote{ // Normalized to URL-style - PackageAddr: ModulePackage("git::ssh://git@example.com/code/baz.git"), + Package: ModulePackage("git::ssh://git@example.com/code/baz.git"), }, }, "git over SSH, scp-style, subdir": { input: "git::git@example.com:code/baz.git//bleep/bloop", want: ModuleSourceRemote{ // Normalized to URL-style - PackageAddr: ModulePackage("git::ssh://git@example.com/code/baz.git"), - Subdir: "bleep/bloop", + Package: ModulePackage("git::ssh://git@example.com/code/baz.git"), + Subdir: "bleep/bloop", }, }, @@ -190,63 +190,63 @@ func TestParseModuleSource(t *testing.T) { "Google Cloud Storage bucket implied, path prefix": { input: "www.googleapis.com/storage/v1/BUCKET_NAME/PATH_TO_MODULE", want: ModuleSourceRemote{ - PackageAddr: ModulePackage("gcs::https://www.googleapis.com/storage/v1/BUCKET_NAME/PATH_TO_MODULE"), + Package: ModulePackage("gcs::https://www.googleapis.com/storage/v1/BUCKET_NAME/PATH_TO_MODULE"), }, }, "Google Cloud Storage bucket, path prefix": { input: "gcs::https://www.googleapis.com/storage/v1/BUCKET_NAME/PATH_TO_MODULE", want: ModuleSourceRemote{ - PackageAddr: ModulePackage("gcs::https://www.googleapis.com/storage/v1/BUCKET_NAME/PATH_TO_MODULE"), + Package: ModulePackage("gcs::https://www.googleapis.com/storage/v1/BUCKET_NAME/PATH_TO_MODULE"), }, }, "Google Cloud Storage bucket implied, archive object": { input: "www.googleapis.com/storage/v1/BUCKET_NAME/PATH/TO/module.zip", want: ModuleSourceRemote{ - PackageAddr: ModulePackage("gcs::https://www.googleapis.com/storage/v1/BUCKET_NAME/PATH/TO/module.zip"), + Package: ModulePackage("gcs::https://www.googleapis.com/storage/v1/BUCKET_NAME/PATH/TO/module.zip"), }, }, "Google Cloud Storage bucket, archive object": { input: "gcs::https://www.googleapis.com/storage/v1/BUCKET_NAME/PATH/TO/module.zip", want: ModuleSourceRemote{ - PackageAddr: ModulePackage("gcs::https://www.googleapis.com/storage/v1/BUCKET_NAME/PATH/TO/module.zip"), + Package: ModulePackage("gcs::https://www.googleapis.com/storage/v1/BUCKET_NAME/PATH/TO/module.zip"), }, }, "Amazon S3 bucket implied, archive object": { input: "s3-eu-west-1.amazonaws.com/examplecorp-terraform-modules/vpc.zip", want: ModuleSourceRemote{ - PackageAddr: ModulePackage("s3::https://s3-eu-west-1.amazonaws.com/examplecorp-terraform-modules/vpc.zip"), + Package: ModulePackage("s3::https://s3-eu-west-1.amazonaws.com/examplecorp-terraform-modules/vpc.zip"), }, }, "Amazon S3 bucket, archive object": { input: "s3::https://s3-eu-west-1.amazonaws.com/examplecorp-terraform-modules/vpc.zip", want: ModuleSourceRemote{ - PackageAddr: ModulePackage("s3::https://s3-eu-west-1.amazonaws.com/examplecorp-terraform-modules/vpc.zip"), + Package: ModulePackage("s3::https://s3-eu-west-1.amazonaws.com/examplecorp-terraform-modules/vpc.zip"), }, }, "HTTP URL": { input: "http://example.com/module", want: ModuleSourceRemote{ - PackageAddr: ModulePackage("http://example.com/module"), + Package: ModulePackage("http://example.com/module"), }, }, "HTTPS URL": { input: "https://example.com/module", want: ModuleSourceRemote{ - PackageAddr: ModulePackage("https://example.com/module"), + Package: ModulePackage("https://example.com/module"), }, }, "HTTPS URL, archive file": { input: "https://example.com/module.zip", want: ModuleSourceRemote{ - PackageAddr: ModulePackage("https://example.com/module.zip"), + Package: ModulePackage("https://example.com/module.zip"), }, }, "HTTPS URL, forced archive file": { input: "https://example.com/module?archive=tar", want: ModuleSourceRemote{ - PackageAddr: ModulePackage("https://example.com/module?archive=tar"), + Package: ModulePackage("https://example.com/module?archive=tar"), }, }, "HTTPS URL, forced archive file and checksum": { @@ -255,7 +255,7 @@ func TestParseModuleSource(t *testing.T) { // The query string only actually gets processed when we finally // do the get, so "checksum=blah" is accepted as valid up // at this parsing layer. - PackageAddr: ModulePackage("https://example.com/module?archive=tar&checksum=blah"), + Package: ModulePackage("https://example.com/module?archive=tar&checksum=blah"), }, }, @@ -266,7 +266,7 @@ func TestParseModuleSource(t *testing.T) { // is replaced by a deep filesystem copy instead. input: "/tmp/foo/example", want: ModuleSourceRemote{ - PackageAddr: ModulePackage("file:///tmp/foo/example"), + Package: ModulePackage("file:///tmp/foo/example"), }, }, "absolute filesystem path, subdir": { @@ -277,8 +277,8 @@ func TestParseModuleSource(t *testing.T) { // syntax to move the package root higher in the real filesystem. input: "/tmp/foo//example", want: ModuleSourceRemote{ - PackageAddr: ModulePackage("file:///tmp/foo"), - Subdir: "example", + Package: ModulePackage("file:///tmp/foo"), + Subdir: "example", }, }, @@ -310,7 +310,7 @@ func TestParseModuleSource(t *testing.T) { // Unfortunately go-getter doesn't actually reject a totally // invalid address like this until getting time, as long as // it looks somewhat like a URL. - PackageAddr: ModulePackage("dfgdfgsd:dgfhdfghdfghdfg/dfghdfghdfg"), + Package: ModulePackage("dfgdfgsd:dgfhdfghdfghdfg/dfghdfghdfg"), }, }, } @@ -344,8 +344,8 @@ func TestParseModuleSource(t *testing.T) { func TestModuleSourceRemoteFromRegistry(t *testing.T) { t.Run("both have subdir", func(t *testing.T) { remote := ModuleSourceRemote{ - PackageAddr: ModulePackage("boop"), - Subdir: "foo", + Package: ModulePackage("boop"), + Subdir: "foo", } registry := ModuleSourceRegistry{ Subdir: "bar", @@ -363,8 +363,8 @@ func TestModuleSourceRemoteFromRegistry(t *testing.T) { }) t.Run("only remote has subdir", func(t *testing.T) { remote := ModuleSourceRemote{ - PackageAddr: ModulePackage("boop"), - Subdir: "foo", + Package: ModulePackage("boop"), + Subdir: "foo", } registry := ModuleSourceRegistry{ Subdir: "", @@ -382,8 +382,8 @@ func TestModuleSourceRemoteFromRegistry(t *testing.T) { }) t.Run("only registry has subdir", func(t *testing.T) { remote := ModuleSourceRemote{ - PackageAddr: ModulePackage("boop"), - Subdir: "", + Package: ModulePackage("boop"), + Subdir: "", } registry := ModuleSourceRegistry{ Subdir: "bar", @@ -565,7 +565,7 @@ func TestParseModuleSourceRegistry(t *testing.T) { if got, want := addr.ForDisplay(), test.wantForDisplay; got != want { t.Errorf("wrong ForDisplay() result\ngot: %s\nwant: %s", got, want) } - if got, want := addr.PackageAddr.ForRegistryProtocol(), test.wantForProtocol; got != want { + if got, want := addr.Package.ForRegistryProtocol(), test.wantForProtocol; got != want { t.Errorf("wrong ForRegistryProtocol() result\ngot: %s\nwant: %s", got, want) } }) diff --git a/internal/configs/module_call_test.go b/internal/configs/module_call_test.go index 9c607f8e34c3..af2269dca0bb 100644 --- a/internal/configs/module_call_test.go +++ b/internal/configs/module_call_test.go @@ -45,7 +45,7 @@ func TestLoadModuleCall(t *testing.T) { { Name: "bar", SourceAddr: addrs.ModuleSourceRegistry{ - PackageAddr: addrs.ModuleRegistryPackage{ + Package: addrs.ModuleRegistryPackage{ Host: addrs.DefaultModuleRegistryHost, Namespace: "hashicorp", Name: "bar", @@ -68,7 +68,7 @@ func TestLoadModuleCall(t *testing.T) { { Name: "baz", SourceAddr: addrs.ModuleSourceRemote{ - PackageAddr: addrs.ModulePackage("git::https://example.com/"), + Package: addrs.ModulePackage("git::https://example.com/"), }, SourceAddrRaw: "git::https://example.com/", SourceSet: true, diff --git a/internal/initwd/module_install.go b/internal/initwd/module_install.go index e9ee4953183c..0bc971860a1b 100644 --- a/internal/initwd/module_install.go +++ b/internal/initwd/module_install.go @@ -306,7 +306,7 @@ func (i *ModuleInstaller) installLocalModule(req *earlyconfig.ModuleRequest, key func (i *ModuleInstaller) installRegistryModule(ctx context.Context, req *earlyconfig.ModuleRequest, key string, instPath string, addr addrs.ModuleSourceRegistry, manifest modsdir.Manifest, hooks ModuleInstallHooks, fetcher *getmodules.PackageFetcher) (*tfconfig.Module, *version.Version, tfdiags.Diagnostics) { var diags tfdiags.Diagnostics - hostname := addr.PackageAddr.Host + hostname := addr.Package.Host reg := i.reg var resp *response.ModuleVersions var exists bool @@ -314,7 +314,7 @@ func (i *ModuleInstaller) installRegistryModule(ctx context.Context, req *earlyc // A registry entry isn't _really_ a module package, but we'll pretend it's // one for the sake of this reporting by just trimming off any source // directory. - packageAddr := addr.PackageAddr + packageAddr := addr.Package // Our registry client is still using the legacy model of addresses, so // we'll shim it here for now. @@ -469,9 +469,9 @@ func (i *ModuleInstaller) installRegistryModule(ctx context.Context, req *earlyc dlAddr := i.registryPackageSources[moduleAddr] - log.Printf("[TRACE] ModuleInstaller: %s %s %s is available at %q", key, packageAddr, latestMatch, dlAddr.PackageAddr) + log.Printf("[TRACE] ModuleInstaller: %s %s %s is available at %q", key, packageAddr, latestMatch, dlAddr.Package) - err := fetcher.FetchPackage(ctx, instPath, dlAddr.PackageAddr.String()) + err := fetcher.FetchPackage(ctx, instPath, dlAddr.Package.String()) if errors.Is(err, context.Canceled) { diags = diags.Append(tfdiags.Sourceless( tfdiags.Error, @@ -494,7 +494,7 @@ func (i *ModuleInstaller) installRegistryModule(ctx context.Context, req *earlyc return nil, nil, diags } - log.Printf("[TRACE] ModuleInstaller: %s %q was downloaded to %s", key, dlAddr.PackageAddr, instPath) + log.Printf("[TRACE] ModuleInstaller: %s %q was downloaded to %s", key, dlAddr.Package, instPath) // Incorporate any subdir information from the original path into the // address returned by the registry in order to find the final directory @@ -540,7 +540,7 @@ func (i *ModuleInstaller) installGoGetterModule(ctx context.Context, req *earlyc // Report up to the caller that we're about to start downloading. addr := req.SourceAddr.(addrs.ModuleSourceRemote) - packageAddr := addr.PackageAddr + packageAddr := addr.Package hooks.Download(key, packageAddr.String(), nil) if len(req.VersionConstraints) != 0 { @@ -758,7 +758,7 @@ func splitAddrSubdir(addr addrs.ModuleSource) (string, string) { addr.Subdir = "" return addr.String(), subDir case addrs.ModuleSourceRemote: - return addr.PackageAddr.String(), addr.Subdir + return addr.Package.String(), addr.Subdir case nil: panic("splitAddrSubdir on nil addrs.ModuleSource") default: diff --git a/internal/refactoring/move_validate_test.go b/internal/refactoring/move_validate_test.go index aa4ec4f3b800..2a61bdc6c2c9 100644 --- a/internal/refactoring/move_validate_test.go +++ b/internal/refactoring/move_validate_test.go @@ -702,5 +702,5 @@ func makeTestImpliedMoveStmt(t *testing.T, moduleStr, fromStr, toStr string) Mov } var fakeExternalModuleSource = addrs.ModuleSourceRemote{ - PackageAddr: addrs.ModulePackage("fake-external:///"), + Package: addrs.ModulePackage("fake-external:///"), } diff --git a/internal/registry/regsrc/module.go b/internal/registry/regsrc/module.go index 9f9999d3474b..3ffa002bba07 100644 --- a/internal/registry/regsrc/module.go +++ b/internal/registry/regsrc/module.go @@ -105,7 +105,7 @@ func NewModule(host, namespace, name, provider, submodule string) (*Module, erro // use addrs.ModuleSourceRegistry instead, and then package regsrc can be // removed altogether. func ModuleFromModuleSourceAddr(addr addrs.ModuleSourceRegistry) *Module { - ret := ModuleFromRegistryPackageAddr(addr.PackageAddr) + ret := ModuleFromRegistryPackageAddr(addr.Package) ret.RawSubmodule = addr.Subdir return ret }