Skip to content

Commit

Permalink
do not template the default value from file
Browse files Browse the repository at this point in the history
  • Loading branch information
mvanholsteijn committed Oct 25, 2019
1 parent 4089746 commit 72f6bdd
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,15 @@ func environmentToSSMParameterReferences(environ []string) ([]SSMParameterRef, e

defaultValue := values.Get("default")
destination := values.Get("destination")
template := template.New("secret")
template, _ = template.Parse("{{.}}")
var tpl *template.Template
if values.Get("template") != "" {
template, err = template.Parse(values.Get("template"))
tpl, err = template.New("secret").Parse(values.Get("template"))
if err != nil {
return nil, fmt.Errorf("environment variable %s has an invalid template syntax, %s", name, err)
}
}
result = append(result, SSMParameterRef{&name, &uri.Path,
&defaultValue, &destination, template})
&defaultValue, &destination, tpl})
}
}
return result, nil
Expand All @@ -93,6 +92,9 @@ func environmentToSSMParameterReferences(environ []string) ([]SSMParameterRef, e
// get the default value for the parameter
func getDefaultValue(ref *SSMParameterRef) (string, error) {
if *ref.default_value != "" {
if ref.template != nil {
return formatValue(ref, ref.default_value), nil
}
return *ref.default_value, nil
}

Expand Down Expand Up @@ -131,6 +133,10 @@ func ssmParameterReferencesToEnvironment(refs []SSMParameterRef) (map[string]str

func formatValue(ref *SSMParameterRef, value *string) string {
var writer bytes.Buffer
if ref.template == nil {
return *value
}

if err := ref.template.Execute(&writer, value); err != nil {
log.Fatalf("failed to format value of '%s' with template", *ref.name)
}
Expand Down

0 comments on commit 72f6bdd

Please sign in to comment.