mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-23 07:33:32 -06:00
config: comments
This commit is contained in:
parent
218cc80aab
commit
c1dea5e5b3
@ -5,6 +5,9 @@ import (
|
||||
)
|
||||
|
||||
// Load loads the Terraform configuration from a given file.
|
||||
//
|
||||
// This file can be any format that Terraform recognizes, and import any
|
||||
// other format that Terraform recognizes.
|
||||
func Load(path string) (*Config, error) {
|
||||
importTree, err := loadTree(path)
|
||||
if err != nil {
|
||||
@ -19,19 +22,31 @@ func Load(path string) (*Config, error) {
|
||||
return configTree.Flatten()
|
||||
}
|
||||
|
||||
|
||||
// configurable is an interface that must be implemented by any configuration
|
||||
// formats of Terraform in order to return a *Config.
|
||||
type configurable interface {
|
||||
Config() (*Config, error)
|
||||
}
|
||||
|
||||
// importTree is the result of the first-pass load of the configuration
|
||||
// files. It is a tree of raw configurables and then any children (their
|
||||
// imports).
|
||||
//
|
||||
// An importTree can be turned into a configTree.
|
||||
type importTree struct {
|
||||
Path string
|
||||
Raw configurable
|
||||
Children []*importTree
|
||||
}
|
||||
|
||||
// This is the function type that must be implemented by the configuration
|
||||
// file loader to turn a single file into a configurable and any additional
|
||||
// imports.
|
||||
type fileLoaderFunc func(path string) (configurable, []string, error)
|
||||
|
||||
// loadTree takes a single file and loads the entire importTree for that
|
||||
// file. This function detects what kind of configuration file it is an
|
||||
// executes the proper fileLoaderFunc.
|
||||
func loadTree(root string) (*importTree, error) {
|
||||
c, imps, err := loadFileLibucl(root)
|
||||
if err != nil {
|
||||
@ -55,6 +70,8 @@ func loadTree(root string) (*importTree, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ConfigTree traverses the importTree and turns each node into a *Config
|
||||
// object, ultimately returning a *configTree.
|
||||
func (t *importTree) ConfigTree() (*configTree, error) {
|
||||
config, err := t.Raw.Config()
|
||||
if err != nil {
|
||||
|
@ -11,6 +11,8 @@ import (
|
||||
// equally behaving parsing everywhere.
|
||||
const libuclParseFlags = libucl.ParserKeyLowercase
|
||||
|
||||
// libuclConfigurable is an implementation of configurable that knows
|
||||
// how to turn libucl configuration into a *Config object.
|
||||
type libuclConfigurable struct {
|
||||
Object *libucl.Object
|
||||
}
|
||||
@ -43,6 +45,8 @@ func (t *libuclConfigurable) Config() (*Config, error) {
|
||||
return config, nil
|
||||
}
|
||||
|
||||
// loadFileLibucl is a fileLoaderFunc that knows how to read libucl
|
||||
// files and turn them into libuclConfigurables.
|
||||
func loadFileLibucl(root string) (configurable, []string, error) {
|
||||
var obj *libucl.Object = nil
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user