]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blob - vendor/github.com/hashicorp/terraform/config/module/get.go
Merge branch 'fix_read_test' of github.com:alexandreFre/terraform-provider-statuscake
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / terraform / config / module / get.go
1 package module
2
3 import (
4 "io/ioutil"
5 "os"
6 "path/filepath"
7
8 "github.com/hashicorp/go-getter"
9 )
10
11 // GetMode is an enum that describes how modules are loaded.
12 //
13 // GetModeLoad says that modules will not be downloaded or updated, they will
14 // only be loaded from the storage.
15 //
16 // GetModeGet says that modules can be initially downloaded if they don't
17 // exist, but otherwise to just load from the current version in storage.
18 //
19 // GetModeUpdate says that modules should be checked for updates and
20 // downloaded prior to loading. If there are no updates, we load the version
21 // from disk, otherwise we download first and then load.
22 type GetMode byte
23
24 const (
25 GetModeNone GetMode = iota
26 GetModeGet
27 GetModeUpdate
28 )
29
30 // GetCopy is the same as Get except that it downloads a copy of the
31 // module represented by source.
32 //
33 // This copy will omit and dot-prefixed files (such as .git/, .hg/) and
34 // can't be updated on its own.
35 func GetCopy(dst, src string) error {
36 // Create the temporary directory to do the real Get to
37 tmpDir, err := ioutil.TempDir("", "tf")
38 if err != nil {
39 return err
40 }
41 defer os.RemoveAll(tmpDir)
42
43 tmpDir = filepath.Join(tmpDir, "module")
44
45 // Get to that temporary dir
46 if err := getter.Get(tmpDir, src); err != nil {
47 return err
48 }
49
50 // Make sure the destination exists
51 if err := os.MkdirAll(dst, 0755); err != nil {
52 return err
53 }
54
55 // Copy to the final location
56 return copyDir(dst, tmpDir)
57 }