Skip to content

Commit

Permalink
Add support for json template
Browse files Browse the repository at this point in the history
  • Loading branch information
x-color committed May 16, 2021
1 parent 077d254 commit dd224c6
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package main
import (
"bytes"
_ "embed"
"encoding/json"
"errors"
"flag"
"fmt"
"html/template"
Expand All @@ -14,26 +16,26 @@ import (

type resource struct {
ID string
Type string `yaml:"Type,omitempty"`
Type string `yaml:"Type,omitempty" json:"Type,omitempty"`
}

type output struct {
ID string
Description string `yaml:"Description,omitempty"`
Description string `yaml:"Description,omitempty" json:"Description,omitempty"`
}

type parameter struct {
ID string
Description string `yaml:"Description,omitempty"`
Type string `yaml:"Type,omitempty"`
Default string `yaml:"Default,omitempty"`
Description string `yaml:"Description,omitempty" json:"Description,omitempty"`
Type string `yaml:"Type,omitempty" json:"Type,omitempty"`
Default string `yaml:"Default,omitempty" json:"Default,omitempty"`
}

type cfnTemplate struct {
Description string `yaml:"Description,omitempty"`
Parameters map[string]parameter `yaml:"Parameters,omitempty"`
Resources map[string]resource `yaml:"Resources,omitempty"`
Outputs map[string]output `yaml:"Outputs,omitempty"`
Description string `yaml:"Description,omitempty" json:"Description,omitempty"`
Parameters map[string]parameter `yaml:"Parameters,omitempty" json:"Parameters,omitempty"`
Resources map[string]resource `yaml:"Resources,omitempty" json:"Resources,omitempty"`
Outputs map[string]output `yaml:"Outputs,omitempty" json:"Outputs,omitempty"`
}

type templateValue struct {
Expand Down Expand Up @@ -128,6 +130,11 @@ func readCFnTemplate(filename string) (cfnTemplate, error) {

raw := cfnTemplate{}
err = yaml.Unmarshal(b, &raw)
if !errors.Is(err, new(yaml.TypeError)) {
return raw, err
}

err = json.Unmarshal(b, &raw)
return raw, err
}

Expand Down

0 comments on commit dd224c6

Please sign in to comment.