Skip to content

Commit

Permalink
Add option to use a default registry
Browse files Browse the repository at this point in the history
  • Loading branch information
eveld committed Mar 25, 2024
1 parent 94ac07f commit c4f1894
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type ParserOptions struct {
VariableEnvPrefix string
// location of any downloaded modules
ModuleCache string
// default registry to use when fetching modules
DefaultRegistry string
// credentials to use with the registries
RegistryCredentials map[string]string
// Callback executed when the parser reads a resource stanza, callbacks are
Expand Down Expand Up @@ -648,8 +650,14 @@ func (p *Parser) parseModule(ctx *hcl.EvalContext, c *Config, file string, b *hc
fi, serr := os.Stat(moduleSrc)
if serr != nil || !fi.IsDir() {
moduleURL := src.AsString()

parts := strings.Split(moduleURL, "/")

// if there are 2 parts (namespace, module), check if the default registry is set
if len(parts) == 2 && p.options.DefaultRegistry != "" {
parts = append([]string{p.options.DefaultRegistry}, parts...)
}

// if there are 3 parts (registry, namespace, module) it could be a registry
if len(parts) == 3 {
host := parts[0]
Expand Down

0 comments on commit c4f1894

Please sign in to comment.