This commit is contained in:
Philippe Caseiro 2022-06-30 16:20:21 +02:00
parent 7821239ab3
commit d6d7695e0c
1 changed files with 5 additions and 5 deletions

View File

@ -69,7 +69,7 @@ func (s *Service) Manage(templateDir string, rootDir string) error {
}
log.Print(" Generating configuration files\n")
err = processConfigFiles(s.ConfigFiles, s.Vars, templateDir, rootDir)
err = processConfigFiles(s, templateDir, rootDir)
if err != nil {
return fmt.Errorf("ProcessingTemplatesFailed with error: %v", err)
}
@ -84,14 +84,14 @@ func (s *Service) Manage(templateDir string, rootDir string) error {
return nil
}
func processConfigFiles(tpls []ConfigFile, variables map[string]interface{}, templateDir string, rootDir string) error {
values, err := json.Marshal(variables)
func processConfigFiles(s *Service, templateDir string, rootDir string) error {
values, err := json.Marshal(s)
if err != nil {
return fmt.Errorf("Error unmarshaling values on template process; %v", err)
}
var servicesToRestart []string
for _, tpl := range tpls {
for _, tpl := range s.ConfigFiles {
fileExt := filepath.Ext(tpl.Source)
if fileExt == ".hcl" {
tpl.TemplateType = "hcl"
@ -100,7 +100,7 @@ func processConfigFiles(tpls []ConfigFile, variables map[string]interface{}, tem
} else {
return fmt.Errorf("Unsupported file type %s, templates extensions have to be '.hcl' or '.tpl'", fileExt)
}
if err := tpl.Generate("/tmp/test", templateDir, values); err != nil {
if err := tpl.Generate(rootDir, templateDir, values); err != nil {
return fmt.Errorf("Template %s generation failed with error %v", tpl.Source, err)
}