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