Skip to content

Commit

Permalink
fix: issue where the default version is not used (#716)
Browse files Browse the repository at this point in the history
* fix: issue where the default version is not used

* fix test cases
  • Loading branch information
jakeyheath authored Aug 29, 2022
1 parent d365cd8 commit 2b45e36
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,12 @@ type TFEWorkspace struct {
RemoteApply *bool `json:"remote_apply,omitempty"`
}

func MakeTFEWorkspace() *TFEWorkspace {
func MakeTFEWorkspace(tfVersion string) *TFEWorkspace {
defaultTriggerPrefixes := make([]string, 0)
defaultTerraformVersion := "1.2.6"
defaultTerraformVersion := tfVersion
if defaultTerraformVersion == "" {
defaultTerraformVersion = "1.2.6"
}
defaultGithubBranch := "main"
defaultAutoApply := true
defaultRemoteApply := false
Expand All @@ -138,7 +141,7 @@ func updateLocalsFromPlan(locals *LocalsTFE, plan *plan.Plan) {
// if there is a planned env or account that isn't in the locals, add it
for accountName := range plan.Accounts {
if _, ok := locals.Locals.Accounts[accountName]; !ok {
locals.Locals.Accounts[accountName] = MakeTFEWorkspace()
locals.Locals.Accounts[accountName] = MakeTFEWorkspace(plan.Global.Common.TerraformVersion)
}
}
for envName := range plan.Envs {
Expand All @@ -147,7 +150,7 @@ func updateLocalsFromPlan(locals *LocalsTFE, plan *plan.Plan) {
}
for componentName := range plan.Envs[envName].Components {
if _, ok := locals.Locals.Envs[envName][componentName]; !ok {
locals.Locals.Envs[envName][componentName] = MakeTFEWorkspace()
locals.Locals.Envs[envName][componentName] = MakeTFEWorkspace(plan.Global.Common.TerraformVersion)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions apply/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func makeTestCases(tests []UploadLocalsTestCaseSimple) ([]UploadLocalsTestCase,

localAccounts := make(map[string]*TFEWorkspace, 0)
for _, local := range test.localsAccounts {
localAccounts[local] = MakeTFEWorkspace()
localAccounts[local] = MakeTFEWorkspace("1.2.6")
}
localEnvs := make(map[string]map[string]*TFEWorkspace, 0)
for _, local := range test.localEnvs {
Expand All @@ -77,7 +77,7 @@ func makeTestCases(tests []UploadLocalsTestCaseSimple) ([]UploadLocalsTestCase,
return nil, errors.New("env needs to be of the form env/component")
}
component := map[string]*TFEWorkspace{}
component[splits[1]] = MakeTFEWorkspace()
component[splits[1]] = MakeTFEWorkspace("1.2.6")
localEnvs[splits[0]] = component
}
locals := LocalsTFE{
Expand Down

0 comments on commit 2b45e36

Please sign in to comment.