Skip to content

Commit

Permalink
refactor: split functions (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
suzuki-shunsuke authored Nov 5, 2023
1 parent adc916b commit b69c067
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/controller/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ func (c *Controller) Run(_ context.Context, _ *logrus.Entry, param *ParamRun, vo
}

providers := make(map[string]version.Constraints, len(cfg.Providers))
if err := parseConfig(cfg, providers); err != nil {
return err
}

return validate(vout, providers)
}

func parseConfig(cfg *Config, providers map[string]version.Constraints) error {
for _, provider := range cfg.Providers {
if provider.Name == "" {
return ErrProviderNameIsRequired
Expand All @@ -33,7 +41,10 @@ func (c *Controller) Run(_ context.Context, _ *logrus.Entry, param *ParamRun, vo
}
providers[provider.Name] = constraints
}
return nil
}

func validate(vout *TerraformVersionOutput, providers map[string]version.Constraints) error {
for providerName, providerVersion := range vout.ProviderSelections {
constraints, ok := providers[providerName]
if !ok {
Expand Down

0 comments on commit b69c067

Please sign in to comment.