mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Merge pull request #15490 from hashicorp/jbardin/meta-process-order
meta process order
This commit is contained in:
commit
6ba049470e
@ -11,6 +11,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -398,38 +399,26 @@ func (m *Meta) process(args []string, vars bool) ([]string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
f, err := os.Open(wd)
|
|
||||||
|
fis, err := ioutil.ReadDir(wd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
fi, err := f.Stat()
|
// make sure we add the files in order
|
||||||
if err != nil {
|
sort.Slice(fis, func(i, j int) bool {
|
||||||
return nil, err
|
return fis[i].Name() < fis[j].Name()
|
||||||
}
|
})
|
||||||
if !fi.IsDir() {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = nil
|
for _, fi := range fis {
|
||||||
for err != io.EOF {
|
name := fi.Name()
|
||||||
var fis []os.FileInfo
|
// Ignore directories, non-var-files, and ignored files
|
||||||
fis, err = f.Readdir(128)
|
if fi.IsDir() || !isAutoVarFile(name) || config.IsIgnoredFile(name) {
|
||||||
if err != nil && err != io.EOF {
|
continue
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, fi := range fis {
|
m.autoKey = "var-file-default"
|
||||||
name := fi.Name()
|
preArgs = append(preArgs, "-"+m.autoKey, name)
|
||||||
// Ignore directories, non-var-files, and ignored files
|
|
||||||
if fi.IsDir() || !isAutoVarFile(name) || config.IsIgnoredFile(name) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
m.autoKey = "var-file-default"
|
|
||||||
preArgs = append(preArgs, "-"+m.autoKey, name)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
args = append(preArgs, args...)
|
args = append(preArgs, args...)
|
||||||
|
@ -138,20 +138,12 @@ func TestMetaInputMode_defaultVars(t *testing.T) {
|
|||||||
|
|
||||||
// Create a temporary directory for our cwd
|
// Create a temporary directory for our cwd
|
||||||
d := tempDir(t)
|
d := tempDir(t)
|
||||||
if err := os.MkdirAll(d, 0755); err != nil {
|
os.MkdirAll(d, 0755)
|
||||||
t.Fatalf("err: %s", err)
|
defer os.RemoveAll(d)
|
||||||
}
|
defer testChdir(t, d)()
|
||||||
cwd, err := os.Getwd()
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %s", err)
|
|
||||||
}
|
|
||||||
if err := os.Chdir(d); err != nil {
|
|
||||||
t.Fatalf("err: %s", err)
|
|
||||||
}
|
|
||||||
defer os.Chdir(cwd)
|
|
||||||
|
|
||||||
// Create the default vars file
|
// Create the default vars file
|
||||||
err = ioutil.WriteFile(
|
err := ioutil.WriteFile(
|
||||||
filepath.Join(d, DefaultVarsFilename),
|
filepath.Join(d, DefaultVarsFilename),
|
||||||
[]byte(""),
|
[]byte(""),
|
||||||
0644)
|
0644)
|
||||||
@ -326,21 +318,13 @@ func TestMeta_process(t *testing.T) {
|
|||||||
|
|
||||||
// Create a temporary directory for our cwd
|
// Create a temporary directory for our cwd
|
||||||
d := tempDir(t)
|
d := tempDir(t)
|
||||||
if err := os.MkdirAll(d, 0755); err != nil {
|
os.MkdirAll(d, 0755)
|
||||||
t.Fatalf("err: %s", err)
|
defer os.RemoveAll(d)
|
||||||
}
|
defer testChdir(t, d)()
|
||||||
cwd, err := os.Getwd()
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %s", err)
|
|
||||||
}
|
|
||||||
if err := os.Chdir(d); err != nil {
|
|
||||||
t.Fatalf("err: %s", err)
|
|
||||||
}
|
|
||||||
defer os.Chdir(cwd)
|
|
||||||
|
|
||||||
// Create two vars files
|
// Create two vars files
|
||||||
defaultVarsfile := "terraform.tfvars"
|
defaultVarsfile := "terraform.tfvars"
|
||||||
err = ioutil.WriteFile(
|
err := ioutil.WriteFile(
|
||||||
filepath.Join(d, defaultVarsfile),
|
filepath.Join(d, defaultVarsfile),
|
||||||
[]byte(""),
|
[]byte(""),
|
||||||
0644)
|
0644)
|
||||||
@ -388,18 +372,18 @@ func TestMeta_process(t *testing.T) {
|
|||||||
t.Fatalf("expected %q, got %q", "-var-file-default", args[0])
|
t.Fatalf("expected %q, got %q", "-var-file-default", args[0])
|
||||||
}
|
}
|
||||||
if args[1] != defaultVarsfile {
|
if args[1] != defaultVarsfile {
|
||||||
t.Fatalf("expected %q, got %q", defaultVarsfile, args[3])
|
t.Fatalf("expected %q, got %q", defaultVarsfile, args[1])
|
||||||
}
|
}
|
||||||
if args[2] != "-var-file-default" {
|
if args[2] != "-var-file-default" {
|
||||||
t.Fatalf("expected %q, got %q", "-var-file-default", args[0])
|
t.Fatalf("expected %q, got %q", "-var-file-default", args[2])
|
||||||
}
|
}
|
||||||
if args[3] != fileFirstAlphabetical {
|
if args[3] != fileFirstAlphabetical {
|
||||||
t.Fatalf("expected %q, got %q", fileFirstAlphabetical, args[1])
|
t.Fatalf("expected %q, got %q", fileFirstAlphabetical, args[3])
|
||||||
}
|
}
|
||||||
if args[4] != "-var-file-default" {
|
if args[4] != "-var-file-default" {
|
||||||
t.Fatalf("expected %q, got %q", "-var-file-default", args[0])
|
t.Fatalf("expected %q, got %q", "-var-file-default", args[4])
|
||||||
}
|
}
|
||||||
if args[5] != fileLastAlphabetical {
|
if args[5] != fileLastAlphabetical {
|
||||||
t.Fatalf("expected %q, got %q", fileLastAlphabetical, args[3])
|
t.Fatalf("expected %q, got %q", fileLastAlphabetical, args[5])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user