Skip to content

Commit

Permalink
feat: add some custom yaml unmarshalling rules to add default values
Browse files Browse the repository at this point in the history
where go-flags ones aren't applicable
  • Loading branch information
hbollon committed Jun 24, 2021
1 parent 694ef54 commit 68e8291
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
33 changes: 33 additions & 0 deletions config/yaml.go
@@ -0,0 +1,33 @@
package config

/*********************************************
* Custom UnmarshalYAML used to define some struct fields
* default values where go-flags ones aren't applicable
* (and so makes them optional)
*********************************************/

func (s *S3BucketConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
type rawS3BucketConfig S3BucketConfig
raw := rawS3BucketConfig{
FileExtension: []string{".tfstate"},
}
if err := unmarshal(&raw); err != nil {
return err
}

*s = S3BucketConfig(raw)
return nil
}

func (s *GitlabConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
type rawGitlabConfig GitlabConfig
raw := GitlabConfig{
Address: "https://gitlab.com",
}
if err := unmarshal(&raw); err != nil {
return err
}

*s = GitlabConfig(raw)
return nil
}
1 change: 0 additions & 1 deletion state/aws.go
Expand Up @@ -65,7 +65,6 @@ func NewAWS(c *config.Config) []*AWS {
noLocks: c.Provider.NoLocks,
noVersioning: c.Provider.NoVersioning,
}
log.Debugf("Instance: %+v\n", *instance)
awsInstances = append(awsInstances, instance)
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/docker-compose.yml
Expand Up @@ -47,7 +47,7 @@ services:
# - ../static:/static:ro
# - ./config.yml:/config/config.yml:ro
# ports:
# - "8081:8081"
# - "8081:8080"

minio:
image: minio/minio:latest
Expand Down

0 comments on commit 68e8291

Please sign in to comment.