Skip to content

Commit b1fdc47

Browse files
jimrazmussagikazarmark
authored andcommittedSep 19, 2021
Recognize tfvars files as hcl by default.
Signed-off-by: Mark Sagi-Kazar <[email protected]>
1 parent 65f16c1 commit b1fdc47

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed
 

‎viper.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ func init() {
105105

106106
encoderRegistry.RegisterEncoder("hcl", codec)
107107
decoderRegistry.RegisterDecoder("hcl", codec)
108+
109+
encoderRegistry.RegisterEncoder("tfvars", codec)
110+
decoderRegistry.RegisterDecoder("tfvars", codec)
108111
}
109112
}
110113

@@ -329,7 +332,7 @@ func NewWithOptions(opts ...Option) *Viper {
329332
// can use it in their testing as well.
330333
func Reset() {
331334
v = New()
332-
SupportedExts = []string{"json", "toml", "yaml", "yml", "properties", "props", "prop", "hcl", "dotenv", "env", "ini"}
335+
SupportedExts = []string{"json", "toml", "yaml", "yml", "properties", "props", "prop", "hcl", "tfvars", "dotenv", "env", "ini"}
333336
SupportedRemoteProviders = []string{"etcd", "consul", "firestore"}
334337
}
335338

@@ -368,7 +371,7 @@ type RemoteProvider interface {
368371
}
369372

370373
// SupportedExts are universally supported extensions.
371-
var SupportedExts = []string{"json", "toml", "yaml", "yml", "properties", "props", "prop", "hcl", "dotenv", "env", "ini"}
374+
var SupportedExts = []string{"json", "toml", "yaml", "yml", "properties", "props", "prop", "hcl", "tfvars", "dotenv", "env", "ini"}
372375

373376
// SupportedRemoteProviders are universally supported remote providers.
374377
var SupportedRemoteProviders = []string{"etcd", "consul", "firestore"}
@@ -1624,7 +1627,7 @@ func (v *Viper) unmarshalReader(in io.Reader, c map[string]interface{}) error {
16241627
buf.ReadFrom(in)
16251628

16261629
switch format := strings.ToLower(v.getConfigType()); format {
1627-
case "yaml", "yml", "json", "toml", "hcl":
1630+
case "yaml", "yml", "json", "toml", "hcl", "tfvars":
16281631
err := decoderRegistry.Decode(format, buf.Bytes(), &c)
16291632
if err != nil {
16301633
return ConfigParseError{err}
@@ -1681,7 +1684,7 @@ func (v *Viper) unmarshalReader(in io.Reader, c map[string]interface{}) error {
16811684
func (v *Viper) marshalWriter(f afero.File, configType string) error {
16821685
c := v.AllSettings()
16831686
switch configType {
1684-
case "yaml", "yml", "json", "toml", "hcl":
1687+
case "yaml", "yml", "json", "toml", "hcl", "tfvars":
16851688
b, err := encoderRegistry.Encode(configType, c)
16861689
if err != nil {
16871690
return ConfigMarshalError{err}

0 commit comments

Comments
 (0)
Please sign in to comment.