From 505683dcd3e34633326232f3a3f47e5c2d275eb8 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Mon, 30 Oct 2017 09:59:52 -0700 Subject: [PATCH] config/module: produce explicit error for non-registry hosts If registry API discovery fails for a particular host then it's better to generate an explicit error message for that early -- so we can tell the user exactly what happened -- rather than assuming a default path and then failing downstream when we get a 404 from that request. --- config/module/registry.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/config/module/registry.go b/config/module/registry.go index 3ea31708d..bef8b3373 100644 --- a/config/module/registry.go +++ b/config/module/registry.go @@ -21,7 +21,6 @@ import ( const ( defaultRegistry = "registry.terraform.io" - defaultApiPath = "/v1/modules" registryServiceID = "registry.v1" xTerraformGet = "X-Terraform-Get" xTerraformVersion = "X-Terraform-Version" @@ -48,11 +47,7 @@ func (e errModuleNotFound) Error() string { func (s *Storage) discoverRegURL(module *regsrc.Module) *url.URL { regURL := s.Services.DiscoverServiceURL(svchost.Hostname(module.RawHost.Normalized()), serviceID) if regURL == nil { - regURL = &url.URL{ - Scheme: "https", - Host: module.RawHost.String(), - Path: defaultApiPath, - } + return nil } if !strings.HasSuffix(regURL.Path, "/") { @@ -85,6 +80,9 @@ func (s *Storage) lookupModuleVersions(module *regsrc.Module) (*response.ModuleV } service := s.discoverRegURL(module) + if service == nil { + return nil, fmt.Errorf("host %s does not provide Terraform modules", module.RawHost.Display()) + } p, err := url.Parse(path.Join(module.Module(), "versions")) if err != nil { @@ -135,6 +133,9 @@ func (s *Storage) lookupModuleLocation(module *regsrc.Module, version string) (s } service := s.discoverRegURL(module) + if service == nil { + return "", fmt.Errorf("host %s does not provide Terraform modules", module.RawHost.Display()) + } var p *url.URL var err error