github.com/Yunsang-Jeong/terraforge@v0.0.0-20231003081416-fe4fad2c57e3/internal/app/run.go (about) 1 package app 2 3 import ( 4 "github.com/Yunsang-Jeong/terraforge/internal/configs" 5 "github.com/Yunsang-Jeong/terraforge/internal/logger" 6 "github.com/hashicorp/hcl/v2" 7 "github.com/spf13/afero" 8 "github.com/zclconf/go-cty/cty" 9 "github.com/zclconf/go-cty/cty/function" 10 ) 11 12 type terraforge struct { 13 lg logger.Logger 14 ctx *hcl.EvalContext 15 fs afero.Afero 16 wd string 17 cf string 18 } 19 20 func NewTerraforge(workingDir string, configFile string, debug bool) *terraforge { 21 return &terraforge{ 22 lg: logger.NewSimpleLogger(debug), 23 ctx: &hcl.EvalContext{ 24 Variables: map[string]cty.Value{}, 25 Functions: map[string]function.Function{}, 26 }, 27 fs: afero.Afero{Fs: afero.OsFs{}}, 28 wd: workingDir, 29 cf: configFile, 30 } 31 } 32 33 func (app *terraforge) Run() error { 34 parser := configs.NewParser(app.lg, app.wd, app.fs) 35 36 config, err := parser.LoadConfigFile(app.cf) 37 if err != nil { 38 app.lg.Error("fail to load config file", "err", err) 39 return nil 40 } 41 42 if err := config.GenerateTFConfig(app.wd, app.fs); err != nil { 43 app.lg.Error("fail to generate terraform config", "err", err) 44 return nil 45 } 46 47 return nil 48 }