Skip to content

Commit

Permalink
Recognize tfvars files as hcl by default.
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
  • Loading branch information
jimrazmus authored and sagikazarmark committed Sep 19, 2021
1 parent 65f16c1 commit b1fdc47
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions viper.go
Expand Up @@ -105,6 +105,9 @@ func init() {

encoderRegistry.RegisterEncoder("hcl", codec)
decoderRegistry.RegisterDecoder("hcl", codec)

encoderRegistry.RegisterEncoder("tfvars", codec)
decoderRegistry.RegisterDecoder("tfvars", codec)
}
}

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

Expand Down Expand Up @@ -368,7 +371,7 @@ type RemoteProvider interface {
}

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

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

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

0 comments on commit b1fdc47

Please sign in to comment.