databricks-cli/libs/template/materialize.go

32 lines
775 B
Go
Raw Normal View History

2023-05-21 20:37:38 +00:00
package template
2023-05-21 20:48:38 +00:00
import (
"path/filepath"
)
2023-05-21 20:37:38 +00:00
const schemaFileName = "databricks_template_schema.json"
2023-05-21 20:48:38 +00:00
const templateDirName = "template"
2023-07-05 08:54:31 +00:00
const libraryDirName = "library"
2023-05-21 20:37:38 +00:00
func Materialize(templateRoot, instanceRoot, configPath string) error {
2023-05-21 20:37:38 +00:00
// read the file containing schema for template input parameters
schema, err := ReadSchema(filepath.Join(templateRoot, schemaFileName))
2023-05-21 20:37:38 +00:00
if err != nil {
return err
}
2023-07-05 08:54:31 +00:00
// read user config to initialize the template with
2023-05-22 03:58:05 +00:00
config, err := schema.ReadConfig(configPath)
2023-05-21 20:37:38 +00:00
if err != nil {
return err
}
2023-07-05 08:54:31 +00:00
r, err := newRenderer(config, filepath.Join(templateRoot, libraryDirName))
if err != nil {
return err
}
2023-05-21 20:37:38 +00:00
// materialize the template
2023-07-05 08:54:31 +00:00
return walkFileTree(r, filepath.Join(templateRoot, templateDirName), instanceRoot)
2023-05-21 20:37:38 +00:00
}