MCPcopy Index your code
hub / github.com/coder/coder / DiscoverVarsFiles

Function DiscoverVarsFiles

codersdk/templatevariables.go:24–52  ·  view source on GitHub ↗

** * DiscoverVarsFiles function loads vars files in a predefined order: * 1. terraform.tfvars * 2. terraform.tfvars.json * 3. *.auto.tfvars * 4. *.auto.tfvars.json */

(workDir string)

Source from the content-addressed store, hash-verified

22 * 4. *.auto.tfvars.json
23 */
24func DiscoverVarsFiles(workDir string) ([]string, error) {
25 var found []string
26
27 fi, err := os.Stat(filepath.Join(workDir, "terraform.tfvars"))
28 if err == nil {
29 found = append(found, filepath.Join(workDir, fi.Name()))
30 } else if !os.IsNotExist(err) {
31 return nil, err
32 }
33
34 fi, err = os.Stat(filepath.Join(workDir, "terraform.tfvars.json"))
35 if err == nil {
36 found = append(found, filepath.Join(workDir, fi.Name()))
37 } else if !os.IsNotExist(err) {
38 return nil, err
39 }
40
41 dirEntries, err := os.ReadDir(workDir)
42 if err != nil {
43 return nil, err
44 }
45
46 for _, dirEntry := range dirEntries {
47 if strings.HasSuffix(dirEntry.Name(), ".auto.tfvars") || strings.HasSuffix(dirEntry.Name(), ".auto.tfvars.json") {
48 found = append(found, filepath.Join(workDir, dirEntry.Name()))
49 }
50 }
51 return found, nil
52}
53
54func ParseUserVariableValues(varsFiles []string, variablesFile string, commandLineVariables []string) ([]VariableValue, error) {
55 fromVars, err := parseVariableValuesFromVarsFiles(varsFiles)

Callers 3

TestDiscoverVarsFilesFunction · 0.92
templateCreateMethod · 0.92
templatePushMethod · 0.92

Calls 2

ReadDirMethod · 0.80
NameMethod · 0.65

Tested by 1

TestDiscoverVarsFilesFunction · 0.74