Skip to content
This repository was archived by the owner on Jun 11, 2021. It is now read-only.

Commit 25daaee

Browse files
committed
This commit allows users to set the module download directory in the Terrafile.
1 parent 5eb7606 commit 25daaee

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

Terrafile.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
vendor_dir: vendor/modules
2+
13
terrafile-test-registry:
24
source: "terraform-digitalocean-modules/droplet/digitalocean"
35
version: "0.1.x"

cmd/install.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ var installCmd = &cobra.Command{
4545
os.MkdirAll(VendorDir, os.ModePerm)
4646

4747
var wg sync.WaitGroup
48-
wg.Add(len(Config))
48+
wg.Add(len(Config.Modules))
4949

50-
for moduleName, moduleMeta := range Config {
50+
for moduleName, moduleMeta := range Config.Modules {
5151
go getModule(moduleName, moduleMeta, &wg)
5252
}
5353
wg.Wait()

cmd/root.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,20 @@ type module struct {
3737
Path string `yaml:"path"`
3838
}
3939

40+
type cfgFileContents struct {
41+
VendorDirFromFile string `yaml:"vendor_dir"`
42+
Modules map[string]module `yaml:",inline"`
43+
}
44+
4045
var cfgFile string
4146

4247
// VendorDir is the directory to download modules to
4348
var VendorDir string
4449

50+
const defaultVendorDir = "vendor/modules"
51+
4552
// Config holds our module information
46-
var Config map[string]module
53+
var Config cfgFileContents
4754

4855
// rootCmd represents the base command when called without any subcommands
4956
var rootCmd = &cobra.Command{
@@ -62,12 +69,13 @@ func Execute() {
6269

6370
func init() {
6471
// Exclude certain commands from initConfig
72+
rootCmd.PersistentFlags().StringVarP(&cfgFile, "file", "f", "Terrafile", "config file")
73+
rootCmd.PersistentFlags().StringVarP(&VendorDir, "directory", "d", defaultVendorDir, "module directory")
74+
6575
commandRe := regexp.MustCompile(`(version|help)`)
6676
if (len(os.Args) > 1) && !commandRe.MatchString(os.Args[1]) {
6777
cobra.OnInitialize(initConfig)
6878
}
69-
rootCmd.PersistentFlags().StringVarP(&cfgFile, "file", "f", "Terrafile", "config file")
70-
rootCmd.PersistentFlags().StringVarP(&VendorDir, "directory", "d", "vendor/modules", "module directory")
7179
}
7280

7381
// initConfig reads in config file and ENV variables if set.
@@ -77,4 +85,7 @@ func initConfig() {
7785

7886
err = yaml.Unmarshal(yamlFile, &Config)
7987
xt.CheckIfError(cfgFile, err)
88+
if (VendorDir == defaultVendorDir) && (Config.VendorDirFromFile != "") {
89+
VendorDir = Config.VendorDirFromFile
90+
}
8091
}

0 commit comments

Comments
 (0)